在远程主机上运行删除命令
(workspaceInfo workspace.WorkspaceInfo, isRemoveAllComposeImages bool, isRemoveRemoteDirectory bool, isForce bool, cmd *cobra.Command)
| 29 | |
| 30 | // 在远程主机上运行删除命令 |
| 31 | func RemoveRemote(workspaceInfo workspace.WorkspaceInfo, |
| 32 | isRemoveAllComposeImages bool, isRemoveRemoteDirectory bool, isForce bool, |
| 33 | cmd *cobra.Command) error { |
| 34 | // ssh 连接 |
| 35 | common.SmartIDELog.Info(i18nInstance.Remove.Info_sshremote_connection_creating) |
| 36 | |
| 37 | sshRemote, err := common.NewSSHRemote(workspaceInfo.Remote.Addr, workspaceInfo.Remote.SSHPort, workspaceInfo.Remote.UserName, workspaceInfo.Remote.Password, workspaceInfo.Remote.SSHKey) |
| 38 | if err != nil { |
| 39 | return err |
| 40 | } |
| 41 | |
| 42 | // 检查环境 |
| 43 | err = sshRemote.CheckRemoteEnv() |
| 44 | if err != nil { |
| 45 | return err |
| 46 | } |
| 47 | |
| 48 | // 项目文件夹是否存在 |
| 49 | if workspaceInfo.GitCloneRepoUrl != "" && !sshRemote.IsCloned(workspaceInfo.WorkingDirectoryPath) { |
| 50 | sshRemote.GitClone(workspaceInfo.GitCloneRepoUrl, workspaceInfo.WorkingDirectoryPath, common.SmartIDELog.Ws_id, cmd) |
| 51 | isRemoveRemoteDirectory = true // 创建后就删掉 |
| 52 | |
| 53 | } |
| 54 | |
| 55 | // 检查临时文件夹是否存在 |
| 56 | configYamlFilePath := workspaceInfo.ConfigYaml.GetConfigFileAbsolutePath() |
| 57 | if !sshRemote.IsFileExist(workspaceInfo.TempYamlFileAbsolutePath) || !sshRemote.IsFileExist(configYamlFilePath) { |
| 58 | workspaceInfo.SaveTempFilesForRemote(sshRemote) |
| 59 | //isRemoveRemoteDirectory = true // 创建后就删掉 |
| 60 | |
| 61 | } |
| 62 | |
| 63 | // 容器列表 |
| 64 | containers, err := start.GetRemoteContainersWithServices(sshRemote, |
| 65 | workspaceInfo.WorkingDirectoryPath, workspaceInfo.ConfigYaml.GetServiceNames()) // 只能获取到运行中的容器 |
| 66 | if err != nil { |
| 67 | return err |
| 68 | } |
| 69 | if len(containers) <= 0 { |
| 70 | common.SmartIDELog.Importance(i18nInstance.Start.Warn_docker_container_getnone) |
| 71 | } |
| 72 | |
| 73 | // 远程主机上执行 docker-compose 删除容器 |
| 74 | // if len(containers) > 0 { |
| 75 | common.SmartIDELog.Info(i18nInstance.Remove.Info_docker_removing) |
| 76 | command := fmt.Sprintf(`docker-compose -f %v --project-directory %v down -v`, |
| 77 | common.FilePahtJoin4Linux(workspaceInfo.TempYamlFileAbsolutePath), common.FilePahtJoin4Linux(workspaceInfo.WorkingDirectoryPath)) |
| 78 | err = sshRemote.ExecSSHCommandRealTime(command) |
| 79 | if err != nil { |
| 80 | return err |
| 81 | } |
| 82 | |
| 83 | // 删除对应的镜像 |
| 84 | if isRemoveAllComposeImages { |
| 85 | common.SmartIDELog.Info(i18nInstance.Remove.Info_docker_rmi_removing) |
| 86 | |
| 87 | force := "" |
| 88 | if isForce { |
nothing calls this directly
no test coverage detected