package main import ( "os" "path/filepath" "wdd.io/agent-common/utils" "wdd.io/agent-deploy" "wdd.io/agent-operator/image" ) func CmiiEnvDeploy() { // 完整部署 shouldDoCompleteDeploy := true // 部署的环境 cmiiNamespace := dev // 输出特定版本的Tag 或者 从DEMO环境拉取 DeploySpecificTag := "5.5.0" 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 applyYamlFolder := agent_deploy.CmiiEnvironmentDeploy(shouldDoCompleteDeploy, cmiiNamespace, frontendMap, backendMap) // clear old apply file clearOldApplyStuff(applyYamlFolder+"old/", cmiiNamespace) // apply new app applyNewAppStuff(applyYamlFolder, cmiiNamespace) } func applyNewAppStuff(applyYamlFolder string, cmiiEnv string) bool { files, err := os.ReadDir(applyYamlFolder) if err != nil { log.ErrorF("failed to read directory: %v", err) return false } for _, file := range files { if filepath.Ext(file.Name()) == ".yaml" || filepath.Ext(file.Name()) == ".yml" { filePath := filepath.Join(applyYamlFolder, file.Name()) ApplyByKubectl(filePath, cmiiEnv) } } 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 } 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 }