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

Preserve existing ENV variables if they exist #21

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

jakesgordon
Copy link

Overview

This PR ensures that existing environment variables take priority over those inside the .env file, this allows us to override the .env file values with command line values, e.g.

FOO=bar mix phx.server

... and the command line FOO=bar will take priority over any instance of FOO in the .env file

Priority

Note that because of this change in behavior I also needed to swap around the priority of the .env.#{current_env} file in order to ensure that version continues to take priority over the more generic .env variation (to maintain the existing behavior). The new order loads the env specific version first and now if a variable is set by that variant it takes priority over the generic .env. E.g the priority order is now:

  1. any existing environment variables
  2. any environment variables specified in the .env.#{current_env} variant (if it exists)
  3. any environment variables specified in the .env variant.

Tests

I added a new unit test to confirm this behavior. All existing tests still pass.

This change ensures that existing ENV variables take priority over those
inside the .env file, this means we can still do

```
FOO=bar mix phx.server
```

... and the command line FOO will take priority over the .env FOO
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

Successfully merging this pull request may close these issues.

1 participant