diff --git a/agent-go/executor/BaseFunction.go b/agent-go/executor/BaseFunction.go index 676d9d0..ca3c8b4 100644 --- a/agent-go/executor/BaseFunction.go +++ b/agent-go/executor/BaseFunction.go @@ -963,8 +963,144 @@ func (op *AgentOsOperator) installHarbor() [][]string { return installHarborFunc } +// installHarborExec install harbor offline func (op *AgentOsOperator) installHarborExec() (bool, []string) { - return true, nil + + // check docker-compose + if !BasicCommandExists("docker-compose") { + return false, []string{ + "docker-compose uninstalled ! can't install harbor!", + } + } + + // check already installed + ok, _ := PipelineCommandExecutor([][]string{ + { + "docker", + "ps", + }, + { + "grep", + "-q", + "harbor-core", + }, + }) + if ok { + alreadyInstalledLog := []string{ + "install harbor, container harbor-core already running! harbor installed !", + } + + log.Info(alreadyInstalledLog[0]) + + resultOk, resultLog := AllCommandExecutor([]string{ + "docker-compose", + "-f", + "/root/wdd/harbor/harbor.yml", + "up", + "-d", + }) + + if !resultOk { + alreadyInstalledLog = append(alreadyInstalledLog, "restart docker-compose file failed !") + return false, append(alreadyInstalledLog, resultLog...) + } else { + return true, append(alreadyInstalledLog, "restart docker-compose file success !") + } + } + + // download offline file + resultOk, resultLog := AllCompleteExecutor([][]string{ + { + "mkdir", + "-p", + "/root/wdd/", + }, + { + "rm", + "-rf", + "/root/wdd/harbor-offline-installer-v2.1.0.tgz", + }, + { + "rm", + "-rf", + "/root/wdd/harbor", + }, + { + "wget", + "--no-check-certificate", + g.BaseFuncOssUrlPrefix + "harbor-offline-installer-v2.1.0.tgz", + "-qO", + "/root/wdd/harbor-offline-installer-v2.1.0.tgz", + }}, + ) + if !resultOk { + return false, append(resultLog, "download harbor offline installer failed!") + } + + if !BasicFileExistAndNotNull("/root/wdd/harbor-offline-installer-v2.1.0.tgz") { + return false, []string{"download harbor offline installer failed!"} + } + + // unzip + AllCompleteExecutor([][]string{ + { + "tar", + "-zvxf", + "/root/wdd/harbor-offline-installer-v2.1.0.tgz", + "-C", + "/root/wdd/", + }, + { + "rm", + "-rf", + "/root/wdd/harbor/harbor.yml", + }, + }) + + // configuration + AllCommandExecutor([]string{ + "wget", + "--no-check-certificate", + g.BaseFuncOssUrlPrefix + "harbor-config-template.yml", + "-qO", + "/root/wdd/harbor/harbor.yml", + }) + if !BasicFileExistAndNotNull("/root/wdd/harbor/harbor.yml") { + return false, []string{"harbor config template file download error !"} + } + + AllCompleteExecutor([][]string{ + { + "sed", + "-i", + "s/$HarborHostName/" + op.AgentServerInfo.ServerIPInV4 + "/g", + "/root/wdd/harbor/harbor.yml", + }, + { + "sed", + "-i", + "s/$HarborHostPort/8033/g", + "/root/wdd/harbor/harbor.yml", + }, + { + "sed", + "-i", + "s/$HarborPassword/V2ryStr@ngPss/g", + "/root/wdd/harbor/harbor.yml", + }}) + + log.InfoF("harbor config changed success to => %s!", op.AgentServerInfo.ServerIPInV4) + + // install + executor, l := AllCommandExecutor([]string{ + "/root/wdd/harbor/install.sh", + "--with-chartmuseum", + }) + if !executor { + return false, l + } + + return true, l } func (op *AgentOsOperator) chronyToPublicNTP() [][]string { @@ -1069,7 +1205,7 @@ func (op *AgentOsOperator) chronyToPublicNTPExec() (bool, []string) { { "sed", "-i", - "s/pool ntp.ubuntu.com iburst/server ntp2.aliyun.com iburst/g", + "s/pool ntp.ubuntu.com/server ntp2.aliyun.com/g", chronyFile, }, { diff --git a/server/src/main/java/io/wdd/func/auto/service/BaseFuncScheduler.java b/server/src/main/java/io/wdd/func/auto/service/BaseFuncScheduler.java index b8001fe..20e0113 100644 --- a/server/src/main/java/io/wdd/func/auto/service/BaseFuncScheduler.java +++ b/server/src/main/java/io/wdd/func/auto/service/BaseFuncScheduler.java @@ -88,6 +88,7 @@ public class BaseFuncScheduler { List masterNodeProcedureList = List.of( BaseFunctionEnum.DISABLE_SWAP, BaseFunctionEnum.SHUTDOWN_FIREWALL, + BaseFunctionEnum.INSTALL_CHRONY, BaseFunctionEnum.CHRONY_TO_PUBLIC_NTP, BaseFunctionEnum.INSTALL_DEFAULT_SSH_KEY, BaseFunctionEnum.INSTALL_DOCKER,