Skip to content

Bundle install reuses layer even when bundle-respected env vars should change app image setup #111

@fg-j

Description

@fg-j

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

  1. Clone this sample app
  2. Change the Gemfile to contain:
source 'https://rubygems.org'

ruby '~> 2.0'

group :test do
  gem 'rspec'
end

gem 'puma'
gem 'sinatra'
  1. Run bundle locally to generate a Gemfile.lock.
  2. 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
  1. 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
  1. 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]
  1. 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:

  • I have included log output.
  • The log output includes an error message.
  • I have included steps for reproduction.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions