From 00e43b82742bd0f70b742e559ba785ab563ed804 Mon Sep 17 00:00:00 2001 From: Michael Barz Date: Thu, 1 Feb 2024 12:24:30 +0100 Subject: [PATCH] feat: use env variable in yaml config files --- changelog/unreleased/enhancement-env-in-yaml.md | 15 +++++++++++++++ ocis-pkg/config/helpers.go | 1 + 2 files changed, 16 insertions(+) create mode 100644 changelog/unreleased/enhancement-env-in-yaml.md diff --git a/changelog/unreleased/enhancement-env-in-yaml.md b/changelog/unreleased/enhancement-env-in-yaml.md new file mode 100644 index 000000000..29cef7756 --- /dev/null +++ b/changelog/unreleased/enhancement-env-in-yaml.md @@ -0,0 +1,15 @@ +Enhancement: Use environment variables in yaml config files + +We added the ability to use environment variables in yaml config files. This allows to use environment variables in the config files of the ocis services which will be replaced by the actual value of the environment variable at runtime. + +Example: + +``` +web: + http: + addr: ${SOME_HTTP_ADDR} +``` + +This makes it possible to use the same config file for different environments without the need to change the config file itself. This is especially useful when using docker-compose to run the ocis services. It is a common pattern to create an .env file which contains the environment variables for the docker-compose file. Now you can use the same .env file to configure the ocis services. + +https://github.com/owncloud/ocis/pull/8339 diff --git a/ocis-pkg/config/helpers.go b/ocis-pkg/config/helpers.go index 7b72333e9..c0ec6f1f4 100644 --- a/ocis-pkg/config/helpers.go +++ b/ocis-pkg/config/helpers.go @@ -20,6 +20,7 @@ var ( func BindSourcesToStructs(service string, dst interface{}) (*gofig.Config, error) { cnf := gofig.NewWithOptions(service) cnf.WithOptions(func(options *gofig.Options) { + options.ParseEnv = true options.DecoderConfig.TagName = decoderConfigTagName }) cnf.AddDriver(gooyaml.Driver)