Skip to content

Commit fcbd42b

Browse files
committed
feat!: if SERVICE_ENV is not set, default to dev
If an environment is not set, it will try to load weird paths, which might not exist in Vault Make sure SERVICE_NAME is set as a lot of paths need that to work Remove peer references as that's no longer a think BREAKING CHANGE: will exit if SERVICE_NAME is not set
1 parent a6f51d7 commit fcbd42b

File tree

2 files changed

+29
-14
lines changed

2 files changed

+29
-14
lines changed

.golangci.yml

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,15 @@ linters:
1111
- misspell
1212
- whitespace
1313
- goimports
14+
- gofmt
1415
- gosec
15-
- testpackage
1616
- lll
17+
- unused
18+
- nonamedreturns
19+
- tenv
20+
- funlen
21+
- nestif
22+
- forbidigo
1723
disable:
1824
- scopelint
1925
- rowserrcheck
@@ -25,3 +31,8 @@ linters-settings:
2531
min-complexity: 10
2632
goimports:
2733
local-prefixes: github.com/articulate/docker-consul-template-bootstrap
34+
forbidigo:
35+
analyze-types: true
36+
forbid:
37+
- ^(fmt\\.Print(|f|ln)|print|println)$
38+
- ^spew\.(ConfigState\.)?Dump$

main.go

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,15 @@ func main() {
2727
Region: os.Getenv("AWS_REGION"),
2828
}
2929

30+
if cfg.Service == "" {
31+
log.Fatal().Msg("SERVICE_NAME cannot be blank")
32+
}
33+
34+
if cfg.Environment == "" {
35+
log.Warn().Msg("SERVICE_ENV is blank, defaulting to dev")
36+
cfg.Environment = "dev"
37+
}
38+
3039
if cfg.Region == "" {
3140
cfg.Region = "us-east-1"
3241
}
@@ -37,22 +46,11 @@ func main() {
3746
Str("region", cfg.Region).
3847
Logger()
3948

40-
// handles peer environments (peer-some-thing => peer), which loads stage vars
41-
if strings.HasPrefix(cfg.Environment, "peer") {
42-
cfg.Environment = "stage"
43-
}
44-
4549
if len(os.Args) < 2 {
4650
logger.Fatal().Msg("Missing command")
4751
}
4852

4953
env := NewEnvMap()
50-
pwd, err := os.Getwd()
51-
if err != nil {
52-
logger.Warn().Err(err).Msg("Cannot determine PWD")
53-
}
54-
env.Add("PWD", pwd)
55-
env.Add("AWS_REGION", cfg.Region)
5654

5755
if addr := os.Getenv("CONSUL_ADDR"); addr != "" {
5856
env.Merge(loadConsul(addr, cfg, logger))
@@ -66,10 +64,16 @@ func main() {
6664
logger.Warn().Msg("Not loading values from Vault. VAULT_ADDR is not set")
6765
}
6866

67+
pwd, err := os.Getwd()
68+
if err != nil {
69+
logger.Warn().Err(err).Msg("Cannot determine PWD")
70+
}
71+
env.Add("PWD", pwd)
72+
env.Add("AWS_REGION", cfg.Region)
73+
env.Add("SERVICE_ENV", cfg.Environment)
6974
env.Add("PROCESSOR_COUNT", strconv.Itoa(runtime.NumCPU()))
7075

71-
exit := run(os.Args[1], os.Args[2:], env.Environ(), logger)
72-
os.Exit(exit)
76+
os.Exit(run(os.Args[1], os.Args[2:], env.Environ(), logger))
7377
}
7478

7579
func loadConsul(addr string, c Config, l zerolog.Logger) Dict {

0 commit comments

Comments
 (0)