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

Vendor Ruby if an installation is not found #103

Merged
merged 1 commit into from
Jun 21, 2022

Conversation

edmorley
Copy link
Member

The ERB templating feature of this buildpack requires that the erb command (part of Ruby) be available at runtime, in order that the nginx config templates can be rendered into a valid nginx config.

On Heroku-22 the stack image no longer includes a system Ruby installation, so in order for this buildpack to continue to work, a Ruby install must be vendored by this buildpack.

If an app already uses the Ruby buildpack, and that buildpack is ordered prior to the nginx buildpack, then this buildpack will skip the Ruby vendoring step to save installing a redundant copy of Ruby.

Fixes #101.
GUS-W-11321729.

The ERB templating feature of this buildpack requires that the
`erb` command (part of Ruby) be available at runtime, in order
that the nginx config templates can be rendered into a valid nginx
config.

On Heroku-22 the stack image no longer includes a system Ruby
installation, so in order for this buildpack to continue to work, a
Ruby install must be vendored by this buildpack.

If an app already uses the Ruby buildpack, and that buildpack is
ordered prior to the nginx buildpack, then this buildpack will skip
the Ruby vendoring step to save installing a redundant copy of Ruby.

Fixes #101.
GUS-W-11321729.
@edmorley edmorley self-assigned this Jun 20, 2022
@edmorley
Copy link
Member Author

edmorley commented Jun 20, 2022

Tested on Heroku-22 and seems to work fine:

$ mkdir nginx-test && cd $_
$ git init
...
$ h create --stack heroku-22 --buildpack 'https://github.com/heroku/heroku-buildpack-nginx#edmorley/vendor-ruby-if-needed'
...
$ mkdir config public
$ curl -sSfL https://raw.githubusercontent.com/heroku/heroku-buildpack-nginx/main/config/nginx-solo-sample.conf.erb -o config/nginx.conf.erb
$ echo 'hello' > public/hello.txt
$ echo 'web: bin/start-nginx-solo' > Procfile
$ git add -A && git commit -m '.' && git push heroku main
...
remote: -----> Building on the Heroku-22 stack
remote: -----> Using buildpack: https://github.com/heroku/heroku-buildpack-nginx#edmorley/vendor-ruby-if-needed
remote: -----> nginx-buildpack app detected
remote: ./
remote: ./mime.types
remote: ./nginx
remote: ./nginx-debug
remote: -----> nginx-buildpack: Installed nginx/1.20.2 to app/bin
remote: -----> nginx-buildpack: An existing Ruby installation was not found (required for erb template support)
remote: -----> nginx-buildpack: Installed Ruby 3.1.2
remote: -----> nginx-buildpack: Added start-nginx to app/bin
remote: -----> nginx-buildpack: Added start-nginx-debug to app/bin
remote: -----> nginx-buildpack: Added start-nginx-solo to app/bin
remote: -----> nginx-buildpack: Default mime.types copied to app/config/
remote: -----> nginx-buildpack: Custom config found in app/config.
remote: -----> Discovering process types
remote:        Procfile declares types -> web
remote:
remote: -----> Compressing...
remote:        Done: 25.1M
remote: -----> Launching...
remote:        Released v4
remote:        https://dry-badlands-86959.herokuapp.com/ deployed to Heroku
remote:
remote: Verifying deploy... done.
To https://git.heroku.com/dry-badlands-86959.git
   4c72ab1..eb0ff52  main -> main

$ h run erb --version
...
2.2.3

$ curl https://dry-badlands-86959.herokuapp.com/hello.txt
hello

@edmorley edmorley marked this pull request as ready for review June 20, 2022 22:00
@edmorley
Copy link
Member Author

edmorley commented Jun 20, 2022

In terms of impact on slug size, the uncompressed size of the Ruby install is 48MB:

$ h run -- du -sh .heroku-buildpack-nginx/ruby
...
48M	.heroku-buildpack-nginx/ruby

However the 500MB slug size limit applies to the compressed size, for which the increase is only 20.9 MB on Heroku-22:

Before:

remote: -----> Compressing...
remote:        Done: 4.2M

After:

remote: -----> Compressing...
remote:        Done: 25.1M

These slug size increases seem very acceptable, in return for the benefits of no longer having Ruby in the stack image - for which there are more details in:
heroku/base-images#209 (comment)

@edmorley
Copy link
Member Author

And confirmed the vendored Ruby isn't installed on stacks where system Ruby is present:

remote: -----> Building on the Heroku-20 stack
remote: -----> Using buildpack: https://github.com/heroku/heroku-buildpack-nginx#edmorley/vendor-ruby-if-needed
remote: -----> nginx-buildpack app detected
remote: ./
remote: ./nginx
remote: ./mime.types
remote: ./nginx-debug
remote: -----> nginx-buildpack: Installed nginx/1.20.2 to app/bin
remote: -----> nginx-buildpack: Added start-nginx to app/bin
remote: -----> nginx-buildpack: Added start-nginx-debug to app/bin
remote: -----> nginx-buildpack: Added start-nginx-solo to app/bin
remote: -----> nginx-buildpack: Default mime.types copied to app/config/
remote: -----> nginx-buildpack: Custom config found in app/config.
remote: -----> Discovering process types
remote:
remote: -----> Compressing...
remote:        Done: 5.2M

@edmorley edmorley merged commit 760407b into main Jun 21, 2022
@edmorley edmorley deleted the edmorley/vendor-ruby-if-needed branch June 21, 2022 09:56
@edmorley
Copy link
Member Author

Published:

$ h buildpacks:publish heroku-community/nginx v1.9
Publishing buildpack heroku-community/nginx... done
Publishing buildpack was successful

$ h buildpacks:versions heroku-community/nginx | head -n4
Version  Released At               Status
───────  ────────────────────────  ─────────
11       2022-06-21T09:57:43.472Z  published
10       2022-05-19T09:33:50.285Z  published

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

Successfully merging this pull request may close these issues.

App fails to start on Heroku-22 stack due to lack of erb executable
2 participants