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

Consider adding a warning when PORT environment variable is missing at runtime #938

Open
thephw opened this issue Dec 16, 2019 · 2 comments

Comments

@thephw
Copy link

thephw commented Dec 16, 2019

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

"bundle exec rackup config.ru -p $PORT"

Reference

buildpacks/samples#46

@thephw thephw changed the title Consider adding a warning when PORT environment variable is missing Consider adding a warning when PORT environment variable is missing at runtime Dec 16, 2019
@thephw
Copy link
Author

thephw commented Dec 18, 2019

Some historical context from the CNCF working group minutes:

2019.01.15
PORT

  • Assume for now: set in launch, not in build
  • For now, pack build can set on images defaulting to 8080
  • pack run can pick a port that’s the same for container and host

@thephw
Copy link
Author

thephw commented Jan 23, 2020

@schneems You have any thoughts/feelings about this?

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

No branches or pull requests

1 participant