From 7d65af88d73c663b0c3c2d2296e2f3c46c2aad73 Mon Sep 17 00:00:00 2001 From: OZGCloud <ozgcloud@mgm-tp.com> Date: Mon, 11 Nov 2024 17:33:46 +0100 Subject: [PATCH] OZG-6747 refactor config files --- config/{config-development.yml => config-local.yml} | 0 config/{config-production.yml => config.yml} | 0 internal/config/config.go | 10 ++++++---- src/main/helm/templates/deployment.yaml | 2 +- src/test/helm/deployment_env_test.yaml | 11 ++++++++++- 5 files changed, 17 insertions(+), 6 deletions(-) rename config/{config-development.yml => config-local.yml} (100%) rename config/{config-production.yml => config.yml} (100%) diff --git a/config/config-development.yml b/config/config-local.yml similarity index 100% rename from config/config-development.yml rename to config/config-local.yml diff --git a/config/config-production.yml b/config/config.yml similarity index 100% rename from config/config-production.yml rename to config/config.yml diff --git a/internal/config/config.go b/internal/config/config.go index 52be8d2..b49a424 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -34,7 +34,7 @@ import ( ) const ( - defaultEnv = "development" + defaultConfig = "config.yml" testFilePath = "testdata/test_config.yml" ) @@ -61,12 +61,14 @@ type Config struct { func LoadConfig(configFilePath ...string) Config { var config Config + configFile := defaultConfig + env := os.Getenv("APP_ENV") - if env == "" { - env = defaultEnv + if env != "" { + configFile = fmt.Sprintf("config-%s.yml", env) } - fp := fmt.Sprintf("config/config-%s.yml", env) + fp := fmt.Sprintf("config/%s", configFile) if len(configFilePath) > 0 { fp = configFilePath[0] diff --git a/src/main/helm/templates/deployment.yaml b/src/main/helm/templates/deployment.yaml index 31ce8ed..687f78a 100644 --- a/src/main/helm/templates/deployment.yaml +++ b/src/main/helm/templates/deployment.yaml @@ -59,7 +59,7 @@ spec: containers: - env: - name: APP_ENV - value: "production" + value: "{{ .Values.appEnv | default "dev" }}" {{- with include "app.getCustomList" . }} {{ . | indent 10 }} {{- end }} diff --git a/src/test/helm/deployment_env_test.yaml b/src/test/helm/deployment_env_test.yaml index d7a973a..8223aac 100644 --- a/src/test/helm/deployment_env_test.yaml +++ b/src/test/helm/deployment_env_test.yaml @@ -69,4 +69,13 @@ tests: path: spec.template.spec.containers[0].env content: name: APP_ENV - value: "production" \ No newline at end of file + value: "dev" + - it: should set APP_ENV + set: + appEnv: prod + asserts: + - contains: + path: spec.template.spec.containers[0].env + content: + name: APP_ENV + value: "prod" \ No newline at end of file -- GitLab