Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for env files #23

Open
ahochsteger opened this issue Jun 5, 2020 · 4 comments
Open

Add support for env files #23

ahochsteger opened this issue Jun 5, 2020 · 4 comments

Comments

@ahochsteger
Copy link

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.
@a8m
Copy link
Owner

a8m commented Jun 20, 2020

Sounds good to me.

Should we follow the the docker-compose syntax rules?

@ahochsteger
Copy link
Author

Yes, that makes sense.

@mehdihadeli
Copy link

@a8m is this feature in your plan?

@polarathene
Copy link
Contributor

polarathene commented Aug 29, 2023

Teller might meet your needs?

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 dotenv provider using the env_sync: property, or you can pull in only a subset of keys with env:. It also supports a feature to rename variables.

    • env_sync uses a remap property 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.
    • env uses a field property per ENV key listed. It works the other way around though the key is the target ENV to map to, and the field value 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.yaml file can specify multiple providers (and multiple instances of a provider by using a custom name + the kind: <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 .env file, you can do this with the dotenv provider path property. It can leverage the opts setting to use a variable (only works with path:), 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 .env files 👍

  • 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 the carry_env: true setting (does not affect providers).

Useful providers:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants