heroku / heroku-buildpack-ruby

Heroku's buildpack for Ruby applications.
MIT License
787 stars 1.87k forks source link

RAILS_ENV should not be set when using ps:exec #871

Open jkutner opened 5 years ago

jkutner commented 5 years ago

The ps:exec command does not load config variables, but does run .profile.d scripts. This results in incorrect values being set for RAILS_ENV and RACK_ENV.

For example, if you inspect an app's .profile.d/ruby.sh, you'll see:

~ $ cat .profile.d/ruby.sh | grep _ENV
export RAILS_ENV=${RAILS_ENV:-production}
export RACK_ENV=${RACK_ENV:-production}

Because your custom set RAILS_ENV config var is not load, the profile.d script sets the default value of production.

Correct behavior

The .profile.d/ruby.sh should wrap the export lines in an if guard like:

if [[ -z "$SSH_CLIENT" ]]; then
  export RAILS_ENV=${RAILS_ENV:-production}
  export RACK_ENV=${RACK_ENV:-production}
fi
schneems commented 5 years ago

Wouldn't all default config vars fall into the same trap here?

jkutner commented 5 years ago

@schneems yes

schneems commented 4 years ago

Related support ticket: https://heroku.support/708919