From 692728b77082708f21a5dd4d83685080272bf39e Mon Sep 17 00:00:00 2001 From: Yar Kravtsov Date: Mon, 21 Oct 2024 08:47:18 +0300 Subject: [PATCH] feat: Implement environment variable expansion in configuration parsing --- README.md | 6 +++--- pkg/config/config.go | 4 +++- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 68e1d57..8c51c45 100644 --- a/README.md +++ b/README.md @@ -81,9 +81,9 @@ storages: image: postgres:16 - postgres_data:/var/lib/postgresql/data env_vars: - - POSTGRES_PASSWORD=S3cret - - POSTGRES_USER=my-app - - POSTGRES_DB=my-app + - POSTGRES_PASSWORD=${POSTGRES_PASSWORD} + - POSTGRES_USER=${POSTGRES_USER} + - POSTGRES_DB=${POSTGRES_DB} volumes: - postgres_data diff --git a/pkg/config/config.go b/pkg/config/config.go index 0dfb6d7..4490a39 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -77,8 +77,10 @@ type Volume struct { } func ParseConfig(data []byte) (*Config, error) { + expandedData := os.ExpandEnv(string(data)) + var config Config - if err := yaml.Unmarshal(data, &config); err != nil { + if err := yaml.Unmarshal([]byte(expandedData), &config); err != nil { return nil, fmt.Errorf("error parsing YAML: %v", err) }