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

Bundler original_env.GEM_HOME is incorrect if bundler version is trampolined #7567

Open
shanesmith opened this issue Apr 10, 2024 · 0 comments
Labels

Comments

@shanesmith
Copy link

Describe the problem as clearly as you can

The value for Bundler.original_env['GEM_HOME'] is incorrect in the following scenario:

  • The BUNDLED WITH version found in Gemfile.lock is not installed in the Gem Path
  • The BUNDLE_PATH (or BUNDLE_DEPLOYMENT) is set
  • The script is executed with bundle exec

The impact is that system gems can't be run with Bundle.unbundled_X, which is how the issue was first encountered.

gem install ejson2env
bundle exec ruby -e 'Bundler.unbundled_system("ejson2env")
# [...] can't find gem ejson2env (>= 0.a) with executable ejson2env (Gem::GemNotFoundException)

Did you try upgrading rubygems & bundler?

Yes

Post steps to reproduce the problem

FROM ruby:3.2.2-bullseye

RUN mkdir /app

COPY <<EOF /app/Gemfile
source "https://rubygems.org"
gem "a", "~> 0.2.8"
EOF

COPY <<EOF /app/Gemfile.lock
GEM
  remote: https://rubygems.org/
  specs:
    a (0.2.8)

PLATFORMS
  ruby

DEPENDENCIES
  a (~> 0.2.8)

BUNDLED WITH
   2.4.0
EOF

RUN gem update --system

ENV BUNDLE_PATH '/vendor/bundle'

RUN cd app && bundle install

Which command did you run?

docker build -t foo . && docker run -i foo bash - <<'EOF'
echo -n "system: "
bundle version

cd app

echo -n "app: "
bundle version

echo -n "GEM_HOME: "
echo $GEM_HOME

echo -n "original_env.GEM_HOME: "
bundle exec ruby -e 'puts Bundler.original_env["GEM_HOME"]'
EOF

What were you expecting to happen?

Expected output to be:

system: Bundler version 2.5.7 (2024-03-22 commit 199531f621)
app: Bundler version 2.4.0 (2022-12-24 commit e67004d0fe)
GEM_HOME: /usr/local/bundle
original_env.GEM_HOME: /usr/local/bundle

What actually happened?

Actual output is:

system: Bundler version 2.5.7 (2024-03-22 commit 199531f621)
app: Bundler version 2.4.0 (2022-12-24 commit e67004d0fe)
GEM_HOME: /usr/local/bundle
original_env.GEM_HOME: /vendor/bundle/ruby/3.2.0

Other notes

I know of a couple workarounds, any of these fixes the issue:

  1. Set BUNDLE_VERSION=system
  2. Pre-install the BUNDLED WITH version (ex: gem install bundler:2.4.0)
  3. Use -rbundler/setup instead of bundle exec (ex: ruby -rbundler/setup -e 'puts Bundler.original_env["GEM_HOME"]')

If not included with the output of your command, run bundle env and paste the output below

Environment

Bundler       2.4.0
  Platforms   ruby, aarch64-linux
Ruby          3.2.2p53 (2023-03-30 revision e51014f9c05aa65cbf203442d37fef7c12390015) [aarch64-linux]
  Full Path   /usr/local/bin/ruby
  Config Dir  /usr/local/etc
RubyGems      3.5.7
  Gem Home    /vendor/bundle/ruby/3.2.0
  Gem Path    /vendor/bundle/ruby/3.2.0
  User Home   /root
  User Path   /root/.local/share/gem/ruby/3.2.0
  Bin Dir     /vendor/bundle/ruby/3.2.0/bin
Tools
  Git         2.30.2
  RVM         not installed
  rbenv       not installed
  chruby      not installed

Bundler Build Metadata

Built At          2022-12-24
Git SHA           e67004d0fe
Released Version  true

Bundler settings

app_config
  Set via BUNDLE_APP_CONFIG: "/usr/local/bundle"
path
  Set via BUNDLE_PATH: "/vendor/bundle"
silence_root_warning
  Set via BUNDLE_SILENCE_ROOT_WARNING: true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant