检测远程服务器的环境,是否安装docker、docker-compose、git
(sshRemote common.SSHRemote, workingDir string, dockerComposeServices []string)
| 69 | |
| 70 | // 检测远程服务器的环境,是否安装docker、docker-compose、git |
| 71 | func GetRemoteContainersWithServices(sshRemote common.SSHRemote, |
| 72 | workingDir string, dockerComposeServices []string) (dockerComposeContainers []DockerComposeContainer, err error) { |
| 73 | |
| 74 | // https://docs.docker.com/engine/api/v1.41/#operation/ContainerList |
| 75 | command := "sudo curl -s --unix-socket /var/run/docker.sock http://dummy/containers/json " |
| 76 | output, err := sshRemote.ExeSSHCommand(command) |
| 77 | common.CheckError(err) |
| 78 | |
| 79 | if len(output) >= 0 { // 有返回结果的时候才需要转换 |
| 80 | var originContainers []types.Container |
| 81 | err = json.Unmarshal([]byte(output), &originContainers) |
| 82 | |
| 83 | // home dir |
| 84 | if workingDir[0:1] == "~" { |
| 85 | homeDir, _ := sshRemote.GetRemoteHome() |
| 86 | workingDir = common.FilePahtJoin4Linux(homeDir, workingDir[1:]) |
| 87 | } |
| 88 | |
| 89 | dockerComposeContainers = convertOriginContainer(originContainers, workingDir, dockerComposeServices) |
| 90 | } |
| 91 | |
| 92 | return dockerComposeContainers, err |
| 93 | } |
| 94 | |
| 95 | // 转换结构体 |
| 96 | func convertOriginContainer(containers []types.Container, |
no test coverage detected