Loading go-apps/meepctl/cmd/build.go +25 −25 Original line number Original line Diff line number Diff line Loading @@ -160,7 +160,7 @@ func build(targetName string, cobraCmd *cobra.Command) { return return } } } } fmt.Println("Error: Unsupported target: ", targetName) fmt.Println(utils.FormatError("Error: Unsupported target: " + targetName)) } } func buildJsApp(targetName string, repo string, cobraCmd *cobra.Command) { func buildJsApp(targetName string, repo string, cobraCmd *cobra.Command) { Loading @@ -168,12 +168,12 @@ func buildJsApp(targetName string, repo string, cobraCmd *cobra.Command) { case "meep-frontend": case "meep-frontend": buildFrontend(targetName, repo, cobraCmd) buildFrontend(targetName, repo, cobraCmd) default: default: fmt.Println("Error: Unsupported JS App: ", targetName) fmt.Println(utils.FormatError("Error: Unsupported JS App: " + targetName)) } } } } func buildFrontend(targetName string, repo string, cobraCmd *cobra.Command) { func buildFrontend(targetName string, repo string, cobraCmd *cobra.Command) { fmt.Println("--", targetName, "--") fmt.Println(utils.FormatHeader("-- " + targetName + " --")) target := utils.RepoCfg.GetStringMapString(repo + targetName) target := utils.RepoCfg.GetStringMapString(repo + targetName) version := utils.RepoCfg.GetString("version") version := utils.RepoCfg.GetString("version") gitDir := viper.GetString("meep.gitdir") gitDir := viper.GetString("meep.gitdir") Loading @@ -182,25 +182,25 @@ func buildFrontend(targetName string, repo string, cobraCmd *cobra.Command) { lintEnabled := utils.RepoCfg.GetBool(repo + targetName + ".lint") lintEnabled := utils.RepoCfg.GetBool(repo + targetName + ".lint") // dependencies // dependencies fmt.Println(" + checking external dependencies") fmt.Println(utils.FormatStep(" + checking external dependencies")) cmd := exec.Command("npm", "ci") cmd := exec.Command("npm", "ci") cmd.Dir = srcDir cmd.Dir = srcDir out, err := utils.ExecuteCmd(cmd, cobraCmd) out, err := utils.ExecuteCmd(cmd, cobraCmd) if err != nil { if err != nil { fmt.Println("Error:", err) fmt.Println(utils.FormatError("Error: " + err.Error())) fmt.Println(out) fmt.Println(out) } } locDeps := utils.RepoCfg.GetStringMapString(repo + targetName + ".local-deps") locDeps := utils.RepoCfg.GetStringMapString(repo + targetName + ".local-deps") if len(locDeps) > 0 { if len(locDeps) > 0 { fmt.Println(" + checking local dependencies") fmt.Println(utils.FormatStep(" + checking local dependencies")) for dep, depDir := range locDeps { for dep, depDir := range locDeps { fmt.Println(" * " + dep) fmt.Println(utils.FormatStep(" * " + dep)) cmd := exec.Command("npm", "ci") cmd := exec.Command("npm", "ci") cmd.Dir = gitDir + "/" + depDir cmd.Dir = gitDir + "/" + depDir out, err := utils.ExecuteCmd(cmd, cobraCmd) out, err := utils.ExecuteCmd(cmd, cobraCmd) if err != nil { if err != nil { fmt.Println("Error:", err) fmt.Println(utils.FormatError("Error: " + err.Error())) fmt.Println(out) fmt.Println(out) } } } } Loading @@ -212,39 +212,39 @@ func buildFrontend(targetName string, repo string, cobraCmd *cobra.Command) { cmd.Dir = srcDir cmd.Dir = srcDir out, err = utils.ExecuteCmd(cmd, cobraCmd) out, err = utils.ExecuteCmd(cmd, cobraCmd) if err != nil { if err != nil { fmt.Println("Error:", err) fmt.Println(utils.FormatError("Error: " + err.Error())) fmt.Println(out) fmt.Println(out) } } } } // linter: ESLint // linter: ESLint if lintEnabled && !buildData.nolint { if lintEnabled && !buildData.nolint { fmt.Println(" + running linter") fmt.Println(utils.FormatStep(" + running linter")) cmd := exec.Command("eslint", "src/js/") cmd := exec.Command("eslint", "src/js/") cmd.Dir = srcDir cmd.Dir = srcDir out, err := utils.ExecuteCmd(cmd, cobraCmd) out, err := utils.ExecuteCmd(cmd, cobraCmd) if err != nil { if err != nil { fmt.Println("Error:", err) fmt.Println(utils.FormatError("Error: " + err.Error())) fmt.Println(out) fmt.Println(out) fmt.Println("Linting failed. Exiting...") fmt.Println(utils.FormatError("Linting failed. Exiting...")) fmt.Println("To skip linting run build with --nolint") fmt.Println(utils.FormatWarning("To skip linting run build with --nolint")) return return } } } } //build //build fmt.Println(" + building " + targetName) fmt.Println(utils.FormatStep(" + building " + targetName)) cmd = exec.Command("npm", "run", "build", "--", "--output-path="+binDir, "--env.VERSION=v"+version) cmd = exec.Command("npm", "run", "build", "--", "--output-path="+binDir, "--env.VERSION=v"+version) cmd.Dir = srcDir cmd.Dir = srcDir out, err = utils.ExecuteCmd(cmd, cobraCmd) out, err = utils.ExecuteCmd(cmd, cobraCmd) if err != nil { if err != nil { fmt.Println("Error:", err) fmt.Println(utils.FormatError("Error: " + err.Error())) fmt.Println(out) fmt.Println(out) } } } } func buildGoApp(targetName string, repo string, cobraCmd *cobra.Command) { func buildGoApp(targetName string, repo string, cobraCmd *cobra.Command) { fmt.Println("--", targetName, "--") fmt.Println(utils.FormatHeader("-- " + targetName + " --")) target := utils.RepoCfg.GetStringMapString(repo + targetName) target := utils.RepoCfg.GetStringMapString(repo + targetName) gitDir := viper.GetString("meep.gitdir") gitDir := viper.GetString("meep.gitdir") srcDir := gitDir + "/" + target["src"] srcDir := gitDir + "/" + target["src"] Loading @@ -253,26 +253,26 @@ func buildGoApp(targetName string, repo string, cobraCmd *cobra.Command) { lintEnabled := utils.RepoCfg.GetBool(repo + targetName + ".lint") lintEnabled := utils.RepoCfg.GetBool(repo + targetName + ".lint") // dependencies // dependencies fmt.Println(" + checking external dependencies") fmt.Println(utils.FormatStep(" + checking external dependencies")) cmd := exec.Command("go", "mod", "vendor") cmd := exec.Command("go", "mod", "vendor") cmd.Dir = srcDir cmd.Dir = srcDir out, err := utils.ExecuteCmd(cmd, cobraCmd) out, err := utils.ExecuteCmd(cmd, cobraCmd) if err != nil { if err != nil { fmt.Println("Error:", err) fmt.Println(utils.FormatError("Error: " + err.Error())) fmt.Println(out) fmt.Println(out) } } // linter: goloangci-lint // linter: goloangci-lint if lintEnabled && !buildData.nolint { if lintEnabled && !buildData.nolint { fmt.Println(" + running linter") fmt.Println(utils.FormatStep(" + running linter")) cmd := exec.Command("golangci-lint", "run") cmd := exec.Command("golangci-lint", "run") cmd.Dir = srcDir cmd.Dir = srcDir out, err := utils.ExecuteCmd(cmd, cobraCmd) out, err := utils.ExecuteCmd(cmd, cobraCmd) if err != nil { if err != nil { fmt.Println("Error:", err) fmt.Println(utils.FormatError("Error: " + err.Error())) fmt.Println(out) fmt.Println(out) fmt.Println("Linting failed. Exiting...") fmt.Println(utils.FormatError("Linting failed. Exiting...")) fmt.Println("To skip linting run build with --nolint") fmt.Println(utils.FormatWarning("To skip linting run build with --nolint")) return return } } } } Loading @@ -285,13 +285,13 @@ func buildGoApp(targetName string, repo string, cobraCmd *cobra.Command) { // build // build buildFlags := utils.RepoCfg.GetStringSlice(repo + targetName + ".build-flags") buildFlags := utils.RepoCfg.GetStringSlice(repo + targetName + ".build-flags") if buildData.codecov && codecovCapable { if buildData.codecov && codecovCapable { fmt.Println(" + building " + targetName + " (warning: development build - code coverage)") fmt.Println(utils.FormatWarning(" + building " + targetName + " (warning: development build - code coverage)")) args := []string{"test", "-covermode=count", "-coverpkg=./...", "-c"} args := []string{"test", "-covermode=count", "-coverpkg=./...", "-c"} args = append(args, buildFlags...) args = append(args, buildFlags...) args = append(args, "-o", binDir+"/"+targetName, srcDir) args = append(args, "-o", binDir+"/"+targetName, srcDir) cmd = exec.Command("go", args...) cmd = exec.Command("go", args...) } else { } else { fmt.Println(" + building " + targetName) fmt.Println(utils.FormatStep(" + building " + targetName)) args := []string{"build"} args := []string{"build"} args = append(args, buildFlags...) args = append(args, buildFlags...) args = append(args, "-o", binDir+"/"+targetName, srcDir) args = append(args, "-o", binDir+"/"+targetName, srcDir) Loading @@ -300,7 +300,7 @@ func buildGoApp(targetName string, repo string, cobraCmd *cobra.Command) { cmd.Dir = srcDir cmd.Dir = srcDir out, err = utils.ExecuteCmd(cmd, cobraCmd) out, err = utils.ExecuteCmd(cmd, cobraCmd) if err != nil { if err != nil { fmt.Println("Error:", err) fmt.Println(utils.FormatError("Error: " + err.Error())) fmt.Println(out) fmt.Println(out) } } } } Loading go-apps/meepctl/cmd/deploy.go +6 −6 Original line number Original line Diff line number Diff line Loading @@ -138,7 +138,7 @@ func deployRun(cmd *cobra.Command, args []string) { deployData.registry = viper.GetString("meep.registry") deployData.registry = viper.GetString("meep.registry") } } deployData.registry = strings.TrimSuffix(deployData.registry, "/") deployData.registry = strings.TrimSuffix(deployData.registry, "/") fmt.Println("Using docker registry:", deployData.registry) fmt.Println(utils.FormatStep("Using docker registry: " + deployData.registry)) // Get config // Get config deployData.gitdir = strings.TrimSuffix(viper.GetString("meep.gitdir"), "/") deployData.gitdir = strings.TrimSuffix(viper.GetString("meep.gitdir"), "/") Loading Loading @@ -291,10 +291,10 @@ func deploySingleDepApp(app string, cobraCmd *cobra.Command) { } } } } if !found { if !found { fmt.Println("Error: '" + app + "' is not a valid dep target") fmt.Println(utils.FormatError("Error: '" + app + "' is not a valid dep target")) fmt.Println("Valid dep targets:") fmt.Println(utils.FormatStep("Valid dep targets:")) for _, a := range deployData.depApps { for _, a := range deployData.depApps { fmt.Println(" * " + a) fmt.Println(utils.FormatStep(" * " + a)) } } return return } } Loading Loading @@ -632,10 +632,10 @@ func k8sDeploy(app string, chart string, flags [][]string, cobraCmd *cobra.Comma if force { if force { _ = utils.HelmDelete(app, cobraCmd) _ = utils.HelmDelete(app, cobraCmd) // Wait for K8s to clean up resources before redeploying // Wait for K8s to clean up resources before redeploying fmt.Println("Waiting 5s for resource cleanup...") fmt.Println(utils.FormatWarning("Waiting 5s for resource cleanup...")) time.Sleep(10 * time.Second) time.Sleep(10 * time.Second) } else { } else { fmt.Println("Skipping " + app + ": already deployed -- use [-f, --force] flag to force deployment") fmt.Println(utils.FormatWarning("Skipping " + app + ": already deployed -- use [-f, --force] flag to force deployment")) return return } } } } Loading go-apps/meepctl/cmd/dockerize.go +16 −16 Original line number Original line Diff line number Diff line Loading @@ -165,36 +165,36 @@ func dockerizeTarget(targetName string, cobraCmd *cobra.Command) { return return } } } } fmt.Println("Error: Unsupported target: ", targetName) fmt.Println(utils.FormatError("Error: Unsupported target: " + targetName)) } } func dockerize(targetName string, repo string, cobraCmd *cobra.Command) { func dockerize(targetName string, repo string, cobraCmd *cobra.Command) { srcdir := dockerizeData.gitdir + "/" + utils.RepoCfg.GetString(repo+targetName+".src") srcdir := dockerizeData.gitdir + "/" + utils.RepoCfg.GetString(repo+targetName+".src") bindir := dockerizeData.gitdir + "/" + utils.RepoCfg.GetString(repo+targetName+".bin") bindir := dockerizeData.gitdir + "/" + utils.RepoCfg.GetString(repo+targetName+".bin") fmt.Println("--", targetName, "--") fmt.Println(utils.FormatHeader("-- " + targetName + " --")) // Check if bindir exists, create it if it doesn't // Check if bindir exists, create it if it doesn't if _, err := os.Stat(bindir); os.IsNotExist(err) { if _, err := os.Stat(bindir); os.IsNotExist(err) { fmt.Println(" + creating bin directory:", bindir) fmt.Println(utils.FormatStep(" + creating bin directory: " + bindir)) err := os.MkdirAll(bindir, 0755) err := os.MkdirAll(bindir, 0755) if err != nil { if err != nil { fmt.Println("Error: Failed to create bin directory:", err) fmt.Println(utils.FormatError("Error: Failed to create bin directory: " + err.Error())) return return } } } } // Copy Dockerfile // Copy Dockerfile fmt.Println(" + copy docker file") fmt.Println(utils.FormatStep(" + copy docker file")) cmd := exec.Command("cp", "Dockerfile", bindir) cmd := exec.Command("cp", "Dockerfile", bindir) cmd.Dir = srcdir cmd.Dir = srcdir out, err := utils.ExecuteCmd(cmd, cobraCmd) out, err := utils.ExecuteCmd(cmd, cobraCmd) if err != nil { if err != nil { fmt.Println("Error:", err) fmt.Println(utils.FormatError("Error: " + err.Error())) fmt.Println(out) fmt.Println(out) return return } } // copy service api files locally // copy service api files locally fmt.Println(" + copy api files") fmt.Println(utils.FormatStep(" + copy api files")) err = dockerizeCopyApi(repo+targetName+".api", bindir+"/api", cobraCmd) err = dockerizeCopyApi(repo+targetName+".api", bindir+"/api", cobraCmd) if err != nil { if err != nil { return return Loading @@ -205,7 +205,7 @@ func dockerize(targetName string, repo string, cobraCmd *cobra.Command) { } } // copy container data locally // copy container data locally fmt.Println(" + copy docker data") fmt.Println(utils.FormatStep(" + copy docker data")) err = dockerizeCopyData(repo+targetName+".docker-data", bindir+"/data", cobraCmd) err = dockerizeCopyData(repo+targetName+".docker-data", bindir+"/data", cobraCmd) if err != nil { if err != nil { return return Loading @@ -217,7 +217,7 @@ func dockerize(targetName string, repo string, cobraCmd *cobra.Command) { checksum := strings.Split(output, " ") checksum := strings.Split(output, " ") // dockerize & push to private meep docker registry // dockerize & push to private meep docker registry fmt.Println(" + dockerize " + targetName) fmt.Println(utils.FormatStep(" + dockerize " + targetName)) buildArgs := []string{"build", "--rm", "--label", "MeepVersion=" + checksum[0]} buildArgs := []string{"build", "--rm", "--label", "MeepVersion=" + checksum[0]} if dockerizeData.noCache { if dockerizeData.noCache { Loading @@ -231,13 +231,13 @@ func dockerize(targetName string, repo string, cobraCmd *cobra.Command) { cmd := exec.Command("docker", buildArgs...) cmd := exec.Command("docker", buildArgs...) _, err = utils.ExecuteCmd(cmd, cobraCmd) _, err = utils.ExecuteCmd(cmd, cobraCmd) if err != nil { if err != nil { fmt.Println("Error: Failed to dockerize ", tag, " with error: ", err) fmt.Println(utils.FormatError("Error: Failed to dockerize " + tag + " with error: " + err.Error())) return return } } cmd = exec.Command("docker", "push", tag) cmd = exec.Command("docker", "push", tag) _, err = utils.ExecuteCmd(cmd, cobraCmd) _, err = utils.ExecuteCmd(cmd, cobraCmd) if err != nil { if err != nil { fmt.Println("Error: Failed to push ", tag, " with error: ", err) fmt.Println(utils.FormatError("Error: Failed to push " + tag + " with error: " + err.Error())) return return } } } else { } else { Loading Loading @@ -265,7 +265,7 @@ func dockerizeCopyApi(key string, dstDir string, cobraCmd *cobra.Command) (err e var apiList []dockerizeApi var apiList []dockerizeApi err = utils.RepoCfg.UnmarshalKey(key, &apiList) err = utils.RepoCfg.UnmarshalKey(key, &apiList) if err != nil { if err != nil { fmt.Println("Error: Failed to unmarshal api @ ", key) fmt.Println(utils.FormatError("Error: Failed to unmarshal api @ " + key)) return err return err } } Loading @@ -282,11 +282,11 @@ func dockerizeCopyApi(key string, dstDir string, cobraCmd *cobra.Command) (err e cmd = exec.Command("cp", srcApi, dstApi) cmd = exec.Command("cp", srcApi, dstApi) _, err = utils.ExecuteCmd(cmd, cobraCmd) _, err = utils.ExecuteCmd(cmd, cobraCmd) if err != nil { if err != nil { fmt.Println("Error: Failed to copy data: ", srcApi, " --> ", dstApi) fmt.Println(utils.FormatError("Error: Failed to copy data: " + srcApi + " --> " + dstApi)) return err return err } } } else { } else { fmt.Println("Error: Source data not found: ", srcApi, " --> ", dstApi) fmt.Println(utils.FormatError("Error: Source data not found: " + srcApi + " --> " + dstApi)) return err return err } } } } Loading Loading @@ -316,11 +316,11 @@ func dockerizeCopyData(key string, dstDir string, cobraCmd *cobra.Command) (err cmd = exec.Command("cp", "-r", srcDataDir, dstDataDir) cmd = exec.Command("cp", "-r", srcDataDir, dstDataDir) _, err = utils.ExecuteCmd(cmd, cobraCmd) _, err = utils.ExecuteCmd(cmd, cobraCmd) if err != nil { if err != nil { fmt.Println("Error: Failed to copy data: ", srcDataDir, " --> ", dstDataDir) fmt.Println(utils.FormatError("Error: Failed to copy data: " + srcDataDir + " --> " + dstDataDir)) return err return err } } } else { } else { fmt.Println("Error: Source data not found: ", srcDataDir, " --> ", dstDataDir) fmt.Println(utils.FormatError("Error: Source data not found: " + srcDataDir + " --> " + dstDataDir)) return err return err } } } } Loading go-apps/meepctl/utils/format.go +39 −0 Original line number Original line Diff line number Diff line Loading @@ -17,11 +17,50 @@ package utils package utils import ( import ( "fmt" "time" "time" "github.com/spf13/cobra" "github.com/spf13/cobra" ) ) // ANSI color escape codes const ( ColorReset = "\033[0m" ColorRed = "\033[31m" ColorGreen = "\033[32m" ColorYellow = "\033[33m" ColorBlue = "\033[34m" ColorPurple = "\033[35m" ColorCyan = "\033[36m" ColorWhite = "\033[37m" ColorBold = "\033[1m" ) // FormatHeader formats command headers in bold blue func FormatHeader(msg string) string { return fmt.Sprintf("%s%s%s%s", ColorBold, ColorBlue, msg, ColorReset) } // FormatStep formats execution steps in cyan func FormatStep(msg string) string { return fmt.Sprintf("%s%s%s", ColorCyan, msg, ColorReset) } // FormatWarning formats warning messages in yellow func FormatWarning(msg string) string { return fmt.Sprintf("%s%s%s", ColorYellow, msg, ColorReset) } // FormatError formats error messages in bold red func FormatError(msg string) string { return fmt.Sprintf("%s%s%s%s", ColorBold, ColorRed, msg, ColorReset) } // FormatSuccess formats success status in bold green func FormatSuccess(msg string) string { return fmt.Sprintf("%s%s%s%s", ColorBold, ColorGreen, msg, ColorReset) } // FormatResult consistent formatting for results to be displayed // FormatResult consistent formatting for results to be displayed func FormatResult(result string, elapsed time.Duration, cobraCmd *cobra.Command) string { func FormatResult(result string, elapsed time.Duration, cobraCmd *cobra.Command) string { ret := result ret := result Loading Loading
go-apps/meepctl/cmd/build.go +25 −25 Original line number Original line Diff line number Diff line Loading @@ -160,7 +160,7 @@ func build(targetName string, cobraCmd *cobra.Command) { return return } } } } fmt.Println("Error: Unsupported target: ", targetName) fmt.Println(utils.FormatError("Error: Unsupported target: " + targetName)) } } func buildJsApp(targetName string, repo string, cobraCmd *cobra.Command) { func buildJsApp(targetName string, repo string, cobraCmd *cobra.Command) { Loading @@ -168,12 +168,12 @@ func buildJsApp(targetName string, repo string, cobraCmd *cobra.Command) { case "meep-frontend": case "meep-frontend": buildFrontend(targetName, repo, cobraCmd) buildFrontend(targetName, repo, cobraCmd) default: default: fmt.Println("Error: Unsupported JS App: ", targetName) fmt.Println(utils.FormatError("Error: Unsupported JS App: " + targetName)) } } } } func buildFrontend(targetName string, repo string, cobraCmd *cobra.Command) { func buildFrontend(targetName string, repo string, cobraCmd *cobra.Command) { fmt.Println("--", targetName, "--") fmt.Println(utils.FormatHeader("-- " + targetName + " --")) target := utils.RepoCfg.GetStringMapString(repo + targetName) target := utils.RepoCfg.GetStringMapString(repo + targetName) version := utils.RepoCfg.GetString("version") version := utils.RepoCfg.GetString("version") gitDir := viper.GetString("meep.gitdir") gitDir := viper.GetString("meep.gitdir") Loading @@ -182,25 +182,25 @@ func buildFrontend(targetName string, repo string, cobraCmd *cobra.Command) { lintEnabled := utils.RepoCfg.GetBool(repo + targetName + ".lint") lintEnabled := utils.RepoCfg.GetBool(repo + targetName + ".lint") // dependencies // dependencies fmt.Println(" + checking external dependencies") fmt.Println(utils.FormatStep(" + checking external dependencies")) cmd := exec.Command("npm", "ci") cmd := exec.Command("npm", "ci") cmd.Dir = srcDir cmd.Dir = srcDir out, err := utils.ExecuteCmd(cmd, cobraCmd) out, err := utils.ExecuteCmd(cmd, cobraCmd) if err != nil { if err != nil { fmt.Println("Error:", err) fmt.Println(utils.FormatError("Error: " + err.Error())) fmt.Println(out) fmt.Println(out) } } locDeps := utils.RepoCfg.GetStringMapString(repo + targetName + ".local-deps") locDeps := utils.RepoCfg.GetStringMapString(repo + targetName + ".local-deps") if len(locDeps) > 0 { if len(locDeps) > 0 { fmt.Println(" + checking local dependencies") fmt.Println(utils.FormatStep(" + checking local dependencies")) for dep, depDir := range locDeps { for dep, depDir := range locDeps { fmt.Println(" * " + dep) fmt.Println(utils.FormatStep(" * " + dep)) cmd := exec.Command("npm", "ci") cmd := exec.Command("npm", "ci") cmd.Dir = gitDir + "/" + depDir cmd.Dir = gitDir + "/" + depDir out, err := utils.ExecuteCmd(cmd, cobraCmd) out, err := utils.ExecuteCmd(cmd, cobraCmd) if err != nil { if err != nil { fmt.Println("Error:", err) fmt.Println(utils.FormatError("Error: " + err.Error())) fmt.Println(out) fmt.Println(out) } } } } Loading @@ -212,39 +212,39 @@ func buildFrontend(targetName string, repo string, cobraCmd *cobra.Command) { cmd.Dir = srcDir cmd.Dir = srcDir out, err = utils.ExecuteCmd(cmd, cobraCmd) out, err = utils.ExecuteCmd(cmd, cobraCmd) if err != nil { if err != nil { fmt.Println("Error:", err) fmt.Println(utils.FormatError("Error: " + err.Error())) fmt.Println(out) fmt.Println(out) } } } } // linter: ESLint // linter: ESLint if lintEnabled && !buildData.nolint { if lintEnabled && !buildData.nolint { fmt.Println(" + running linter") fmt.Println(utils.FormatStep(" + running linter")) cmd := exec.Command("eslint", "src/js/") cmd := exec.Command("eslint", "src/js/") cmd.Dir = srcDir cmd.Dir = srcDir out, err := utils.ExecuteCmd(cmd, cobraCmd) out, err := utils.ExecuteCmd(cmd, cobraCmd) if err != nil { if err != nil { fmt.Println("Error:", err) fmt.Println(utils.FormatError("Error: " + err.Error())) fmt.Println(out) fmt.Println(out) fmt.Println("Linting failed. Exiting...") fmt.Println(utils.FormatError("Linting failed. Exiting...")) fmt.Println("To skip linting run build with --nolint") fmt.Println(utils.FormatWarning("To skip linting run build with --nolint")) return return } } } } //build //build fmt.Println(" + building " + targetName) fmt.Println(utils.FormatStep(" + building " + targetName)) cmd = exec.Command("npm", "run", "build", "--", "--output-path="+binDir, "--env.VERSION=v"+version) cmd = exec.Command("npm", "run", "build", "--", "--output-path="+binDir, "--env.VERSION=v"+version) cmd.Dir = srcDir cmd.Dir = srcDir out, err = utils.ExecuteCmd(cmd, cobraCmd) out, err = utils.ExecuteCmd(cmd, cobraCmd) if err != nil { if err != nil { fmt.Println("Error:", err) fmt.Println(utils.FormatError("Error: " + err.Error())) fmt.Println(out) fmt.Println(out) } } } } func buildGoApp(targetName string, repo string, cobraCmd *cobra.Command) { func buildGoApp(targetName string, repo string, cobraCmd *cobra.Command) { fmt.Println("--", targetName, "--") fmt.Println(utils.FormatHeader("-- " + targetName + " --")) target := utils.RepoCfg.GetStringMapString(repo + targetName) target := utils.RepoCfg.GetStringMapString(repo + targetName) gitDir := viper.GetString("meep.gitdir") gitDir := viper.GetString("meep.gitdir") srcDir := gitDir + "/" + target["src"] srcDir := gitDir + "/" + target["src"] Loading @@ -253,26 +253,26 @@ func buildGoApp(targetName string, repo string, cobraCmd *cobra.Command) { lintEnabled := utils.RepoCfg.GetBool(repo + targetName + ".lint") lintEnabled := utils.RepoCfg.GetBool(repo + targetName + ".lint") // dependencies // dependencies fmt.Println(" + checking external dependencies") fmt.Println(utils.FormatStep(" + checking external dependencies")) cmd := exec.Command("go", "mod", "vendor") cmd := exec.Command("go", "mod", "vendor") cmd.Dir = srcDir cmd.Dir = srcDir out, err := utils.ExecuteCmd(cmd, cobraCmd) out, err := utils.ExecuteCmd(cmd, cobraCmd) if err != nil { if err != nil { fmt.Println("Error:", err) fmt.Println(utils.FormatError("Error: " + err.Error())) fmt.Println(out) fmt.Println(out) } } // linter: goloangci-lint // linter: goloangci-lint if lintEnabled && !buildData.nolint { if lintEnabled && !buildData.nolint { fmt.Println(" + running linter") fmt.Println(utils.FormatStep(" + running linter")) cmd := exec.Command("golangci-lint", "run") cmd := exec.Command("golangci-lint", "run") cmd.Dir = srcDir cmd.Dir = srcDir out, err := utils.ExecuteCmd(cmd, cobraCmd) out, err := utils.ExecuteCmd(cmd, cobraCmd) if err != nil { if err != nil { fmt.Println("Error:", err) fmt.Println(utils.FormatError("Error: " + err.Error())) fmt.Println(out) fmt.Println(out) fmt.Println("Linting failed. Exiting...") fmt.Println(utils.FormatError("Linting failed. Exiting...")) fmt.Println("To skip linting run build with --nolint") fmt.Println(utils.FormatWarning("To skip linting run build with --nolint")) return return } } } } Loading @@ -285,13 +285,13 @@ func buildGoApp(targetName string, repo string, cobraCmd *cobra.Command) { // build // build buildFlags := utils.RepoCfg.GetStringSlice(repo + targetName + ".build-flags") buildFlags := utils.RepoCfg.GetStringSlice(repo + targetName + ".build-flags") if buildData.codecov && codecovCapable { if buildData.codecov && codecovCapable { fmt.Println(" + building " + targetName + " (warning: development build - code coverage)") fmt.Println(utils.FormatWarning(" + building " + targetName + " (warning: development build - code coverage)")) args := []string{"test", "-covermode=count", "-coverpkg=./...", "-c"} args := []string{"test", "-covermode=count", "-coverpkg=./...", "-c"} args = append(args, buildFlags...) args = append(args, buildFlags...) args = append(args, "-o", binDir+"/"+targetName, srcDir) args = append(args, "-o", binDir+"/"+targetName, srcDir) cmd = exec.Command("go", args...) cmd = exec.Command("go", args...) } else { } else { fmt.Println(" + building " + targetName) fmt.Println(utils.FormatStep(" + building " + targetName)) args := []string{"build"} args := []string{"build"} args = append(args, buildFlags...) args = append(args, buildFlags...) args = append(args, "-o", binDir+"/"+targetName, srcDir) args = append(args, "-o", binDir+"/"+targetName, srcDir) Loading @@ -300,7 +300,7 @@ func buildGoApp(targetName string, repo string, cobraCmd *cobra.Command) { cmd.Dir = srcDir cmd.Dir = srcDir out, err = utils.ExecuteCmd(cmd, cobraCmd) out, err = utils.ExecuteCmd(cmd, cobraCmd) if err != nil { if err != nil { fmt.Println("Error:", err) fmt.Println(utils.FormatError("Error: " + err.Error())) fmt.Println(out) fmt.Println(out) } } } } Loading
go-apps/meepctl/cmd/deploy.go +6 −6 Original line number Original line Diff line number Diff line Loading @@ -138,7 +138,7 @@ func deployRun(cmd *cobra.Command, args []string) { deployData.registry = viper.GetString("meep.registry") deployData.registry = viper.GetString("meep.registry") } } deployData.registry = strings.TrimSuffix(deployData.registry, "/") deployData.registry = strings.TrimSuffix(deployData.registry, "/") fmt.Println("Using docker registry:", deployData.registry) fmt.Println(utils.FormatStep("Using docker registry: " + deployData.registry)) // Get config // Get config deployData.gitdir = strings.TrimSuffix(viper.GetString("meep.gitdir"), "/") deployData.gitdir = strings.TrimSuffix(viper.GetString("meep.gitdir"), "/") Loading Loading @@ -291,10 +291,10 @@ func deploySingleDepApp(app string, cobraCmd *cobra.Command) { } } } } if !found { if !found { fmt.Println("Error: '" + app + "' is not a valid dep target") fmt.Println(utils.FormatError("Error: '" + app + "' is not a valid dep target")) fmt.Println("Valid dep targets:") fmt.Println(utils.FormatStep("Valid dep targets:")) for _, a := range deployData.depApps { for _, a := range deployData.depApps { fmt.Println(" * " + a) fmt.Println(utils.FormatStep(" * " + a)) } } return return } } Loading Loading @@ -632,10 +632,10 @@ func k8sDeploy(app string, chart string, flags [][]string, cobraCmd *cobra.Comma if force { if force { _ = utils.HelmDelete(app, cobraCmd) _ = utils.HelmDelete(app, cobraCmd) // Wait for K8s to clean up resources before redeploying // Wait for K8s to clean up resources before redeploying fmt.Println("Waiting 5s for resource cleanup...") fmt.Println(utils.FormatWarning("Waiting 5s for resource cleanup...")) time.Sleep(10 * time.Second) time.Sleep(10 * time.Second) } else { } else { fmt.Println("Skipping " + app + ": already deployed -- use [-f, --force] flag to force deployment") fmt.Println(utils.FormatWarning("Skipping " + app + ": already deployed -- use [-f, --force] flag to force deployment")) return return } } } } Loading
go-apps/meepctl/cmd/dockerize.go +16 −16 Original line number Original line Diff line number Diff line Loading @@ -165,36 +165,36 @@ func dockerizeTarget(targetName string, cobraCmd *cobra.Command) { return return } } } } fmt.Println("Error: Unsupported target: ", targetName) fmt.Println(utils.FormatError("Error: Unsupported target: " + targetName)) } } func dockerize(targetName string, repo string, cobraCmd *cobra.Command) { func dockerize(targetName string, repo string, cobraCmd *cobra.Command) { srcdir := dockerizeData.gitdir + "/" + utils.RepoCfg.GetString(repo+targetName+".src") srcdir := dockerizeData.gitdir + "/" + utils.RepoCfg.GetString(repo+targetName+".src") bindir := dockerizeData.gitdir + "/" + utils.RepoCfg.GetString(repo+targetName+".bin") bindir := dockerizeData.gitdir + "/" + utils.RepoCfg.GetString(repo+targetName+".bin") fmt.Println("--", targetName, "--") fmt.Println(utils.FormatHeader("-- " + targetName + " --")) // Check if bindir exists, create it if it doesn't // Check if bindir exists, create it if it doesn't if _, err := os.Stat(bindir); os.IsNotExist(err) { if _, err := os.Stat(bindir); os.IsNotExist(err) { fmt.Println(" + creating bin directory:", bindir) fmt.Println(utils.FormatStep(" + creating bin directory: " + bindir)) err := os.MkdirAll(bindir, 0755) err := os.MkdirAll(bindir, 0755) if err != nil { if err != nil { fmt.Println("Error: Failed to create bin directory:", err) fmt.Println(utils.FormatError("Error: Failed to create bin directory: " + err.Error())) return return } } } } // Copy Dockerfile // Copy Dockerfile fmt.Println(" + copy docker file") fmt.Println(utils.FormatStep(" + copy docker file")) cmd := exec.Command("cp", "Dockerfile", bindir) cmd := exec.Command("cp", "Dockerfile", bindir) cmd.Dir = srcdir cmd.Dir = srcdir out, err := utils.ExecuteCmd(cmd, cobraCmd) out, err := utils.ExecuteCmd(cmd, cobraCmd) if err != nil { if err != nil { fmt.Println("Error:", err) fmt.Println(utils.FormatError("Error: " + err.Error())) fmt.Println(out) fmt.Println(out) return return } } // copy service api files locally // copy service api files locally fmt.Println(" + copy api files") fmt.Println(utils.FormatStep(" + copy api files")) err = dockerizeCopyApi(repo+targetName+".api", bindir+"/api", cobraCmd) err = dockerizeCopyApi(repo+targetName+".api", bindir+"/api", cobraCmd) if err != nil { if err != nil { return return Loading @@ -205,7 +205,7 @@ func dockerize(targetName string, repo string, cobraCmd *cobra.Command) { } } // copy container data locally // copy container data locally fmt.Println(" + copy docker data") fmt.Println(utils.FormatStep(" + copy docker data")) err = dockerizeCopyData(repo+targetName+".docker-data", bindir+"/data", cobraCmd) err = dockerizeCopyData(repo+targetName+".docker-data", bindir+"/data", cobraCmd) if err != nil { if err != nil { return return Loading @@ -217,7 +217,7 @@ func dockerize(targetName string, repo string, cobraCmd *cobra.Command) { checksum := strings.Split(output, " ") checksum := strings.Split(output, " ") // dockerize & push to private meep docker registry // dockerize & push to private meep docker registry fmt.Println(" + dockerize " + targetName) fmt.Println(utils.FormatStep(" + dockerize " + targetName)) buildArgs := []string{"build", "--rm", "--label", "MeepVersion=" + checksum[0]} buildArgs := []string{"build", "--rm", "--label", "MeepVersion=" + checksum[0]} if dockerizeData.noCache { if dockerizeData.noCache { Loading @@ -231,13 +231,13 @@ func dockerize(targetName string, repo string, cobraCmd *cobra.Command) { cmd := exec.Command("docker", buildArgs...) cmd := exec.Command("docker", buildArgs...) _, err = utils.ExecuteCmd(cmd, cobraCmd) _, err = utils.ExecuteCmd(cmd, cobraCmd) if err != nil { if err != nil { fmt.Println("Error: Failed to dockerize ", tag, " with error: ", err) fmt.Println(utils.FormatError("Error: Failed to dockerize " + tag + " with error: " + err.Error())) return return } } cmd = exec.Command("docker", "push", tag) cmd = exec.Command("docker", "push", tag) _, err = utils.ExecuteCmd(cmd, cobraCmd) _, err = utils.ExecuteCmd(cmd, cobraCmd) if err != nil { if err != nil { fmt.Println("Error: Failed to push ", tag, " with error: ", err) fmt.Println(utils.FormatError("Error: Failed to push " + tag + " with error: " + err.Error())) return return } } } else { } else { Loading Loading @@ -265,7 +265,7 @@ func dockerizeCopyApi(key string, dstDir string, cobraCmd *cobra.Command) (err e var apiList []dockerizeApi var apiList []dockerizeApi err = utils.RepoCfg.UnmarshalKey(key, &apiList) err = utils.RepoCfg.UnmarshalKey(key, &apiList) if err != nil { if err != nil { fmt.Println("Error: Failed to unmarshal api @ ", key) fmt.Println(utils.FormatError("Error: Failed to unmarshal api @ " + key)) return err return err } } Loading @@ -282,11 +282,11 @@ func dockerizeCopyApi(key string, dstDir string, cobraCmd *cobra.Command) (err e cmd = exec.Command("cp", srcApi, dstApi) cmd = exec.Command("cp", srcApi, dstApi) _, err = utils.ExecuteCmd(cmd, cobraCmd) _, err = utils.ExecuteCmd(cmd, cobraCmd) if err != nil { if err != nil { fmt.Println("Error: Failed to copy data: ", srcApi, " --> ", dstApi) fmt.Println(utils.FormatError("Error: Failed to copy data: " + srcApi + " --> " + dstApi)) return err return err } } } else { } else { fmt.Println("Error: Source data not found: ", srcApi, " --> ", dstApi) fmt.Println(utils.FormatError("Error: Source data not found: " + srcApi + " --> " + dstApi)) return err return err } } } } Loading Loading @@ -316,11 +316,11 @@ func dockerizeCopyData(key string, dstDir string, cobraCmd *cobra.Command) (err cmd = exec.Command("cp", "-r", srcDataDir, dstDataDir) cmd = exec.Command("cp", "-r", srcDataDir, dstDataDir) _, err = utils.ExecuteCmd(cmd, cobraCmd) _, err = utils.ExecuteCmd(cmd, cobraCmd) if err != nil { if err != nil { fmt.Println("Error: Failed to copy data: ", srcDataDir, " --> ", dstDataDir) fmt.Println(utils.FormatError("Error: Failed to copy data: " + srcDataDir + " --> " + dstDataDir)) return err return err } } } else { } else { fmt.Println("Error: Source data not found: ", srcDataDir, " --> ", dstDataDir) fmt.Println(utils.FormatError("Error: Source data not found: " + srcDataDir + " --> " + dstDataDir)) return err return err } } } } Loading
go-apps/meepctl/utils/format.go +39 −0 Original line number Original line Diff line number Diff line Loading @@ -17,11 +17,50 @@ package utils package utils import ( import ( "fmt" "time" "time" "github.com/spf13/cobra" "github.com/spf13/cobra" ) ) // ANSI color escape codes const ( ColorReset = "\033[0m" ColorRed = "\033[31m" ColorGreen = "\033[32m" ColorYellow = "\033[33m" ColorBlue = "\033[34m" ColorPurple = "\033[35m" ColorCyan = "\033[36m" ColorWhite = "\033[37m" ColorBold = "\033[1m" ) // FormatHeader formats command headers in bold blue func FormatHeader(msg string) string { return fmt.Sprintf("%s%s%s%s", ColorBold, ColorBlue, msg, ColorReset) } // FormatStep formats execution steps in cyan func FormatStep(msg string) string { return fmt.Sprintf("%s%s%s", ColorCyan, msg, ColorReset) } // FormatWarning formats warning messages in yellow func FormatWarning(msg string) string { return fmt.Sprintf("%s%s%s", ColorYellow, msg, ColorReset) } // FormatError formats error messages in bold red func FormatError(msg string) string { return fmt.Sprintf("%s%s%s%s", ColorBold, ColorRed, msg, ColorReset) } // FormatSuccess formats success status in bold green func FormatSuccess(msg string) string { return fmt.Sprintf("%s%s%s%s", ColorBold, ColorGreen, msg, ColorReset) } // FormatResult consistent formatting for results to be displayed // FormatResult consistent formatting for results to be displayed func FormatResult(result string, elapsed time.Duration, cobraCmd *cobra.Command) string { func FormatResult(result string, elapsed time.Duration, cobraCmd *cobra.Command) string { ret := result ret := result Loading