Kevin Lawrence
Kevin Lawrence

Reputation: 748

Are there any reasons not to use RAILS_ENV=staging on Heroku?

The Heroku documentation at https://devcenter.heroku.com/articles/deploying-to-a-custom-rails-environment says I shouldn't use a staging.rb file to define my staging environment.

It may be tempting to create another custom environment such as “staging” and create a config/environments/staging.rb and deploy to a Heroku app with RAILS_ENV=staging.

This is not a good practice. Instead we recommend always running in production mode and modifying any behavior by setting your config vars.

I think this is terrible advice and conflicts with well-established Rails best practice. However, I'm not here to argue about best practices. I'm here to ask:

Are there any reasons not to use RAILS_ENV=staging on Heroku?

Is there anything that will break if I create a staging.rb file and set the xxx_ENV config vars like this?

heroku config:add RACK_ENV=staging --remote staging
heroku config:add RAILS_ENV=staging --remote staging

Upvotes: 5

Views: 1967

Answers (2)

Damien MATHIEU
Damien MATHIEU

Reputation: 32629

No, there isn't anything that will break if you do this.

However, I do think that Heroku is right here (note that I work at Heroku). It introduces possible differences between your staging and production environments, when the only thing that changes between them should be configuration variables.
Heroku already provides a secure mean of setting configuration variables, with the config:set command.
Using 2 config files means you have to maintain the same configuration twice, and possible can have issues because you updated the configuration correctly in staging, but incorrectly in production.

As a side note, RACK_ENV should only ever have 3 values: production, development and none. See https://www.hezmatt.org/~mpalmer/blog/2013/10/13/rack_env-its-not-for-you.html

Upvotes: 6

eugen
eugen

Reputation: 9226

You'll get some warnings from Heroku when you deploy, but I can confirm I did run staging apps, with RAILS_ENV=staging, on Heroku. As long as you set the correct environment variables and Gemfile groups, it should just work.

My guess is that the reason they advise not to use custom environments is that they have some operational tooling that assumes your Rails app runs in production environment, but so far I didn't run into issues.

Upvotes: 1

Related Questions