[agent-operator] - cmii deploy part - basic accomplished

This commit is contained in:
zeaslity
2024-06-14 11:41:38 +08:00
parent d86bc43b28
commit f3db4a9ff6
7 changed files with 202 additions and 102 deletions

View File

@@ -2,7 +2,6 @@ package agent_deploy
import (
"os"
"strings"
image2 "wdd.io/agent-common/image"
"wdd.io/agent-common/logger"
"wdd.io/agent-common/utils"
@@ -168,72 +167,49 @@ func configMapDeploy(common *z_dep.CommonEnvironmentConfig) {
}
// CmiiEnvironmentDeploy 部署完整的CMII环境的所有组件
func CmiiEnvironmentDeploy(isCompleteDeploy bool, cmiiNameSpace string, backendImageVersionMap, frontendImageVersionMap map[string]string) (applyYamlFolder string) {
folderPrefix := "/home/wdd/IdeaProjects/ProjectOctopus/agent-deploy/" + cmiiNameSpace + "/"
tenantEnv := cmiiNameSpace
if strings.Contains(cmiiNameSpace, "-") {
split := strings.Split(cmiiNameSpace, "-")
tenantEnv = split[len(split)-1]
}
// common environment
common := &z_dep.CommonEnvironmentConfig{
WebIP: "lab.uavcmlc.com",
WebPort: "",
HarborIP: image2.CmiiHarborPrefix,
HarborPort: "",
Namespace: cmiiNameSpace,
TagVersion: "5.5.0",
TenantEnv: tenantEnv,
ApplyFilePrefix: folderPrefix,
}
func CmiiEnvironmentDeploy(isCompleteDeploy bool, commonEnv *z_dep.CommonEnvironmentConfig, backendImageVersionMap, frontendImageVersionMap map[string]string) {
// clear old apply file
_ = os.Mkdir(folderPrefix, os.ModePerm)
_ = os.Mkdir(commonEnv.ApplyFilePrefix, os.ModePerm)
oldApplyFileFolder := folderPrefix + "old"
oldApplyFileFolder := commonEnv.ApplyFilePrefix + "old"
utils.RemoveFolderComplete(oldApplyFileFolder)
_ = os.Mkdir(oldApplyFileFolder, os.ModePerm)
// move all apply file to old folder
_ = utils.FolderMoveFiles(folderPrefix, oldApplyFileFolder)
_ = utils.FolderMoveFiles(commonEnv.ApplyFilePrefix, oldApplyFileFolder)
// clear all middleware data
// ignore redis rabbitmq mongo nacos emqx
// sync mysql-data
// generate
common.GenerateApplyFilePath()
commonEnv.GenerateApplyFilePath()
// generate new apply file for specific environment
if isCompleteDeploy {
// pvc
b_middle.PVCDeploy(common)
b_middle.PVCDeploy(commonEnv)
// middlewares
b_middle.MidMySQlDeploy(common)
b_middle.MidRedisDeploy(common)
b_middle.MidEmqxDeploy(common)
b_middle.MidMongoDeploy(common)
b_middle.MidRabbitMQDeploy(common)
b_middle.MidNacosDeploy(common)
b_middle.MidMySQlDeploy(commonEnv)
b_middle.MidRedisDeploy(commonEnv)
b_middle.MidEmqxDeploy(commonEnv)
b_middle.MidMongoDeploy(commonEnv)
b_middle.MidRabbitMQDeploy(commonEnv)
b_middle.MidNacosDeploy(commonEnv)
configMapDeploy(common)
c_app.IngressDeploy(common)
configMapDeploy(commonEnv)
c_app.IngressDeploy(commonEnv)
}
// frontend
// frontend
frontendDeploy(common, frontendImageVersionMap)
frontendDeploy(commonEnv, frontendImageVersionMap)
// backend
backendDeploy(common, backendImageVersionMap)
backendDeploy(commonEnv, backendImageVersionMap)
// apply for them
return folderPrefix
}

View File

@@ -4,6 +4,7 @@ import (
"bytes"
"fmt"
"github.com/go-playground/validator/v10"
"path/filepath"
"text/template"
"wdd.io/agent-common/assert"
"wdd.io/agent-common/logger"
@@ -82,22 +83,21 @@ func (env *CommonEnvironmentConfig) GenerateApplyFilePath() {
Asserter.NotEmpty(env.ApplyFilePrefix, "apply file prefix is empty!")
K8sDashboardApplyFilePath = env.ApplyFilePrefix + "k8s-dashboard.yaml"
EmqxApplyFilePath = env.ApplyFilePrefix + "k8s-emqx.yaml"
MongoApplyFilePath = env.ApplyFilePrefix + "k8s-mongo.yaml"
RabbitMQApplyFilePath = env.ApplyFilePrefix + "k8s-rabbitmq.yaml"
RedisApplyFilePath = env.ApplyFilePrefix + "k8s-redis.yaml"
MySQLApplyFilePath = env.ApplyFilePrefix + "k8s-mysql.yaml"
NacosApplyFilePath = env.ApplyFilePrefix + "k8s-nacos.yaml"
PVCApplyFilePath = env.ApplyFilePrefix + "k8s-pvc.yaml"
NfsApplyFilePath = env.ApplyFilePrefix + "k8s-nfs.yaml"
NfsTestApplyFilePath = env.ApplyFilePrefix + "k8s-nfs-test.yaml"
BackendApplyFilePath = env.ApplyFilePrefix + "k8s-backend.yaml"
FrontendApplyFilePath = env.ApplyFilePrefix + "k8s-frontend.yaml"
SRSApplyFilePath = env.ApplyFilePrefix + "k8s-srs.yaml"
IngresApplyFilePath = env.ApplyFilePrefix + "k8s-ingress.yaml"
ConfigMapApplyFilePath = env.ApplyFilePrefix + "k8s-configmap.yaml"
K8sDashboardApplyFilePath = filepath.Join(env.ApplyFilePrefix, "k8s-dashboard.yaml")
EmqxApplyFilePath = filepath.Join(env.ApplyFilePrefix, "k8s-emqx.yaml")
MongoApplyFilePath = filepath.Join(env.ApplyFilePrefix, "k8s-mongo.yaml")
RabbitMQApplyFilePath = filepath.Join(env.ApplyFilePrefix, "k8s-rabbitmq.yaml")
RedisApplyFilePath = filepath.Join(env.ApplyFilePrefix, "k8s-redis.yaml")
MySQLApplyFilePath = filepath.Join(env.ApplyFilePrefix, "k8s-mysql.yaml")
NacosApplyFilePath = filepath.Join(env.ApplyFilePrefix, "k8s-nacos.yaml")
PVCApplyFilePath = filepath.Join(env.ApplyFilePrefix, "k8s-pvc.yaml")
NfsApplyFilePath = filepath.Join(env.ApplyFilePrefix, "k8s-nfs.yaml")
NfsTestApplyFilePath = filepath.Join(env.ApplyFilePrefix, "k8s-nfs-test.yaml")
BackendApplyFilePath = filepath.Join(env.ApplyFilePrefix, "k8s-backend.yaml")
FrontendApplyFilePath = filepath.Join(env.ApplyFilePrefix, "k8s-frontend.yaml")
SRSApplyFilePath = filepath.Join(env.ApplyFilePrefix, "k8s-srs.yaml")
IngresApplyFilePath = filepath.Join(env.ApplyFilePrefix, "k8s-ingress.yaml")
ConfigMapApplyFilePath = filepath.Join(env.ApplyFilePrefix, "k8s-configmap.yaml")
}