远程服务器执行 start 命令
(workspaceInfo workspace.WorkspaceInfo, isUnforward bool, yamlExecuteFun func(yamlConfig config.SmartIdeConfig, workspaceInfo workspace.WorkspaceInfo, cmdtype, userguid, workspaceid string), cmd *cobra.Command, args []string, disableClone bool)
| 41 | |
| 42 | // 远程服务器执行 start 命令 |
| 43 | func ExecuteVmStartCmd(workspaceInfo workspace.WorkspaceInfo, isUnforward bool, |
| 44 | yamlExecuteFun func(yamlConfig config.SmartIdeConfig, workspaceInfo workspace.WorkspaceInfo, cmdtype, userguid, workspaceid string), cmd *cobra.Command, args []string, disableClone bool) ( |
| 45 | workspace.WorkspaceInfo, error) { |
| 46 | common.SmartIDELog.Info(i18nInstance.VmStart.Info_starting) |
| 47 | |
| 48 | mode, _ := cmd.Flags().GetString("mode") |
| 49 | calbackAPI, _ := cmd.Flags().GetString("callback-api-address") |
| 50 | userName, _ := cmd.Flags().GetString("serverusername") |
| 51 | isModeServer := strings.ToLower(mode) == "server" |
| 52 | isModePipeline := strings.ToLower(mode) == "pipeline" |
| 53 | // 错误反馈 |
| 54 | serverFeedback := func(err error) { |
| 55 | if !isModeServer { |
| 56 | return |
| 57 | } |
| 58 | if err != nil { |
| 59 | smartideServer.Feedback_Finish(smartideServer.FeedbackCommandEnum_Start, cmd, false, nil, workspaceInfo, err.Error(), "") |
| 60 | } |
| 61 | } |
| 62 | |
| 63 | //0. 连接到远程主机 |
| 64 | msg := fmt.Sprintf(" %v@%v:%v ...", workspaceInfo.Remote.UserName, workspaceInfo.Remote.Addr, workspaceInfo.Remote.SSHPort) |
| 65 | common.SmartIDELog.Info(i18nInstance.VmStart.Info_connect_remote + msg) |
| 66 | sshRemote, err := common.NewSSHRemote(workspaceInfo.Remote.Addr, workspaceInfo.Remote.SSHPort, workspaceInfo.Remote.UserName, workspaceInfo.Remote.Password, workspaceInfo.Remote.SSHKey) |
| 67 | common.CheckErrorFunc(err, serverFeedback) |
| 68 | |
| 69 | //1. 检查远程主机是否有docker、docker-compose、git |
| 70 | err = sshRemote.CheckRemoteEnv() |
| 71 | common.CheckErrorFunc(err, serverFeedback) |
| 72 | |
| 73 | //2. git clone & checkout |
| 74 | if !disableClone { // 是否禁止clone |
| 75 | //2.1. 是否已 clone |
| 76 | common.SmartIDELog.Info(i18nInstance.VmStart.Info_git_clone) |
| 77 | isCloned := sshRemote.IsCloned(workspaceInfo.WorkingDirectoryPath) |
| 78 | |
| 79 | //2.2. git 操作 |
| 80 | if isCloned { |
| 81 | common.SmartIDELog.Info(i18nInstance.VmStart.Info_git_cloned) |
| 82 | } else { |
| 83 | // 执行ssh-key 策略 |
| 84 | var wspId uint = 0 |
| 85 | if workspaceInfo.ServerWorkSpace != nil && workspaceInfo.ServerWorkSpace.SshCredentialId > 0 { |
| 86 | wspId = workspaceInfo.ServerWorkSpace.SshCredentialId |
| 87 | } |
| 88 | sshRemote.ExecSSHkeyPolicy(common.SmartIDELog.Ws_id, userName, common.ServerHost, common.ServerToken, common.ServerUserGuid, wspId) |
| 89 | // Generate Authorizedkeys |
| 90 | err = GitCloneAndCheckoutBranch(sshRemote, workspaceInfo, cmd) |
| 91 | common.CheckErrorFunc(err, serverFeedback) |
| 92 | } |
| 93 | } |
| 94 | sshRemote.AddPublicKeyIntoAuthorizedkeys() |
| 95 | |
| 96 | //3. 获取配置文件的内容 |
| 97 | var ideBindingPort int |
| 98 | var tempDockerCompose compose.DockerComposeYml |
| 99 | ideYamlFilePath := common.FilePahtJoin4Linux(workspaceInfo.WorkingDirectoryPath, workspaceInfo.ConfigFileRelativePath) //fmt.Sprintf(`%v/.ide/.ide.yaml`, repoWorkspace) |
| 100 | common.SmartIDELog.Info(fmt.Sprintf(i18nInstance.VmStart.Info_read_config, ideYamlFilePath)) |
nothing calls this directly
no test coverage detected