package deploy import ( "embed" _ "embed" "fmt" "os" "git.icechen.cn/pkg/wujian_develop_tool/config" "github.com/fatih/color" "git.icechen.cn/pkg/wujian_develop_tool/util" ) //go:embed "*" var deployDir embed.FS func GenDeploy(api config.Api) error { color.Green("正在生成deploy...") // deploy 文件夹 deployDirPath := api.Root + "/deploy" err := os.MkdirAll(deployDirPath, os.ModePerm) if err != nil { return err } host := api.Host if host == "" { host = "api.seamlesser.com" } path := api.Path if path == "" { path = fmt.Sprintf("/%s/%s/?(.*)", api.Namespace, api.Name) } data := map[string]string{ "NameSpace": api.Namespace, "AppName": api.Name, "AliasName": api.AliasName, "Port": api.Port, "Host": host, "Path": path, } // value.yaml valuesTemplate, err := deployDir.ReadFile("values.tpl") if err != nil { return err } err = util.TemplateToFile(deployDirPath+"/values.yaml", string(valuesTemplate), data) if err != nil { return err } // Chart.yaml chartTemplate, err := deployDir.ReadFile("Chart.tpl") if err != nil { return err } err = util.TemplateToFile(deployDirPath+"/Chart.yaml", string(chartTemplate), data) if err != nil { return err } // templates 文件夹 templatesDirPath := api.Root + "/deploy/templates" err = os.MkdirAll(templatesDirPath, os.ModePerm) if err != nil { return err } // .helmignore 文件 err = copyTo(".helmignore", deployDirPath+"/.helmignore") if err != nil { return err } // _helpers.tpl 文件 err = copyTo("templates/helpers.tpl", templatesDirPath+"/_helpers.tpl") if err != nil { return err } // application.yaml 文件 err = copyTo("templates/application.yaml", templatesDirPath+"/application.yaml") if err != nil { return err } // deployment.yaml 文件 err = copyTo("templates/deployment.yaml", templatesDirPath+"/deployment.yaml") if err != nil { return err } // ingress.yaml 文件 err = copyTo("templates/ingress.yaml", templatesDirPath+"/ingress.yaml") if err != nil { return err } // NOTES.txt 文件 err = copyTo("templates/NOTES.txt", templatesDirPath+"/NOTES.txt") if err != nil { return err } // service.yaml 文件 err = copyTo("templates/service.yaml", templatesDirPath+"/service.yaml") if err != nil { return err } return nil } func copyTo(fileName string, toPath string) error { fileContent, err := deployDir.ReadFile(fileName) if err != nil { return err } return util.WriteFile(toPath, fileContent) }