from vscode

This commit is contained in:
zeaslity
2023-11-13 10:25:15 +08:00
parent cdfa4b5d04
commit 3f06350089
8 changed files with 42 additions and 30 deletions

View File

@@ -907,19 +907,19 @@ func (op *AgentOsOperator) installHarbor() [][]string {
//{
// "rm",
// "-rf",
// "/root/wdd/harbor-offline-installer-v2.1.0.tgz",
// "/root/wdd/harbor-offline-installer-v2.9.0.tgz",
//},
//{
// "wget",
// "--no-check-certificate",
// op.OssOfflinePrefix + "harbor-offline-installer-v2.1.0.tgz",
// op.OssOfflinePrefix + "harbor-offline-installer-v2.9.0.tgz",
// "-O",
// "/root/wdd/harbor-offline-installer-v2.1.0.tgz",
// "/root/wdd/harbor-offline-installer-v2.9.0.tgz",
//},
{
"tar",
"-zvxf",
"/root/wdd/harbor-offline-installer-v2.1.0.tgz",
"/root/wdd/harbor-offline-installer-v2.9.0.tgz",
"-C",
"/root/wdd/",
},
@@ -994,7 +994,7 @@ func (op *AgentOsOperator) installHarborExec() (bool, []string) {
resultOk, resultLog := AllCommandExecutor([]string{
"docker-compose",
"-f",
"/root/wdd/harbor/harbor.yml",
"/root/wdd/harbor/docker-compose.yml",
"up",
"-d",
})
@@ -1008,7 +1008,7 @@ func (op *AgentOsOperator) installHarborExec() (bool, []string) {
}
// download offline file
harborOfflineFileURL := op.OssOfflinePrefix + "harbor-offline-installer-v2.1.0.tgz"
harborOfflineFileURL := op.OssOfflinePrefix + "harbor-offline-installer-v2.9.0.tgz"
log.InfoF("[install harbor] - start to download harbor offline installer from => %s !", harborOfflineFileURL)
resultOk, resultLog := AllCompleteExecutor([][]string{
{
@@ -1019,7 +1019,7 @@ func (op *AgentOsOperator) installHarborExec() (bool, []string) {
{
"rm",
"-rf",
"/root/wdd/harbor-offline-installer-v2.1.0.tgz",
"/root/wdd/harbor-offline-installer-v2.9.0.tgz",
},
{
"rm",
@@ -1031,14 +1031,14 @@ func (op *AgentOsOperator) installHarborExec() (bool, []string) {
"--no-check-certificate",
harborOfflineFileURL,
"-qO",
"/root/wdd/harbor-offline-installer-v2.1.0.tgz",
"/root/wdd/harbor-offline-installer-v2.9.0.tgz",
}},
)
if !resultOk {
return false, append(resultLog, "download harbor offline installer failed!")
}
if !BasicFileExistAndNotNull("/root/wdd/harbor-offline-installer-v2.1.0.tgz") {
if !BasicFileExistAndNotNull("/root/wdd/harbor-offline-installer-v2.9.0.tgz") {
return false, []string{"download harbor offline installer failed!"}
}
@@ -1047,7 +1047,7 @@ func (op *AgentOsOperator) installHarborExec() (bool, []string) {
{
"tar",
"-zvxf",
"/root/wdd/harbor-offline-installer-v2.1.0.tgz",
"/root/wdd/harbor-offline-installer-v2.9.0.tgz",
"-C",
"/root/wdd/",
},
@@ -1077,19 +1077,19 @@ func (op *AgentOsOperator) installHarborExec() (bool, []string) {
{
"sed",
"-i",
"s/$HarborHostName/" + op.AgentServerInfo.ServerIPInV4 + "/g",
"s/HarborHostName/" + op.AgentServerInfo.ServerIPInV4 + "/g",
"/root/wdd/harbor/harbor.yml",
},
{
"sed",
"-i",
"s/$HarborHostPort/8033/g",
"s/HarborHostPort/8033/g",
"/root/wdd/harbor/harbor.yml",
},
{
"sed",
"-i",
"s/$HarborAdminPas/V2ryStr@ngPss/g",
"s/HarborAdminPas/V2ryStr@ngPss/g",
"/root/wdd/harbor/harbor.yml",
},
{
@@ -1103,12 +1103,16 @@ func (op *AgentOsOperator) installHarborExec() (bool, []string) {
// install
log.Info("[install harbor] - going to start harbor !")
ReadTimeCommandExecutor([]string{
executor := ReadTimeCommandExecutor([]string{
"bash",
"/root/wdd/harbor/install.sh",
"--with-chartmuseum",
},
)
if !executor {
return false, []string{
"[install harbor] - harbor start FAILED !",
}
}
msg := "[install harbor] - harbor start complete !"
log.Info(msg)

View File

@@ -82,7 +82,7 @@ func Execute(em *ExecutionMessage) (bool, []string) {
if err != nil {
resultLog = append(resultLog, " 命令执行错误如下 ", err.Error())
}
resultLog = append(resultLog, fmt.Sprintf("命令 %s 执行结果为 %s", executionContent, strconv.FormatBool(ok)))
resultLog = append(resultLog, fmt.Sprintf("命令 %v 执行结果为 %s", executionContent, strconv.FormatBool(ok)))
// debug
log.DebugF("%v", resultLog)

View File

@@ -185,7 +185,7 @@ func PureResultSingleExecuteBatch(singleCommandList [][]string) (resultOK bool)
}
// ReadTimeCommandExecutor 执行命令,并且实时返回结果
func ReadTimeCommandExecutor(singleLineCommand []string) {
func ReadTimeCommandExecutor(singleLineCommand []string) bool {
cmd := exec.Command(singleLineCommand[0], singleLineCommand[1:]...)
stdout, err := cmd.StdoutPipe()
if err != nil {
@@ -205,8 +205,10 @@ func ReadTimeCommandExecutor(singleLineCommand []string) {
if err := cmd.Wait(); err != nil {
log.ErrorF("command %v result error => %v", singleLineCommand, err)
return false
}
return true
}
func realTimeOutput(r io.Reader) {

View File

@@ -3,9 +3,10 @@ package executor
import (
"context"
"fmt"
"net"
"github.com/mittwald/goharbor-client/v5/apiv2"
"github.com/mittwald/goharbor-client/v5/apiv2/model"
"net"
)
type HarborOperator struct {
@@ -58,18 +59,20 @@ func (hOp *HarborOperator) CreateProjectExec(funcArgs []string) (bool, []string)
targetHarborHost := funcArgs[0]
parseIP := net.ParseIP(targetHarborHost)
if parseIP != nil {
if parseIP == nil {
return false, []string{
"[Harbor CreateProjectExec] - ip format is wrong!",
fmt.Sprintf("[Harbor CreateProjectExec] - ip format is wrong! parseIP is => %s ", parseIP),
}
}
hOp.TargetHarborHost = string(parseIP) + ":" + hOp.HarborPort
hOp.TargetHarborHost = "http://" + targetHarborHost + ":" + hOp.HarborPort + "/api"
log.DebugF("[Harbor CreateProjectExec] - harbor host is => %s", hOp.TargetHarborHost)
// check connection
client, err := apiv2.NewRESTClientForHost(hOp.TargetHarborHost, hOp.HarborAdminUser, hOp.HarborAdminPass, nil)
if err != nil {
errorLog := fmt.Sprintf("Error creating REST client: %v\n", err)
errorLog := fmt.Sprintf("Error creating REST client: %s\n", err.Error())
log.Error(errorLog)
return false, []string{errorLog}
}
@@ -94,13 +97,13 @@ func (hOp *HarborOperator) CreateProjectExec(funcArgs []string) (bool, []string)
ctx := context.Background()
err = client.NewProject(ctx, cmiiProject)
if err != nil {
errorLog := fmt.Sprintf("Error creating project: %v\n", err)
errorLog := fmt.Sprintf("Error creating project: %s\n", err.Error())
return false, []string{errorLog}
}
err = client.NewProject(ctx, rancherProject)
if err != nil {
errorLog := fmt.Sprintf("Error creating project: %v\n", err)
errorLog := fmt.Sprintf("Error creating project: %s\n", err.Error())
return false, []string{errorLog}
}