Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat!: if SERVICE_ENV is not set, default to dev #178

Merged
merged 2 commits into from
Oct 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,15 @@ linters:
- misspell
- whitespace
- goimports
- gofmt
- gosec
- testpackage
- lll
- unused
- nonamedreturns
- tenv
- funlen
- nestif
- forbidigo
disable:
- scopelint
- rowserrcheck
Expand All @@ -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$
1 change: 0 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
PKG_LIST := $(shell go list ./... | grep -v /vendor/)
RELEASE ?= docker-consul-template-bootstrap

help:
@echo "+ $@"
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ 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
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" ]
```
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
@@ -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
Expand Down
5 changes: 5 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand All @@ -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=
Expand All @@ -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=
Expand Down
30 changes: 17 additions & 13 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
Expand All @@ -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))
Expand All @@ -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 {
Expand Down
Loading