Skip to content

Instantly share code, notes, and snippets.

@jaygooby
Last active June 13, 2024 18:24
Show Gist options
  • Save jaygooby/9098d14d1f5d766c0052c40e1c9e9734 to your computer and use it in GitHub Desktop.
Save jaygooby/9098d14d1f5d766c0052c40e1c9e9734 to your computer and use it in GitHub Desktop.
Testing my understanding of how `BUNDLE_DEPLOYMENT` affects `bundle install`

I didn't expect the BUNDLE_DEPLOYMENT=true to override the BUNDLE_WITHOUT=test

It doesn't. If you call bundle list you see the correct list of gems.

docker build --build-arg BUNDLE_WITHOUT="test" --build-arg BUNDLE_DEPLOYMENT=true -t bundle-deployment-bug:env .
docker run --rm -it -e BUNDLE_DEPLOYMENT=true -e BUNDLE_WITHOUT=test bundle-deployment-bug:env

Shows that the pry gem is missing (it's in the development group) but that the minitest gem is present, even though it was set to be skipped by BUNDLE_WITHOUT=test

# syntax = docker/dockerfile:1
FROM registry.docker.com/library/ruby:3.3.1-slim as base
ARG BUNDLE_DEPLOYMENT \
BUNDLE_WITHOUT
ENV BUNDLE_DEPLOYMENT=$BUNDLE_DEPLOYMENT \
BUNDLE_WITHOUT=$BUNDLE_WITHOUT \
BUNDLE_PATH="/usr/local/bundle" \
GEM_PATH="/usr/local/bundle" \
GEM_HOME="/usr/local/bundle"
WORKDIR /rails
FROM base as build
COPY Gemfile Gemfile.lock ./
RUN bundle install && \
rm -rf ~/.bundle/ "${BUNDLE_PATH}"/ruby/*/cache "${BUNDLE_PATH}"/ruby/*/bundler/gems/*/.git
# Copy this directory to the layer
COPY . .
FROM base
COPY --from=build /usr/local/bundle /usr/local/bundle
COPY --from=build /rails /rails
# List the gems the Gemfile specifies
CMD ["bundle", "list"]
source "https://rubygems.org"
ruby "3.3.1"
group :development do
gem "pry"
end
group :test do
gem "minitest"
end
gem "rake"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment