Skip to content

Commit

Permalink
[envsec] Allow setting build env to dev or prod (#251)
Browse files Browse the repository at this point in the history
## Summary

TSIA

This will allow for better integration testing with devbox

## How was it tested?
  • Loading branch information
mikeland73 authored Jan 5, 2024
1 parent 611b4a4 commit bb16843
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
22 changes: 18 additions & 4 deletions internal/build/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -38,3 +45,10 @@ func JetpackAPIHost() string {
}
return "https://api.jetpack.io"
}

func BuildEnv() string {
if IsDev {
return "dev"
}
return "prod"
}
1 change: 1 addition & 0 deletions pkg/envcli/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit bb16843

Please sign in to comment.