heroku / heroku/heroku-buildpack-ruby

RAILS_ENV should not be set when using ps:exec

Open
#871 3 comments 0 reactions 0 assignees View on GitHub
Dominant language
Ruby
Stars
785
Forks
1.8k
Avg merge
1d 9h
Merged PRs (30d)
8

Description

The `ps:exec` command [does not load config variables](https://devcenter.heroku.com/articles/exec#environment-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:

```bash
if [[ -z "$SSH_CLIENT" ]]; then
export RAILS_ENV=${RAILS_ENV:-production}
export RACK_ENV=${RACK_ENV:-production}
fi
```

Contributor guide

No contributing guide indexed for this repository

Research direction

Start by tracing how the buildpack generates `.profile.d/ruby.sh` and how `ps:exec` handles environment variables. Update the generated script so the RAILS_ENV and RACK_ENV exports are guarded as shown, then verify that custom values remain available when using `ps:exec`.

Written by the indexing model from the issue text.

Assessment

Tech stack
bash, ruby
Domain
devops
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.