Skip to content

Commit

Permalink
Use env vars to configure app alternatively (#22)
Browse files Browse the repository at this point in the history
* Use env vars alternatively

* do not load config if env present

* update container version

* check properly if envs are set
  • Loading branch information
hanshasselberg authored Nov 12, 2021
1 parent a061b9b commit 5175dba
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
CONTAINER_NAME=hashicorpdemoapp/product-api
DB_CONTAINER_NAME=hashicorpdemoapp/product-api-db
CONTAINER_VERSION=v0.0.17
CONTAINER_VERSION=v0.0.18

test_functional:
shipyard run ./blueprint
Expand Down Expand Up @@ -35,4 +35,4 @@ build_docker: build_linux build_arm64
-f ./Dockerfile \
./bin \
--push
docker buildx rm multi
docker buildx rm multi
23 changes: 16 additions & 7 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ var conf *Config
var logger hclog.Logger

var configFile = env.String("CONFIG_FILE", false, "./conf.json", "Path to JSON encoded config file")
var dbConnection = env.String("DB_CONNECTION", false, "", "db connection string")
var bindAddress = env.String("BIND_ADDRESS", false, "", "Bind address")
var metricsAddress = env.String("METRICS_ADDRESS", false, "", "Metrics address")

const jwtSecret = "test"

Expand All @@ -46,15 +49,21 @@ func main() {
}
defer closer.Close()

conf = &Config{}
conf = &Config{
DBConnection: *dbConnection,
BindAddress: *bindAddress,
MetricsAddress: *metricsAddress,
}

// load the config
c, err := config.New(*configFile, conf, configUpdated)
if err != nil {
logger.Error("Unable to load config file", "error", err)
os.Exit(1)
// load the config, unless provided by env
if conf.DBConnection == "" || conf.BindAddress == "" {
c, err := config.New(*configFile, conf, configUpdated)
if err != nil {
logger.Error("Unable to load config file", "error", err)
os.Exit(1)
}
defer c.Close()
}
defer c.Close()

// configure the telemetry
t := telemetry.New(conf.MetricsAddress)
Expand Down

0 comments on commit 5175dba

Please sign in to comment.