[ Agent ] [ Base ] - refresh for euler

This commit is contained in:
zeaslity
2024-01-24 17:09:48 +08:00
parent 2c1cde980c
commit 4ffd48500c
10 changed files with 111 additions and 104 deletions

View File

@@ -27,6 +27,8 @@ type AgentOsOperator struct {
IsOsTypeCentOS bool `json:"is_os_type_centos",comment:"主机操作系统是否为centos系列"`
IsOsTypeEuler bool `json:"is_os_type_euler",comment:"主机操作系统是否为国产欧拉系列"`
IsAgentInnerWall bool `json:"is_agent_inner_wall",comment:"主机是否身处国内"`
AgentArch string `json:"agent_arch",comment:"主机的CPU架构可选为amd64 arm64"`
@@ -353,6 +355,7 @@ func (op *AgentOsOperator) installDefaultSSHKeyExec(funcArgs []string) (bool, []
// ssh-keygen -t ed25519 -C "wdd@cmii.com"
// ssh-keygen -t rsa -P "" -f /root/.ssh/id_rsa -b 4096
BasicCreateFolder("/root/.ssh/")
// check key exists
if BasicFileExistAndNotNull("/root/.ssh/id_ed25519") {
@@ -598,6 +601,8 @@ func (op *AgentOsOperator) installDockerExec(args []string) (bool, []string) {
BasicCreateFolder("/root/wdd/")
op.removeDockerExec()
if op.IsOsTypeUbuntu {
if !op.CanAccessInternet {
@@ -777,11 +782,44 @@ func (op *AgentOsOperator) installDockerExec(args []string) (bool, []string) {
return false, append(log5, "启动docker.service失败请查明原因", "journalctl -u docker -n 100 -f")
}
} else if op.IsOsTypeCentOS {
if !op.CanAccessInternet {
if !op.CanAccessInternet || op.IsOsTypeEuler {
// offline version
log.InfoF("[installDockerExec] - centos can not access to internet, installing by offline !")
return op.installDockerOfflineExec(args)
}
// download
var dockerRepo string
if op.IsAgentInnerWall {
dockerRepo = "https://mirrors.ustc.edu.cn/docker-ce/linux/centos/docker-ce.repo"
} else {
dockerRepo = "https://download.docker.com/linux/centos/docker-ce.repo"
}
AllCommandExecutor(append(op.InstallCommandPrefix, "yum-utils"))
ok, resultLog := AllCommandExecutor(
[]string{
"yum-config-manager",
"--add-repo",
dockerRepo,
},
)
if !ok {
return false, resultLog
}
// todo 20 version
resultOk, l := AllCommandExecutor(append(op.InstallCommandPrefix, "docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin"))
if !resultOk {
return false, l
}
systemdUp, log2 := BasicSystemdUp("docker")
if !systemdUp {
return false, log2
}
}
return true, []string{
@@ -1995,7 +2033,7 @@ func (op *AgentOsOperator) chronyToMasterExec(args []string) (bool, []string) {
if op.IsOsTypeCentOS {
if !op.CanAccessInternet {
return op.chronyToMasterCentOsOfflineExec(args)
return op.chronyToMasterByDocker(args)
}
// install ntp
@@ -2074,9 +2112,7 @@ func (op *AgentOsOperator) chronyToMasterExec(args []string) (bool, []string) {
}
}
func (op *AgentOsOperator) chronyToMasterCentOsOfflineExec(args []string) (bool, []string) {
// todo
func (op *AgentOsOperator) chronyToMasterByDocker(args []string) (bool, []string) {
return true, nil
}

View File

@@ -2,23 +2,26 @@ package executor
import (
"testing"
"wdd.io/agent-go/assert"
"wdd.io/agent-go/register"
)
var agentOP = &AgentOsOperator{
InstallCommandPrefix: []string{
"apt-get", "install", "-y",
"yum", "install", "-y",
},
RemoveCommandPrefix: []string{"apt", "remove", "-y"},
RemoveCommandPrefix: []string{"yum", "remove", "-y"},
CanAccessInternet: true,
IsOsTypeUbuntu: true,
IsOsTypeUbuntu: false,
IsOsTypeCentOS: true,
IsOsTypeEuler: true,
IsAgentInnerWall: true,
AgentArch: "amd64",
AgentOSReleaseCode: "focal",
AgentServerInfo: &register.AgentServerInfo{
ServerName: "",
ServerIPPbV4: "",
ServerIPInV4: "192.168.0.8",
ServerIPInV4: "10.250.0.147",
ServerIPPbV6: "",
ServerIPInV6: "",
Location: "",
@@ -39,23 +42,39 @@ var agentOP = &AgentOsOperator{
AgentVersion: "",
TopicName: "",
},
OssOfflinePrefix: "http://10.250.0.100:9000/octopus/",
}
func TestBaseFunc(t *testing.T) {
//agentOP.Command("shutdownFirewall")
//agentOP.Command("modifyHostname")
//agentOP.Command("disableSwap")
//agentOP.Command("enableSwap")
//agentOP.Command("removeDocker")
//agentOP.Command("installDocker", "20")
//agentOP.Command("removeDockerCompose")
//agentOP.Command("installDockerCompose")
//agentOP.Command("installHelm")
//agentOP.Command("installHarbor")
//agentOP.Command("chronyToPublicNTP")
//agentOP.Command("chronyToMaster", "192.168.0.8")
//agentOP.Command("installZSH")
agentOP.Command("ok")
//command := "DISABLE_SELINUX"
//command := "installDocker"
//command := "installDockerCompose"
command := "installHarbor"
funcArgs := []string{
"10.250.0.147",
"",
"",
"",
}
//agentOP.Exec("shutdownFirewall")
//agentOP.Exec("modifyHostname")
//agentOP.Exec("disableSwap")
//agentOP.Exec("enableSwap")
//agentOP.Exec("removeDocker")
//agentOP.Exec("installDocker", "20")
//agentOP.Exec("removeDockerCompose")
//agentOP.Exec("installDockerCompose")
//agentOP.Exec("installHelm")
//agentOP.Exec("installHarbor")
//agentOP.Exec("chronyToMaster", "192.168.0.8")
//agentOP.Exec("installZSH")
//agentOP.Exec("ok")
exec, strings := agentOP.Exec(command, funcArgs...)
assert.Equal(t, exec, true, "exec should be true!")
t.Logf("[%s] exec result are %s", command, strings)
}

View File

@@ -17,6 +17,7 @@ func BuildAgentOsOperator(agentInfo *status.AgentInfo, ossOfflinePrefix string)
CanAccessInternet: true,
IsOsTypeUbuntu: true,
IsOsTypeCentOS: false,
IsOsTypeEuler: false,
IsAgentInnerWall: false,
AgentArch: "amd64",
AgentOSReleaseCode: "focal",
@@ -42,21 +43,25 @@ func detectByAgentStatusInfo(agentInfo *status.AgentInfo, os *AgentOsOperator) {
bytes, _ := json.Marshal(agentInfo)
log.DebugF("[detectByAgentStatusInfo] - agent info is => %s", string(bytes))
if strings.Contains(agentInfo.HostInfo.Platform, "openeuler") || strings.Contains(agentInfo.HostInfo.PlatformFamily, "platformFamily") {
if strings.Contains(agentInfo.HostInfo.Platform, "openeuler") || strings.Contains(agentInfo.HostInfo.PlatformFamily, "rehl") {
// centos
os.IsOsTypeUbuntu = false
os.IsOsTypeCentOS = true
if strings.Contains(agentInfo.HostInfo.Platform, "openeuler") {
os.IsOsTypeEuler = true
}
os.InstallCommandPrefix = []string{
"yum", "install", "-y",
}
os.RemoveCommandPrefix = []string{
"yum", "remove",
"yum", "remove", "-y",
}
} else if strings.Contains(agentInfo.HostInfo.PlatformFamily, "debian") {
// ubuntu
os.IsOsTypeUbuntu = true
os.IsOsTypeCentOS = false
os.IsOsTypeEuler = false
os.RemoveCommandPrefix = []string{"apt", "remove", "-y"}
os.InstallCommandPrefix = []string{
"apt-get", "install", "--allow-downgrades", "-y",

View File

@@ -0,0 +1,12 @@
#!/bin/bash
rm -rf go1.21.6.linux-amd64.tar.gz
wget http://10.250.0.100:9000/octopus/go1.21.6.linux-amd64.tar.gz -O go1.21.6.linux-amd64.tar.gz
rm -rf /usr/local/go && tar -C /usr/local -xzf go1.21.6.linux-amd64.tar.gz
sed -i "$ a export PATH=\$PATH:/usr/local/go/bin" /root/.bashrc
source /root/.bashrc
go version
go env -w GO111MODULE=on
go env -w GOPROXY=https://goproxy.cn,direct