From 990fe99e2c70fc2ba339c225083b52b1b393a720 Mon Sep 17 00:00:00 2001 From: Victor Lacasse-Beaudoin Date: Wed, 14 Feb 2024 14:49:58 -0500 Subject: [PATCH] feat: Ajouter et documenter configuration par env --- README.md | 4 ++++ cmd/root.go | 3 +++ docker-compose.yaml | 10 ++++++++++ 3 files changed, 17 insertions(+) diff --git a/README.md b/README.md index b4bcb34..2cc6c87 100644 --- a/README.md +++ b/README.md @@ -14,6 +14,10 @@ Remplir .env BOTTINAG_POSTGRES_DATABASE=bottinag BOTTINAG_POSTGRES_PASSWORD=bottinag BOTTINAG_POSTGRES_USER=bottinag +BOTTINAG_API_KEY=bottinag +BOTTINAG_BOTTIN_API_KEY=bottin +BOTTINAG_WEB_PASSWORD=bottinag +BOTTINAG_WEB_USER=bottinag ``` Le reste s'effectue par le `go` toolchain ou `docker-compose`. diff --git a/cmd/root.go b/cmd/root.go index e56582d..3bf81b3 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -5,6 +5,7 @@ import ( "fmt" "log" "os" + "strings" "git.agecem.com/agecem/bottin-ag/config" "github.com/spf13/cobra" @@ -52,6 +53,8 @@ func initConfig() { viper.SetConfigName(".bottin-ag") } + viper.SetEnvPrefix("BOTTINAG") + viper.SetEnvKeyReplacer(strings.NewReplacer(".", "_")) viper.AutomaticEnv() // read in environment variables that match // If a config file is found, read it in. diff --git a/docker-compose.yaml b/docker-compose.yaml index 0d13037..d6b0f2f 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -15,6 +15,12 @@ services: - db build: . image: 'git.agecem.com/agecem/bottin-ag:latest' + environment: + BOTTINAG_API_KEY: "${BOTTINAG_API_KEY}" + BOTTINAG_BOTTIN_API_KEY: "${BOTTINAG_BOTTIN_API_KEY}" + BOTTINAG_DB_DATABASE: "${BOTTINAG_POSTGRES_DATABASE}" + BOTTINAG_DB_PASSWORD: "${BOTTINAG_POSTGRES_PASSWORD}" + BOTTINAG_DB_USER: "${BOTTINAG_POSTGRES_USER}" ports: - '3182:3182' volumes: @@ -27,6 +33,10 @@ services: - api build: . image: 'git.agecem.com/agecem/bottin-ag:latest' + environment: + BOTTINAG_WEB_API_KEY: "${BOTTINAG_API_KEY}" + BOTTINAG_WEB_PASSWORD: "${BOTTINAG_WEB_PASSWORD}" + BOTTINAG_WEB_USER: "${BOTTINAG_WEB_USER}" ports: - '3183:3183' volumes: