From bb1684358a763e839ccac008859d9b282cda7eca Mon Sep 17 00:00:00 2001 From: Mike Landau Date: Fri, 5 Jan 2024 12:01:40 -0800 Subject: [PATCH] [envsec] Allow setting build env to dev or prod (#251) ## Summary TSIA This will allow for better integration testing with devbox ## How was it tested? --- internal/build/build.go | 22 ++++++++++++++++++---- pkg/envcli/version.go | 1 + 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/internal/build/build.go b/internal/build/build.go index af7a58f..b5297e8 100644 --- a/internal/build/build.go +++ b/internal/build/build.go @@ -5,19 +5,26 @@ package build import ( "os" - "strconv" + "strings" ) -var forceProd, _ = strconv.ParseBool(os.Getenv("ENVSEC_PROD")) - // These variables are set by the build script. var ( - IsDev = Version == "0.0.0-dev" && !forceProd + IsDev = Version == "0.0.0-dev" Version = "0.0.0-dev" Commit = "none" CommitDate = "unknown" ) +func init() { + buildEnv := strings.ToLower(os.Getenv("ENVSEC_BUILD_ENV")) + if buildEnv == "prod" { + IsDev = false + } else if buildEnv == "dev" { + IsDev = true + } +} + func Issuer() string { if IsDev { return "https://laughing-agnesi-vzh2rap9f6.projects.oryapis.com" @@ -38,3 +45,10 @@ func JetpackAPIHost() string { } return "https://api.jetpack.io" } + +func BuildEnv() string { + if IsDev { + return "dev" + } + return "prod" +} diff --git a/pkg/envcli/version.go b/pkg/envcli/version.go index 9deabcc..357c380 100644 --- a/pkg/envcli/version.go +++ b/pkg/envcli/version.go @@ -36,6 +36,7 @@ func versionCmdFunc(cmd *cobra.Command, _ []string, flags versionFlags) error { w := cmd.OutOrStdout() if flags.verbose { fmt.Fprintf(w, "Version: %v\n", build.Version) + fmt.Fprintf(w, "Build Env: %v\n", build.BuildEnv()) fmt.Fprintf(w, "Platform: %v\n", fmt.Sprintf("%s_%s", runtime.GOOS, runtime.GOARCH)) fmt.Fprintf(w, "Commit: %v\n", build.Commit) fmt.Fprintf(w, "Commit Time: %v\n", build.CommitDate)