What happened?
Please provide some details about the task you are trying to accomplish and
what went wrong.
We were trying to use some build-time configuration that the bundle tool natively respects to change the contents of the built app image. In particular, we wanted to take advantage of the BUNDLE_WITHOUT environment variable to exclude certain gems from the built app image. Rather than rebuilding the gems layer, the buildpack reused the cached version of the layer. The resulting app image included gems we didn't want in our image.
Reproduction steps
- Clone this sample app
- Change the Gemfile to contain:
source 'https://rubygems.org'
ruby '~> 2.0'
group :test do
gem 'rspec'
end
gem 'puma'
gem 'sinatra'
- Run
bundle locally to generate a Gemfile.lock.
- Build the app with all of its gems:
pack build exclude-gems --builder paketobuildpacks/builder:0.1.20-base --buildpack gcr.io/paketo-buildpacks/ruby:0.1.5 --clear-cache
- Hop into the built app and see that the
rspec gem is present:
docker run -it --entrypoint=launcher exclude-gems /bin/bash
cnb@fa0d8cb9967f:/workspace$ ls /layers/paketo-buildpacks_bundle-install/gems/ruby/2.7.0/gems/
diff-lcs-1.4.4 nio4r-2.5.4 rack-2.2.3 rspec-3.10.0 rspec-expectations-3.10.0 rspec-support-3.10.0 sinatra-2.1.0
mustermann-1.1.1 puma-5.0.4 rack-protection-2.1.0 rspec-core-3.10.0 rspec-mocks-3.10.0 ruby2_keywords-0.0.2 tilt-2.0.10
- Rebuild the app with the
BUNDLE_WITHOUT env var to exclude the test group:
pack build exclude-gems --builder paketobuildpacks/builder:0.1.20-base --buildpack gcr.io/paketo-buildpacks/ruby:0.1.5 --env BUNDLE_WITHOUT=test
The output should contain:
[builder] Paketo Bundle Install Buildpack 0.1.0
[builder] Reusing cached layer /layers/paketo-buildpacks_bundle-install/gems
[builder]
- Hop into the app container again and see that
rspec is still present in the app container
docker run -it --entrypoint=launcher exclude-gems /bin/bash
cnb@546bd3d68aea:/workspace$ ls /layers/paketo-buildpacks_bundle-install/gems/ruby/2.7.0/gems/
diff-lcs-1.4.4 nio4r-2.5.4 rack-2.2.3 rspec-3.10.0 rspec-expectations-3.10.0 rspec-support-3.10.0 sinatra-2.1.0
mustermann-1.1.1 puma-5.0.4 rack-protection-2.1.0 rspec-core-3.10.0 rspec-mocks-3.10.0 ruby2_keywords-0.0.2 tilt-2.0.10
The buildpack should rebuild the gems layer in a way that respects this native configuration.
Notably, running
pack build exclude-gems --builder paketobuildpacks/builder:0.1.20-base --buildpack gcr.io/paketo-buildpacks/ruby:0.1.5 --env BUNDLE_WITHOUT=test --clear-cache
produces the desired result, where rspec gems are not present.
Checklist
Please confirm the following:
What happened?
Please provide some details about the task you are trying to accomplish and
what went wrong.
We were trying to use some build-time configuration that the bundle tool natively respects to change the contents of the built app image. In particular, we wanted to take advantage of the
BUNDLE_WITHOUTenvironment variable to exclude certain gems from the built app image. Rather than rebuilding the gems layer, the buildpack reused the cached version of the layer. The resulting app image included gems we didn't want in our image.Reproduction steps
bundlelocally to generate aGemfile.lock.rspecgem is present:BUNDLE_WITHOUTenv var to exclude thetestgroup:The output should contain:
rspecis still present in the app containerThe buildpack should rebuild the gems layer in a way that respects this native configuration.
Notably, running
produces the desired result, where rspec gems are not present.
Checklist
Please confirm the following: