[ Agent ] [ Executor ] - 优化修改Pipeline部分的代码
This commit is contained in:
@@ -225,7 +225,14 @@ func (op *AgentOsOperator) modifyHostname(args []string) [][]string {
|
||||
|
||||
func (op *AgentOsOperator) modifyHostnameExec(args []string) (bool, []string) {
|
||||
|
||||
return false, nil
|
||||
ok, resultLog := AllCommandExecutor(
|
||||
[]string{
|
||||
"hostnamectl",
|
||||
"set-hostname",
|
||||
args[0],
|
||||
})
|
||||
|
||||
return ok, resultLog
|
||||
}
|
||||
|
||||
func (op *AgentOsOperator) enableSwap() [][]string {
|
||||
@@ -342,12 +349,17 @@ func (op *AgentOsOperator) removeDockerExec() (bool, []string) {
|
||||
{
|
||||
"systemctl",
|
||||
"stop",
|
||||
"docker",
|
||||
"docker.service",
|
||||
},
|
||||
{
|
||||
"systemctl",
|
||||
"stop",
|
||||
"docker.socket",
|
||||
},
|
||||
{
|
||||
"systemctl",
|
||||
"disable",
|
||||
"docker",
|
||||
"docker.service",
|
||||
},
|
||||
}
|
||||
|
||||
@@ -508,7 +520,7 @@ func (op *AgentOsOperator) installDockerExec(args []string) (bool, []string) {
|
||||
"apt-transport-https",
|
||||
"ca-certificates",
|
||||
"curl",
|
||||
"gnupg-agent",
|
||||
"gnupg",
|
||||
"software-properties-common",
|
||||
}...)
|
||||
|
||||
@@ -518,26 +530,39 @@ func (op *AgentOsOperator) installDockerExec(args []string) (bool, []string) {
|
||||
return false, l
|
||||
}
|
||||
|
||||
dockerGPGFilePath := "/etc/apt/keyrings/docker.gpg"
|
||||
dockerAPTFilePath := "/etc/apt/sources.list.d/docker.list"
|
||||
dockerGPGSource := "https://mirrors.ustc.edu.cn/docker-ce/linux/ubuntu/gpg"
|
||||
dockerAPTSource := "https://mirrors.ustc.edu.cn/docker-ce/linux/ubuntu"
|
||||
|
||||
executor, resultLog := AllCompleteExecutor([][]string{
|
||||
{
|
||||
"rm",
|
||||
"-rf",
|
||||
"/etc/apt/keyrings/docker.gpg",
|
||||
dockerGPGFilePath,
|
||||
},
|
||||
{
|
||||
"rm",
|
||||
"-rf",
|
||||
dockerAPTFilePath,
|
||||
},
|
||||
{
|
||||
"mkdir",
|
||||
"-p",
|
||||
"/etc/apt/keyrings",
|
||||
},
|
||||
{
|
||||
"install",
|
||||
"-m",
|
||||
"0755",
|
||||
"-d",
|
||||
"/etc/apt/keyrings",
|
||||
},
|
||||
})
|
||||
if !executor {
|
||||
return false, append(resultLog, "创建docker-key gpg文件失败!")
|
||||
}
|
||||
|
||||
dockerGPGFilePath := "/etc/apt/keyrings/docker.gpg"
|
||||
dockerGPGSource := "https://mirrors.ustc.edu.cn/docker-ce/linux/ubuntu/gpg"
|
||||
dockerAPTSource := "https://mirrors.ustc.edu.cn/docker-ce/linux/ubuntu"
|
||||
|
||||
// 安装镜像的证书
|
||||
if !op.IsAgentInnerWall {
|
||||
// outside world
|
||||
@@ -545,12 +570,18 @@ func (op *AgentOsOperator) installDockerExec(args []string) (bool, []string) {
|
||||
dockerAPTSource = "https://download.docker.com/linux/ubuntu"
|
||||
}
|
||||
|
||||
ok, l2 := AllCommandExecutor([]string{
|
||||
"curl",
|
||||
"-fsSL",
|
||||
dockerGPGSource,
|
||||
"-o",
|
||||
dockerGPGFilePath,
|
||||
ok, l2 := PipelineCommandExecutor([][]string{
|
||||
{
|
||||
"curl",
|
||||
"-fsSL",
|
||||
dockerGPGSource,
|
||||
},
|
||||
{
|
||||
"gpg",
|
||||
"--dearmor",
|
||||
"-o",
|
||||
dockerGPGFilePath,
|
||||
},
|
||||
})
|
||||
if !ok {
|
||||
return false, append(l2, "下载docker gpg文件失败", dockerGPGSource, dockerAPTSource)
|
||||
@@ -560,31 +591,44 @@ func (op *AgentOsOperator) installDockerExec(args []string) (bool, []string) {
|
||||
}
|
||||
|
||||
resultOk, log2 := AllCompleteExecutor([][]string{
|
||||
{
|
||||
"gpg",
|
||||
"--dearmor",
|
||||
"-o",
|
||||
dockerGPGFilePath,
|
||||
},
|
||||
{
|
||||
"chmod",
|
||||
"a+r",
|
||||
dockerGPGFilePath,
|
||||
},
|
||||
{
|
||||
"add-apt-repository",
|
||||
"deb [arch=" + op.AgentArch + "] " + dockerAPTSource + " " + op.AgentOSReleaseCode + " stable",
|
||||
},
|
||||
//{
|
||||
// "add-apt-repository",
|
||||
// "deb [arch=" + op.AgentArch + " signed-by=" + dockerGPGFilePath + " ] " + dockerAPTSource + " " + op.AgentOSReleaseCode + " stable",
|
||||
//},
|
||||
})
|
||||
if !resultOk {
|
||||
return false, append(log2, "添加APT源失败!")
|
||||
}
|
||||
dockerAPTSourceCommand := "deb [arch=" + op.AgentArch + " signed-by=" + dockerGPGFilePath + "] " + dockerAPTSource + " " + op.AgentOSReleaseCode + " stable"
|
||||
|
||||
log.InfoF("dockerAPTSourceCommand is => %s ", dockerAPTSourceCommand)
|
||||
|
||||
ok, log3 := PipelineCommandExecutor([][]string{
|
||||
{
|
||||
"echo",
|
||||
dockerAPTSourceCommand,
|
||||
},
|
||||
{
|
||||
"tee",
|
||||
dockerAPTFilePath,
|
||||
},
|
||||
})
|
||||
if !ok {
|
||||
return false, append(log3, "添加APT源失败!")
|
||||
}
|
||||
|
||||
// look for specific docker-version to install
|
||||
AllCommandExecutor([]string{"apt-get", "update"})
|
||||
ok, log4 := AllCommandExecutor([]string{"apt-get", "update"})
|
||||
if !ok {
|
||||
return false, append(log4, "apt-get update 失败!")
|
||||
}
|
||||
|
||||
// ubuntu 内部
|
||||
|
||||
var specificDockerVersion string
|
||||
// hard code here 5:20.10.10~3-0~ubuntu-focal
|
||||
if strings.HasPrefix(args[0], "19") {
|
||||
@@ -593,19 +637,53 @@ func (op *AgentOsOperator) installDockerExec(args []string) (bool, []string) {
|
||||
specificDockerVersion = "5:20.10.10~3-0~ubuntu-" + op.AgentOSReleaseCode
|
||||
}
|
||||
|
||||
resultOk, log2 = AllCommandExecutor([]string{
|
||||
log.InfoF("需要安装的docker版本为 => %s", specificDockerVersion)
|
||||
|
||||
dockerStaffList := []string{
|
||||
"docker-ce=" + specificDockerVersion,
|
||||
"docker-ce-cli=" + specificDockerVersion,
|
||||
"containerd.io",
|
||||
"docker-compose-plugin",
|
||||
})
|
||||
if !resultOk {
|
||||
return false, log2
|
||||
}
|
||||
|
||||
for _, s := range dockerStaffList {
|
||||
resultOk, log2 = AllCommandExecutor(
|
||||
append(op.InstallCommandPrefix, s))
|
||||
if !resultOk {
|
||||
return false, append(log2, s, "安装失败!")
|
||||
}
|
||||
}
|
||||
|
||||
// 启动docker服务
|
||||
completeExecutor, log5 := AllCompleteExecutor([][]string{
|
||||
{
|
||||
"systemctl",
|
||||
"stop",
|
||||
"docker.service",
|
||||
},
|
||||
{
|
||||
"sleep",
|
||||
"2",
|
||||
},
|
||||
{
|
||||
"systemctl",
|
||||
"start",
|
||||
"docker.service",
|
||||
},
|
||||
{
|
||||
"systemctl",
|
||||
"enable",
|
||||
"docker.service",
|
||||
},
|
||||
})
|
||||
if !completeExecutor {
|
||||
return false, append(log5, "启动docker.service失败,请查明原因!", "journalctl -u docker -n 100 -f")
|
||||
}
|
||||
}
|
||||
|
||||
return true, nil
|
||||
return true, []string{
|
||||
"docker安装成功!",
|
||||
}
|
||||
}
|
||||
|
||||
func (op *AgentOsOperator) removeDockerCompose() [][]string {
|
||||
@@ -624,7 +702,9 @@ func (op *AgentOsOperator) removeDockerComposeExec() (bool, []string) {
|
||||
|
||||
commandName := "docker-compose"
|
||||
if !BasicCommandExists(commandName) {
|
||||
return true, nil
|
||||
return true, []string{
|
||||
commandName + " 卸载成功!",
|
||||
}
|
||||
}
|
||||
possibleDockerComposeFilePath := []string{
|
||||
"/usr/local/bin/" + commandName,
|
||||
@@ -636,7 +716,9 @@ func (op *AgentOsOperator) removeDockerComposeExec() (bool, []string) {
|
||||
AllCommandExecutor(removeDockerCommand)
|
||||
}
|
||||
|
||||
return true, nil
|
||||
return true, []string{
|
||||
commandName + " 卸载成功!",
|
||||
}
|
||||
}
|
||||
|
||||
func (op *AgentOsOperator) installDockerCompose() [][]string {
|
||||
@@ -652,6 +734,7 @@ func (op *AgentOsOperator) installDockerCompose() [][]string {
|
||||
}
|
||||
|
||||
func (op *AgentOsOperator) installDockerComposeExec() (bool, []string) {
|
||||
log.Info("准备安装docker-compose!")
|
||||
|
||||
// 安装特定版本的 docker-compose 2.18.0
|
||||
if op.OssOfflinePrefix == "" {
|
||||
@@ -659,9 +742,12 @@ func (op *AgentOsOperator) installDockerComposeExec() (bool, []string) {
|
||||
}
|
||||
|
||||
DockerComposeFile := op.OssOfflinePrefix + "docker-compose-linux-x86_64-v2.18.0"
|
||||
log.InfoF("需要安装的docker版本为 => %s", DockerComposeFile)
|
||||
|
||||
ok, resultLog := AllCommandExecutor([]string{
|
||||
"wget", DockerComposeFile,
|
||||
"wget",
|
||||
"--timeout=10",
|
||||
DockerComposeFile,
|
||||
"-O",
|
||||
"/usr/local/bin/docker-compose",
|
||||
})
|
||||
@@ -669,6 +755,7 @@ func (op *AgentOsOperator) installDockerComposeExec() (bool, []string) {
|
||||
return false, resultLog
|
||||
}
|
||||
|
||||
log.Debug("docker-compose下载成功!")
|
||||
if !BasicFileExistAndNotNull("/usr/local/bin/docker-compose") {
|
||||
return false, []string{"docker-compose 下载失败!"}
|
||||
}
|
||||
@@ -681,8 +768,8 @@ func (op *AgentOsOperator) installDockerComposeExec() (bool, []string) {
|
||||
"ln", "-s", "/usr/local/bin/docker-compose", "/usr/bin/docker-compose",
|
||||
},
|
||||
})
|
||||
|
||||
return true, nil
|
||||
log.Info("docker-compose安装成功!")
|
||||
return true, []string{"docker-compose安装成功!"}
|
||||
}
|
||||
func (op *AgentOsOperator) installHelm() [][]string {
|
||||
installHelmFunc := [][]string{
|
||||
@@ -1148,9 +1235,10 @@ func (op *AgentOsOperator) installZSHExec() (bool, []string) {
|
||||
} else {
|
||||
zshRemoteGitUrl = "https://gitee.com/mirrors/oh-my-zsh/raw/master/tools/install.sh"
|
||||
}
|
||||
|
||||
log.InfoF("开始下载zsh的安装脚本 => %s", zshRemoteGitUrl)
|
||||
resultOk, l := AllCommandExecutor([]string{
|
||||
"wget",
|
||||
"--timeout=5",
|
||||
zshRemoteGitUrl,
|
||||
"-O",
|
||||
"/root/wdd/zsh-install.sh",
|
||||
@@ -1178,6 +1266,7 @@ func (op *AgentOsOperator) installZSHExec() (bool, []string) {
|
||||
return false, log2
|
||||
}
|
||||
|
||||
log.Info("zsh安装完成! 开始进行zsh的配置!")
|
||||
modifyZSHOK, log3 := AllCompleteExecutor(
|
||||
[][]string{
|
||||
{
|
||||
@@ -1237,7 +1326,6 @@ func (op *AgentOsOperator) installZSHExec() (bool, []string) {
|
||||
"zsh",
|
||||
},
|
||||
})
|
||||
|
||||
if !modifyZSHOK {
|
||||
log.Warn("ZSH 安装成功,但是配置修改失败!")
|
||||
return true, log3
|
||||
|
||||
@@ -79,6 +79,9 @@ func BasicFileExistAndNotNull(filename string) bool {
|
||||
|
||||
func BasicPrettyPrint(resultOk bool, resultLog []string) {
|
||||
fmt.Printf("resultOK is => %#v\n", resultOk)
|
||||
if resultLog == nil || len(resultLog) == 0 {
|
||||
return
|
||||
}
|
||||
for _, s := range resultLog {
|
||||
fmt.Println(s)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user