diff --git a/.golangci.yml b/.golangci.yml index 9726275..f037c10 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -11,9 +11,15 @@ linters: - misspell - whitespace - goimports + - gofmt - gosec - - testpackage - lll + - unused + - nonamedreturns + - tenv + - funlen + - nestif + - forbidigo disable: - scopelint - rowserrcheck @@ -25,3 +31,8 @@ linters-settings: min-complexity: 10 goimports: local-prefixes: github.com/articulate/docker-consul-template-bootstrap + forbidigo: + analyze-types: true + forbid: + - ^(fmt\\.Print(|f|ln)|print|println)$ + - ^spew\.(ConfigState\.)?Dump$ diff --git a/Makefile b/Makefile index e6ba541..d0a8d5c 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,4 @@ PKG_LIST := $(shell go list ./... | grep -v /vendor/) -RELEASE ?= docker-consul-template-bootstrap help: @echo "+ $@" diff --git a/README.md b/README.md index 9b447aa..3bfc5b0 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ Load values from Consul and Vault as environment variables. ## Installing -Download the [latest release](https://github.com/articulate/docker-consul-template-bootstrap/releases/latest), +Download the [latest release](https://github.com/articulate/docker-bootstrap/releases), add it to your image, and set it as your `ENTRYPOINT`. If you are using Buildkit you can use the `TARGETARCH` arg to `ADD` the correct @@ -12,7 +12,7 @@ architecture. ```docker ARG TARGETARCH -ADD --chmod=755 https://github.com/articulate/docker-consul-template-bootstrap/releases/latest/download/docker-consul-template-bootstrap_linux_${TARGETARCH} /entrypoint +ADD --chmod=755 https://github.com/articulate/docker-bootstrap/releases/latest/download/docker-bootstrap_linux_${TARGETARCH} /entrypoint ENTRYPOINT [ "/entrypoint" ] ``` diff --git a/go.mod b/go.mod index 4cc5984..0717abe 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ -module github.com/articulate/docker-consul-template-bootstrap +module github.com/articulate/docker-bootstrap -go 1.20 +go 1.21 require ( github.com/aws/aws-sdk-go-v2/config v1.18.42 diff --git a/go.sum b/go.sum index 031ebdc..d7522ec 100644 --- a/go.sum +++ b/go.sum @@ -74,16 +74,19 @@ github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5y github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= github.com/google/btree v1.0.1 h1:gK4Kx5IaGY9CD5sPJ36FHiBJ6ZXl0kilRiiCj+jdYp4= +github.com/google/btree v1.0.1/go.mod h1:xXMiIv4Fb/0kKde4SpL7qlzvu5cMJDRkFDxJfI9uaxA= github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.7/go.mod h1:n+brtR0CgQNWTVd5ZUFpTBC8YFBDLK/h/bpaJ8/DtOE= github.com/google/go-cmp v0.5.8/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38= +github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= github.com/hashicorp/consul/api v1.25.1 h1:CqrdhYzc8XZuPnhIYZWH45toM0LB9ZeYr/gvpLVI3PE= github.com/hashicorp/consul/api v1.25.1/go.mod h1:iiLVwR/htV7mas/sy0O+XSuEnrdBUUydemjxcUrAt4g= github.com/hashicorp/consul/sdk v0.14.1 h1:ZiwE2bKb+zro68sWzZ1SgHF3kRMBZ94TwOCFRF4ylPs= +github.com/hashicorp/consul/sdk v0.14.1/go.mod h1:vFt03juSzocLRFo59NkeQHHmQa6+g7oU0pfzdI1mUhg= github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4= github.com/hashicorp/errwrap v1.1.0 h1:OxrOeh75EUXMY8TBjag2fzXGZ40LB6IKw45YeGUDY2I= github.com/hashicorp/errwrap v1.1.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4= @@ -100,6 +103,7 @@ github.com/hashicorp/go-immutable-radix v1.3.1 h1:DKHmCUm2hRBK510BaiZlwvpD40f8bJ github.com/hashicorp/go-immutable-radix v1.3.1/go.mod h1:0y9vanUI8NX6FsYoO3zeMjhV/C5i9g4Q3DwcSNZ4P60= github.com/hashicorp/go-msgpack v0.5.3/go.mod h1:ahLV/dePpqEmjfWmKiqvPkv/twdG7iPBM1vqhUKIvfM= github.com/hashicorp/go-msgpack v0.5.5 h1:i9R9JSrqIz0QVLz3sz+i3YJdT7TTSLcfLLzJi9aZTuI= +github.com/hashicorp/go-msgpack v0.5.5/go.mod h1:ahLV/dePpqEmjfWmKiqvPkv/twdG7iPBM1vqhUKIvfM= github.com/hashicorp/go-multierror v1.0.0/go.mod h1:dHtQlpGsu+cZNNAkkCN/P3hoUDHhCYQXV3UM06sGGrk= github.com/hashicorp/go-multierror v1.1.0/go.mod h1:spPvp8C1qA32ftKqdAHm4hHTbPw+vmowP0z+KUhOZdA= github.com/hashicorp/go-multierror v1.1.1 h1:H5DkEtf6CXdFp0N0Em5UCwQpXMWke8IA0+lD48awMYo= @@ -126,6 +130,7 @@ github.com/hashicorp/go-uuid v1.0.2/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/b github.com/hashicorp/go-uuid v1.0.3 h1:2gKiV6YVmrJ1i2CKKa9obLvRieoRGviZFL26PcT/Co8= github.com/hashicorp/go-uuid v1.0.3/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro= github.com/hashicorp/go-version v1.2.1 h1:zEfKbn2+PDgroKdiOzqiE8rsmLqU2uwi5PB5pBJ3TkI= +github.com/hashicorp/go-version v1.2.1/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA= github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= github.com/hashicorp/golang-lru v0.5.4 h1:YDjusn29QI/Das2iO9M0BHnIbxPeyuCHsjMW+lJfyTc= github.com/hashicorp/golang-lru v0.5.4/go.mod h1:iADmTwqILo4mZ8BN3D2Q6+9jd8WM5uGBxy+E8yxSoD4= diff --git a/main.go b/main.go index 41235db..c78ca8d 100644 --- a/main.go +++ b/main.go @@ -27,6 +27,15 @@ func main() { Region: os.Getenv("AWS_REGION"), } + if cfg.Service == "" { + log.Fatal().Msg("SERVICE_NAME cannot be blank") + } + + if cfg.Environment == "" { + log.Warn().Msg("SERVICE_ENV is blank, defaulting to dev") + cfg.Environment = "dev" + } + if cfg.Region == "" { cfg.Region = "us-east-1" } @@ -37,22 +46,11 @@ func main() { Str("region", cfg.Region). Logger() - // handles peer environments (peer-some-thing => peer), which loads stage vars - if strings.HasPrefix(cfg.Environment, "peer") { - cfg.Environment = "stage" - } - if len(os.Args) < 2 { logger.Fatal().Msg("Missing command") } env := NewEnvMap() - pwd, err := os.Getwd() - if err != nil { - logger.Warn().Err(err).Msg("Cannot determine PWD") - } - env.Add("PWD", pwd) - env.Add("AWS_REGION", cfg.Region) if addr := os.Getenv("CONSUL_ADDR"); addr != "" { env.Merge(loadConsul(addr, cfg, logger)) @@ -66,10 +64,16 @@ func main() { logger.Warn().Msg("Not loading values from Vault. VAULT_ADDR is not set") } + pwd, err := os.Getwd() + if err != nil { + logger.Warn().Err(err).Msg("Cannot determine PWD") + } + env.Add("PWD", pwd) + env.Add("AWS_REGION", cfg.Region) + env.Add("SERVICE_ENV", cfg.Environment) env.Add("PROCESSOR_COUNT", strconv.Itoa(runtime.NumCPU())) - exit := run(os.Args[1], os.Args[2:], env.Environ(), logger) - os.Exit(exit) + os.Exit(run(os.Args[1], os.Args[2:], env.Environ(), logger)) } func loadConsul(addr string, c Config, l zerolog.Logger) Dict {