Add support for env files
I'd suggest the following enhancement of envsubst to be more useful in combination with Docker/Docker Compose or Systemd Unit files:
- Add option to read environment from env files
- Allow multiple env files to be given and process them in order (to override values from former files to support development purposes)
- Add option to ignore the existing shell environment variables and build a fresh environment using the given env file(s) This would greatly simplify some development and deployment processes.
Yes, that makes sense.
@a8m is this feature in your plan?
Teller might meet your needs?
- https://github.com/tellerops/teller#whale-easy-docker-environment
- https://github.com/tellerops/teller#white_check_mark-prompts-and-options
- https://github.com/tellerops/teller#scroll-populate-templates
Not quite the same feature set or UX as envsubst offers, although you could technically use them both together.
I have given teller a try and looked over the project health. Presently it's got quite a few gotchas if your needs are beyond basic. It can't perform any proper parameter expansion like envsubst can (with it's own share of bugs related to that).
-
Add option to read environment from env files
This is supported. You can pull in all keys from the env file with
dotenvprovider using theenv_sync:property, or you can pull in only a subset of keys withenv:. It also supports a feature to rename variables.-
env_syncuses aremapproperty to list the original source ENV names as keys, while the values of those keys is the new target ENV name you want to map it to instead. -
envuses afieldproperty per ENV key listed. It works the other way around though the key is the target ENV to map to, and thefieldvalue is the original source name to get the value from.
-
-
Allow multiple env files to be given and process them in order (to override values from former files to support development purposes)
This is also supported. Your
.teller.yamlfile can specify multiple providers (and multiple instances of a provider by using a custom name + thekind: <provider here>property). The drawback is providers with the same output keys don't seem to have a consistent ordering, thus you can't have a deterministic layering through a single config/run.In your case though, when you only need to choose a different
.envfile, you can do this with thedotenvproviderpathproperty. It can leverage theoptssetting to use a variable (only works withpath:), and you can populate that via ENV as well as provide a default to fallback to. This way the same provider config is re-used across the different.envfiles 👍 -
Add option to ignore the existing shell environment variables and build a fresh environment using the given env file(s)
Teller can support this too. It's the default behaviour with
teller run. If you need the environment to not be ignored you'd add thecarry_env: truesetting (does not affect providers).
Useful providers:
-
dotenv -
processenv -
filesystem(for assigning an ENV value by reading content of a file)