From 66bb03f8eaf0640ec1aa88c6bd5a323d5016f67f Mon Sep 17 00:00:00 2001 From: OZGCloud <ozgcloud@mgm-tp.com> Date: Thu, 24 Oct 2024 15:39:10 +0200 Subject: [PATCH] OZG-6747 set different config profiles --- Jenkinsfile | 1 + cmd/antragsraum-proxy/main.go | 4 +++ config/{config.yml => config-development.yml} | 0 config/config-production.yml | 11 ++++++++ internal/config/config.go | 27 +++++++++++-------- src/main/helm/templates/deployment.yaml | 8 +----- 6 files changed, 33 insertions(+), 18 deletions(-) rename config/{config.yml => config-development.yml} (100%) create mode 100755 config/config-production.yml diff --git a/Jenkinsfile b/Jenkinsfile index be1c6e4..acac81a 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -75,6 +75,7 @@ tools { go 'go-1.22.0' } chmod +x ./buf ./buf generate #to compile go statically with these tags, so that the binary is not dynamically linked and from scratch in Dockerfile will work + APP_ENV=production go build -tags osusergo,netgo cmd/antragsraum-proxy/main.go ''' diff --git a/cmd/antragsraum-proxy/main.go b/cmd/antragsraum-proxy/main.go index 4c86d80..1af8547 100644 --- a/cmd/antragsraum-proxy/main.go +++ b/cmd/antragsraum-proxy/main.go @@ -29,12 +29,16 @@ import ( "antragsraum-proxy/internal/config" "antragsraum-proxy/internal/mock" "antragsraum-proxy/internal/server" + "fmt" ) var version = "v1.1.0-beta.1" func main() { conf := config.LoadConfig() + fmt.Printf("HTTP Server Port: %d\n", conf.Http.Server.Port) + fmt.Printf("gRPC Server Port: %d\n", conf.Grpc.Server.Port) + fmt.Printf("Logging Level: %s\n", conf.Logging.Level) if conf.Grpc.Server.Mock { go mock.StartGrpcServer() diff --git a/config/config.yml b/config/config-development.yml similarity index 100% rename from config/config.yml rename to config/config-development.yml diff --git a/config/config-production.yml b/config/config-production.yml new file mode 100755 index 0000000..06bfbda --- /dev/null +++ b/config/config-production.yml @@ -0,0 +1,11 @@ +http: + server: + port: 8082 +grpc: + server: + mock: false + port: 9090 + router: + port: 50051 +logging: + level: "INFO" \ No newline at end of file diff --git a/internal/config/config.go b/internal/config/config.go index 5089b4c..ad387b0 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -31,40 +31,45 @@ import ( "log" "os" "testing" + "fmt" ) const ( - defaultFilePath = "config/config.yml" - testFilePath = "testdata/test_config.yml" + defaultEnv = "development" + testFilePath = "testdata/test_config.yml" ) type Config struct { Http struct { Server struct { - Port int `yaml:"port" envconfig:"HTTP_SERVER_PORT"` + Port int `yaml:"port"` } `yaml:"server"` } `yaml:"http"` Grpc struct { Server struct { - Mock bool `yaml:"mock" envconfig:"GRPC_SERVER_MOCK"` + Mock bool `yaml:"mock"` Port int `yaml:"port" envconfig:"GRPC_SERVER_PORT"` } `yaml:"server"` Router struct { - Port int `yaml:"port" envconfig:"GRPC_ROUTER_PORT"` + Port int `yaml:"port"` } `yaml:"router"` } `yaml:"grpc"` Logging struct { - Level string `yaml:"level" envconfig:"LOGGING_LEVEL"` + Level string `yaml:"level"` } `yaml:"logging"` } -func LoadConfig(configFilePath ...string) Config { +func LoadConfig() Config { var config Config - fp := defaultFilePath - if len(configFilePath) > 0 { - fp = configFilePath[0] - } else if testing.Testing() { + env := os.Getenv("APP_ENV") + if env == "" { + env = defaultEnv + } + + fp := fmt.Sprintf("config/config-%s.yml", env) + + if testing.Testing() { fp = testFilePath } diff --git a/src/main/helm/templates/deployment.yaml b/src/main/helm/templates/deployment.yaml index 5d7733e..0020d63 100644 --- a/src/main/helm/templates/deployment.yaml +++ b/src/main/helm/templates/deployment.yaml @@ -58,14 +58,8 @@ spec: app.kubernetes.io/name: {{ .Release.Name }} containers: - env: - - name: LOGGING_LEVEL - value: "INFO" - - name: HTTP_SERVER_PORT - value: "8082" - - name: GRPC_SERVER_MOCK - value: "false" - name: GRPC_SERVER_PORT - value: "9090" + value: "{{ .Values.grpc.server.port }}" {{- with include "app.getCustomList" . }} {{ . | indent 10 }} {{- end }} -- GitLab