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

.env not working in production #651

Closed
rafaels88 opened this issue Oct 7, 2016 · 5 comments
Closed

.env not working in production #651

rafaels88 opened this issue Oct 7, 2016 · 5 comments
Assignees
Labels

Comments

@rafaels88
Copy link

rafaels88 commented Oct 7, 2016

I just updated my Hanami application from 0.7.0 to 0.8.0 and .env file is not been loading in production. After reviewing environment.rb file in 0.8.0 version, I saw this line:

 DEFAULT_DOTENV_ENV = '.env.%s'.freeze

So, I tried to change my .env file to .env.production and it worked.

It seems that the solution for this is pretty simple. =)

@cllns
Copy link
Member

cllns commented Oct 7, 2016

Thanks for opening this issue! 🌸

We use the dotenv gem for this functionality. On 0.7, it was a hard dependency of hanami. For 0.8, it's been moved to the default generated Gemfile, but only in the :development and :test groups, so it shouldn't be loaded in production. See here: https://github.com/hanami/hanami/blob/master/lib/hanami/generators/application/app/Gemfile.tt#L40-L42

We want to discourage people from having production environment variables in source control. I think this experience can be improved though, since a lot of people run into this problem. At the very least, this behavior should be explicity documented, but ideally we'd be able to show an error to the user to help them. Any ideas?

@rafaels88
Copy link
Author

Humm I see. That's fair enough. But, as you said, it would be nice to have a documentation mentioning a good way to set ENV variables in production, without using .env file. I mean, in a AWS-like environment probably there will be a dashboard where you just configure that, but in a Digital Ocean-like it is not trivial (at least for me) how to solve that without a .env file in production.

Also, there are some places where documentation mention that .env works on production, it would be nice remove that.

What do you think?

@cllns
Copy link
Member

cllns commented Oct 10, 2016

Just added an issue to create an Environment Variables guide :) hanami/hanami.github.io#224

Feel free to open a PR at https://github.com/hanami/hanami.github.io/ for any error you see in the Guides, and in each repo if it's in Rdoc/comments :)

Also, I'd probably recommend using .env.production instead of just .env, just to signify that it's really just for production (and create an entry in .gitignore for that too).

@b264
Copy link

b264 commented Oct 20, 2016

What if folks have .env.production ignored in source control? ( .gitignore for example )

@jodosha
Copy link
Member

jodosha commented Oct 24, 2016

@rafaels88 Hi 😄 . I think it's just a matter of documentation, we can write a clear statement about the .env expectations in production, why we it's a bad idea to have it in production.

We can cover most common vendors (Heroku, AWS) too. But we expect people to understand their deployment environment.


@b264 Hey :) I think that adding .env.production in source control is misleading because we don't generate that artifact. And even with that people can bypass the check by adding a .env file and using Dotenv directly.

We should educate rather than forbid.


I'm closing this as it isn't a bug.

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

No branches or pull requests

4 participants