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

`heroku local` makes it impossible to override settings from `.env.<environment>` #234

Closed
gabebw opened this issue Jan 26, 2016 · 3 comments

Comments

Projects
None yet
1 participant
@gabebw
Copy link

commented Jan 26, 2016

I'm using dotenv-rails 2.1.0.

I set an environment variable named IN_BOTH_DOTENVS in both .env and .env.development, and a variable named ONLY_IN_DOTENV_DEVELOPMENT in .env.development.

$ cat .env
IN_BOTH_DOTENVS=DOTENV

$ cat .env.development
IN_BOTH_DOTENVS=DOTENV_DEVELOPMENT
ONLY_IN_DOTENV_DEVELOPMENT=DOTENV_DEVELOPMENT

.env.development should take precedence over .env and both environment variables .

I set up a test case Rails app (available here). I set up a root path that renders the value of both variables. (And I'm using WEBrick, though I see the same results with Puma.)

With heroku local, Rails only finds the value from .env and doesn't override it with the value from .env.development:

# heroku local

$ curl localhost:3000
IN_BOTH_DOTENVS: DOTENV
ONLY_IN_DOTENV_DEVELOPMENT: DOTENV_DEVELOPMENT

When I run rails server, everything works as expected:

# rails server

$ curl localhost:3000
IN_BOTH_DOTENVS: DOTENV_DEVELOPMENT
ONLY_IN_DOTENV_DEVELOPMENT: DOTENV_DEVELOPMENT

Interestingly, even with heroku local, settings that are only set in .env.development come through fine. It just can't override settings from .env.

Expected behavior:

.env.development should override .env when running with heroku local.

@gabebw gabebw referenced this issue Jan 26, 2016

Merged

Ignore .env #18

@gabebw

This comment has been minimized.

Copy link
Author

commented Jan 26, 2016

I see the same incorrect results from foreman start. (I believe heroku local runs forego.)

@gabebw

This comment has been minimized.

Copy link
Author

commented Jan 27, 2016

It turns out Foreman no longer uses dotenv, so only reads from .env: ddollar/foreman@19e9806

And Forego never read from anything other than .env, it looks like.

Closing this issue since it's not dotenv's problem.


For future people who find this issue, both foreman and forego take a --env/-e option that lets you specify fallbacks. To use .env and override it with .env.development:

$ foreman start --env .env,.env.development
# or
$ forego start --env .env,.env.development
# or
$ heroku local --env .env,.env.development

If you're using foreman (but not forego/heroku local), you can set an option in the .foreman file:

# .foreman
env: .env,.env.development

...and then just do foreman start without the --env.

@gabebw gabebw closed this Jan 27, 2016

@gabebw

This comment has been minimized.

Copy link
Author

commented Jan 27, 2016

(I'm still not quite sure why using foreman doesn't work even with dotenv in the Gemfile, though.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.