heroku / heroku/heroku-buildpack-ruby
Consider adding a warning when PORT environment variable is missing at runtime
- Dominant language
- Ruby
- Stars
- 785
- Forks
- 1.8k
- Avg merge
- 1d 9h
- Merged PRs (30d)
- 8
Description
# Description
`heroku-buildpack-ruby` require that the runtime specify a `PORT` environment variable. Although consistent across buildpacks -- a recurring issue is building a rack image and forgetting to specify the port at runtime. For many buildpacks, the error is self evident.
When building a rack application with the ruby buildpack, the error is a little more cryptic:
```
bundler: failed to load command: rackup (/layers/heroku_ruby/gems/vendor/bundle/ruby/2.5.0/bin/rackup)
OptionParser::MissingArgument: missing argument: -p
/layers/heroku_ruby/gems/vendor/bundle/ruby/2.5.0/gems/rack-2.0.7/lib/rack/server.rb:97:in `parse!'
/layers/heroku_ruby/gems/vendor/bundle/ruby/2.5.0/gems/rack-2.0.7/lib/rack/server.rb:333:in `parse_options'
/layers/heroku_ruby/gems/vendor/bundle/ruby/2.5.0/gems/rack-2.0.7/lib/rack/server.rb:195:in `initialize'
```
# Suggestion
We could clarify the error message for all application without affecting compliance and integration with other language buildpacks.
```
if [[ -z "${PORT}" ]]; then
>&2 echo "Runtime is missing environment variable PORT"
fi
```
# Alternate Considerations
- Could be resolved by specifying a default at buildtime
- Could be resolved by specifying a default in the buildpack
- Could be left as it currently operates
# Code in question
https://github.com/heroku/heroku-buildpack-ruby/blob/22b24b66c42afdf8c95cc16143221ffd7b2d7f7b/lib/language_pack/rack.rb#L32
# Reference
https://github.com/buildpacks/samples/issues/46
Contributor guide
No contributing guide indexed for this repository
Research direction
Start with lib/language_pack/rack.rb at the referenced line and inspect how the Rack runtime command is assembled. Review the buildpacks/samples issue and the alternate considerations before confirming the intended missing-PORT behavior. Done means the runtime failure is clearer without affecting buildpack compliance or integration with other language buildpacks.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- ruby
- Domain
- build-system
- Issue type
- Feature
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100