停止远程容器
(workspaceInfo workspace.WorkspaceInfo)
| 158 | |
| 159 | // 停止远程容器 |
| 160 | func stopRemote(workspaceInfo workspace.WorkspaceInfo) error { |
| 161 | // ssh 连接 |
| 162 | common.SmartIDELog.Info(i18nInstance.Stop.Info_sshremote_connection_creating) |
| 163 | |
| 164 | sshRemote, err := common.NewSSHRemote(workspaceInfo.Remote.Addr, workspaceInfo.Remote.SSHPort, workspaceInfo.Remote.UserName, workspaceInfo.Remote.Password, workspaceInfo.Remote.SSHKey) |
| 165 | if err != nil { |
| 166 | return err |
| 167 | } |
| 168 | |
| 169 | // 项目文件夹是否存在 |
| 170 | if !sshRemote.IsDirExist(workspaceInfo.WorkingDirectoryPath) { |
| 171 | msg := fmt.Sprintf(i18nInstance.Stop.Err_env_project_dir_remove, workspaceInfo.ID) |
| 172 | return errors.New(msg) |
| 173 | } |
| 174 | |
| 175 | // 检查临时文件夹是否存在 |
| 176 | if !sshRemote.IsFileExist(workspaceInfo.TempYamlFileAbsolutePath) || !sshRemote.IsFileExist(workspaceInfo.ConfigYaml.GetConfigFileAbsolutePath()) { |
| 177 | workspaceInfo.SaveTempFilesForRemote(sshRemote) |
| 178 | } |
| 179 | |
| 180 | // 检查环境 |
| 181 | err = sshRemote.CheckRemoteEnv() |
| 182 | if err != nil { |
| 183 | return err |
| 184 | } |
| 185 | |
| 186 | // 停止容器 |
| 187 | common.SmartIDELog.Info(i18nInstance.Stop.Info_docker_stopping) |
| 188 | command := fmt.Sprintf("docker-compose -f %v --project-directory %v stop", |
| 189 | common.FilePahtJoin4Linux(workspaceInfo.TempYamlFileAbsolutePath), common.FilePahtJoin4Linux(workspaceInfo.WorkingDirectoryPath)) |
| 190 | err = sshRemote.ExecSSHCommandRealTime(command) |
| 191 | if err != nil { |
| 192 | return err |
| 193 | } |
| 194 | |
| 195 | return nil |
| 196 | } |
| 197 | |
| 198 | func init() { |
| 199 | //stopCmd.Flags().StringVarP(&configYamlFileRelativePath, "filepath", "f", "", i18nInstance.Stop.Info_help_flag_filepath) |
no test coverage detected