[ Agent ] [ BASE ] - add docker daemon config modify
This commit is contained in:
@@ -3,6 +3,7 @@ package executor
|
||||
import (
|
||||
"agent-go/register"
|
||||
"fmt"
|
||||
"net"
|
||||
"strings"
|
||||
)
|
||||
|
||||
@@ -321,7 +322,8 @@ func (op *AgentOsOperator) disableSwapExec() (bool, []string) {
|
||||
|
||||
func (op *AgentOsOperator) installDefaultSSHKeyExec(funcArgs []string) (bool, []string) {
|
||||
|
||||
// ssh-keygen -t ed25519 -C "wdd@cmii.com" -N "octopus_standard_phrase"
|
||||
// ssh-keygen -t ed25519 -C "wdd@cmii.com"
|
||||
// ssh-keygen -t rsa -P "" -f /root/.ssh/id_rsa -b 4096
|
||||
|
||||
// check key exists
|
||||
if BasicFileExistAndNotNull("/root/.ssh/id_ed25519") {
|
||||
@@ -349,6 +351,12 @@ func (op *AgentOsOperator) installDefaultSSHKeyExec(funcArgs []string) (bool, []
|
||||
}
|
||||
}
|
||||
|
||||
AllCommandExecutor([]string{
|
||||
"chmod",
|
||||
"600",
|
||||
"/root/.ssh/id_ed25519",
|
||||
})
|
||||
|
||||
// check
|
||||
if BasicGrepItemInFile("wdd@cmii.com", "/root/.ssh/authorized_keys") {
|
||||
return true, nil
|
||||
@@ -936,6 +944,48 @@ func (op *AgentOsOperator) modifyDockerConfig(args []string) [][]string {
|
||||
}
|
||||
|
||||
func (op *AgentOsOperator) modifyDockerConfigExec(args []string) (bool, []string) {
|
||||
|
||||
dockerDaemonFile := "/etc/docker/daemon.json"
|
||||
// check docker daemon json exist
|
||||
if BasicFileExistAndNotNull(dockerDaemonFile) {
|
||||
AllCommandExecutor([]string{
|
||||
"mv",
|
||||
dockerDaemonFile,
|
||||
"/etc/docker/daemon-json.backup",
|
||||
})
|
||||
}
|
||||
|
||||
// download new
|
||||
ok, resultLog := BasicDownloadFile(op.OssOfflinePrefix+"docker-daemon-template.json", dockerDaemonFile)
|
||||
if !ok {
|
||||
return false, append(resultLog, "[modifyDockerConfigExec] - error download docker-daemon-template.json !")
|
||||
}
|
||||
|
||||
// modify config
|
||||
parseIP := net.ParseIP(args[0])
|
||||
if parseIP == nil {
|
||||
return false, []string{
|
||||
"[modifyDockerConfigExec] - ip args error !",
|
||||
args[0],
|
||||
}
|
||||
}
|
||||
if !BasicReplace(dockerDaemonFile, "DockerRegisterDomain", args[0]) {
|
||||
return false, []string{
|
||||
"[modifyDockerConfigExec] - modify docker daemon config error !",
|
||||
}
|
||||
}
|
||||
|
||||
// restart docker
|
||||
if !PureResultSingleExecute([]string{
|
||||
"systemctl",
|
||||
"restart",
|
||||
"docker.service",
|
||||
}) {
|
||||
return false, []string{
|
||||
"[modifyDockerConfigExec] - restart docker.service error !",
|
||||
}
|
||||
}
|
||||
|
||||
return true, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -39,6 +39,11 @@ public enum BaseFunctionEnum {
|
||||
"安装Docker Compose, 默认为2.18.0版本"
|
||||
),
|
||||
|
||||
MODIFY_DOCKER_CONFIG(
|
||||
"modifyDockerConfig",
|
||||
"修改docker daemon config, 参数为 Harbor服务器的IP"
|
||||
),
|
||||
|
||||
INSTALL_HARBOR(
|
||||
"installHarbor",
|
||||
"安装Harbor, 默认为2.9.0版本"
|
||||
|
||||
@@ -115,9 +115,10 @@ public class BaseFuncScheduler {
|
||||
}
|
||||
|
||||
List<BaseFunctionEnum> masterNodeDurationTaskList = List.of(
|
||||
BaseFunctionEnum.INSTALL_DOCKER,
|
||||
BaseFunctionEnum.INSTALL_DOCKER_COMPOSE,
|
||||
BaseFunctionEnum.INSTALL_HARBOR
|
||||
BaseFunctionEnum.INSTALL_DEFAULT_SSH_KEY
|
||||
// BaseFunctionEnum.INSTALL_DOCKER,
|
||||
// BaseFunctionEnum.INSTALL_DOCKER_COMPOSE,
|
||||
// BaseFunctionEnum.INSTALL_HARBOR
|
||||
);
|
||||
|
||||
for (BaseFunctionEnum durationBaseFunc : masterNodeDurationTaskList) {
|
||||
@@ -135,8 +136,6 @@ public class BaseFuncScheduler {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -53,11 +53,11 @@ public class TestBaseFuncScheduler {
|
||||
projectDeployContext.setMasterNode(serverInfoPO);
|
||||
|
||||
|
||||
// baseFuncScheduler.runProcedure(projectDeployContext);
|
||||
baseFuncScheduler.runProcedure(projectDeployContext);
|
||||
|
||||
// harborFuncScheduler.runProcedure(projectDeployContext);
|
||||
|
||||
appFuncScheduler.runProcedure(projectDeployContext);
|
||||
// appFuncScheduler.runProcedure(projectDeployContext);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user