[ Cmii ] [ Octopus ] - optimize octopus procedure

This commit is contained in:
zeaslity
2024-01-31 17:46:58 +08:00
parent 04e2712d9c
commit a83e7da008
11 changed files with 157 additions and 108 deletions

View File

@@ -729,6 +729,7 @@ func (op *AgentOsOperator) installDockerExec(args []string) (bool, []string) {
"20",
}
}
// todo ubuntu 22.04
// ubuntu 内部
var specificDockerVersion string

View File

@@ -69,7 +69,8 @@ func (hOp *HarborOperator) Exec(baseFuncName string, funcArgs ...string) (bool,
func (hOp *HarborOperator) CreateProjectExec(funcArgs []string) (bool, []string) {
if hOp.TargetHarborClient == nil {
ok, createClient := hOp.CheckAndBuildHarborClient(funcArgs[0], true)
ok, createClient := hOp.CheckAndBuildHarborClient(funcArgs[0], "", true)
if !ok {
return false, []string{
"[Harbor Create Project] - Error !",
@@ -116,7 +117,7 @@ func (hOp *HarborOperator) CreateProjectExec(funcArgs []string) (bool, []string)
return true, []string{successLog}
}
func (hOp *HarborOperator) CheckAndBuildHarborClient(targetHarborHost string, isTarget bool) (bool, *apiv2.RESTClient) {
func (hOp *HarborOperator) CheckAndBuildHarborClient(targetHarborHost string, targetHarborPort string, isTarget bool) (bool, *apiv2.RESTClient) {
log.InfoF("[Harbor Client Create] - start to create harbor client %s", targetHarborHost)
@@ -127,12 +128,15 @@ func (hOp *HarborOperator) CheckAndBuildHarborClient(targetHarborHost string, is
)
return false, nil
}
if targetHarborPort == "" {
targetHarborPort = hOp.HarborPort
}
if isTarget {
hOp.TargetHarborHost = "http://" + targetHarborHost + ":" + hOp.HarborPort + "/api/"
hOp.TargetHarborHost = "http://" + targetHarborHost + ":" + targetHarborPort + "/api/"
log.DebugF("[Harbor Client Create] - harbor host is => %s", hOp.TargetHarborHost)
} else {
hOp.SourceHarborHost = "http://" + targetHarborHost + ":" + hOp.HarborPort + "/api/"
hOp.SourceHarborHost = "http://" + targetHarborHost + ":" + targetHarborPort + "/api/"
log.DebugF("[Harbor Client Create] - harbor host is => %s", hOp.SourceHarborHost)
}
@@ -156,7 +160,7 @@ func (hOp *HarborOperator) CheckAndBuildHarborClient(targetHarborHost string, is
func (hOp *HarborOperator) ListProjectExec(funcArgs []string) (bool, []string) {
if hOp.TargetHarborClient == nil {
ok, createClient := hOp.CheckAndBuildHarborClient(funcArgs[0], true)
ok, createClient := hOp.CheckAndBuildHarborClient(funcArgs[0], "", true)
if !ok {
return false, []string{
"[Harbor Create Project ] - Error !",
@@ -190,7 +194,7 @@ func (hOp *HarborOperator) ListProjectExec(funcArgs []string) (bool, []string) {
func (hOp *HarborOperator) SyncProjectExec(funcArgs []string) (bool, []string) {
if hOp.TargetHarborClient == nil {
ok, createClient := hOp.CheckAndBuildHarborClient(funcArgs[0], true)
ok, createClient := hOp.CheckAndBuildHarborClient(funcArgs[0], "", true)
if !ok {
return false, []string{
"[Harbor Sync Project ] - Error !",
@@ -201,7 +205,14 @@ func (hOp *HarborOperator) SyncProjectExec(funcArgs []string) (bool, []string) {
targetClient := hOp.TargetHarborClient
if hOp.SourceHarborClient == nil {
ok, createClient := hOp.CheckAndBuildHarborClient(funcArgs[1], false)
realHost := funcArgs[1]
realPort := ""
if strings.Contains(funcArgs[1], ":") {
split := strings.Split(funcArgs[1], ":")
realHost = split[0]
realPort = split[1]
}
ok, createClient := hOp.CheckAndBuildHarborClient(realHost, realPort, false)
if !ok {
return false, []string{
"[Harbor Sync Project ] - Error !",
@@ -355,7 +366,7 @@ func (hOp *HarborOperator) SyncProjectExec(funcArgs []string) (bool, []string) {
func (hOp *HarborOperator) SyncStatusExec(funcArgs []string) (bool, []string) {
if hOp.TargetHarborClient == nil {
ok, createClient := hOp.CheckAndBuildHarborClient(funcArgs[0], true)
ok, createClient := hOp.CheckAndBuildHarborClient(funcArgs[0], "", true)
if !ok {
return false, []string{
"[ Sync Status ] - Error !",