167 lines
4.2 KiB
Go
Executable File
167 lines
4.2 KiB
Go
Executable File
package main
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"strings"
|
|
image2 "wdd.io/agent-common/image"
|
|
"wdd.io/agent-common/utils"
|
|
agent_deploy "wdd.io/agent-deploy"
|
|
"wdd.io/agent-deploy/z_dep"
|
|
"wdd.io/agent-operator/image"
|
|
)
|
|
|
|
func CmiiEnvDeploy() {
|
|
|
|
// 部署的环境
|
|
cmiiNamespace := dev
|
|
|
|
// 完整部署
|
|
shouldDoCompleteDeploy := true
|
|
|
|
// 输出特定版本的Tag 或者 从DEMO环境拉取
|
|
DeploySpecificTag := "5.5.0"
|
|
|
|
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: DeploySpecificTag,
|
|
TenantEnv: tenantEnv,
|
|
ApplyFilePrefix: folderPrefix,
|
|
}
|
|
|
|
var backendMap map[string]string
|
|
var frontendMap map[string]string
|
|
var srsMap map[string]string
|
|
|
|
if DeploySpecificTag == "" {
|
|
// 从DEMO环境拉取
|
|
backendMap, frontendMap, srsMap = BackupAllCmiiDeploymentToMap(demo)
|
|
} else {
|
|
// 输出特定版本的Tag
|
|
backendMap, frontendMap, srsMap = image.GenerateCmiiTagVersionImageMap(DeploySpecificTag)
|
|
}
|
|
|
|
utils.BeautifulPrintWithTitle(backendMap, "backendMap")
|
|
utils.BeautifulPrintWithTitle(frontendMap, "frontendMap")
|
|
utils.BeautifulPrintWithTitle(srsMap, "srsMap")
|
|
|
|
// generate and get all old stuff
|
|
agent_deploy.CmiiEnvironmentDeploy(shouldDoCompleteDeploy, common, backendMap, frontendMap)
|
|
|
|
// test
|
|
//GetNodeWideByKubectl(cmiiNamespace)
|
|
|
|
// clear old apply file
|
|
//clearOldApplyStuff(applyYamlFolder+"old/", cmiiNamespace)
|
|
|
|
// apply new app
|
|
//applyNewAppStuff(common, shouldDoCompleteDeploy)
|
|
|
|
}
|
|
|
|
func applyNewAppStuff(common *z_dep.CommonEnvironmentConfig, shouldDoCompleteDeploy bool) bool {
|
|
files, err := os.ReadDir(common.ApplyFilePrefix)
|
|
if err != nil {
|
|
log.ErrorF("failed to read directory: %v", err)
|
|
return false
|
|
}
|
|
if len(files) == 0 {
|
|
log.WarnF("no apply file found in %s", common.ApplyFilePrefix)
|
|
return false
|
|
}
|
|
|
|
namespace := common.Namespace
|
|
|
|
if shouldDoCompleteDeploy {
|
|
|
|
// mysql
|
|
ApplyByKubectl(z_dep.MySQLApplyFilePath, namespace)
|
|
if !DefaultCmiiOperator.PodStatusCheckTimeout("helm-mysql-0", namespace, 180) {
|
|
return false
|
|
}
|
|
|
|
// mongo
|
|
ApplyByKubectl(z_dep.MongoApplyFilePath, namespace)
|
|
if !DefaultCmiiOperator.PodStatusCheckTimeout("helm-mongo-0", namespace, 180) {
|
|
return false
|
|
}
|
|
|
|
// redis
|
|
ApplyByKubectl(z_dep.RedisApplyFilePath, namespace)
|
|
if !DefaultCmiiOperator.PodStatusCheckTimeout("helm-redis-master-0", namespace, 180) {
|
|
return false
|
|
}
|
|
if !DefaultCmiiOperator.PodStatusCheckTimeout("helm-redis-replicas-0", namespace, 180) {
|
|
return false
|
|
}
|
|
|
|
// rabbitmq
|
|
ApplyByKubectl(z_dep.RabbitMQApplyFilePath, namespace)
|
|
if !DefaultCmiiOperator.PodStatusCheckTimeout("helm-rabbitmq-0", namespace, 180) {
|
|
return false
|
|
}
|
|
|
|
// nacos
|
|
ApplyByKubectl(z_dep.NacosApplyFilePath, namespace)
|
|
if !DefaultCmiiOperator.PodStatusCheckTimeout("helm-nacos-0", namespace, 180) {
|
|
return false
|
|
}
|
|
|
|
}
|
|
|
|
// frontend
|
|
ApplyByKubectl(z_dep.IngresApplyFilePath, namespace)
|
|
ApplyByKubectl(z_dep.ConfigMapApplyFilePath, namespace)
|
|
ApplyByKubectl(z_dep.FrontendApplyFilePath, namespace)
|
|
|
|
// backend
|
|
ApplyByKubectl(z_dep.BackendApplyFilePath, namespace)
|
|
|
|
return true
|
|
}
|
|
|
|
func clearOldApplyStuff(oldApplyYamlFolder string, cmiiEnv string) bool {
|
|
|
|
files, err := os.ReadDir(oldApplyYamlFolder)
|
|
if err != nil {
|
|
log.ErrorF("failed to read directory: %v", err)
|
|
return false
|
|
}
|
|
|
|
// rearrange
|
|
//rearrangeCmiiDeploySequence(files)
|
|
|
|
for _, file := range files {
|
|
if filepath.Ext(file.Name()) == ".yaml" || filepath.Ext(file.Name()) == ".yml" {
|
|
filePath := filepath.Join(oldApplyYamlFolder, file.Name())
|
|
DeleteByKubectl(filePath, cmiiEnv)
|
|
}
|
|
}
|
|
|
|
return true
|
|
}
|
|
|
|
// rearrangeCmiiDeploySequence 重新排序CmiiDeploy顺序
|
|
func rearrangeCmiiDeploySequence(files []os.DirEntry) {
|
|
|
|
for _, file := range files {
|
|
if filepath.Ext(file.Name()) == ".yaml" || filepath.Ext(file.Name()) == ".yml" {
|
|
//filePath := filepath.Join(oldApplyYamlFolder, file.Name())
|
|
//DeleteByKubectl(filePath, cmiiEnv)
|
|
}
|
|
}
|
|
}
|