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

Attempt to install bundler fails #216

Open
JasonLunn opened this issue Mar 2, 2025 · 6 comments
Open

Attempt to install bundler fails #216

JasonLunn opened this issue Mar 2, 2025 · 6 comments

Comments

@JasonLunn
Copy link

JasonLunn commented Mar 2, 2025

I have a CI system that runs Ruby tests via bazel inside a docker image, with a dedicated image per bazel version + ruby version that we support.

The docker image is built with the desired bazel version, and ruby is installed via RVM at docker image build time along with the version of bundler we use to generate our Gemfile.lock.

The following error is observed in the PR where I'm attempting to adopt rules_ruby, which indicates that rules_ruby is trying to install bundler-2.4.22 despite it being installed already. It fails, presumably because of bazel sandbox rules.

Is there something I need to do differently to prevent rules_ruby from attempting the installation? Does gem installation ever work when using the system version and if not, should disabling automatic installation of bundler be disabled in this configuration?

ERROR: /workspace/_build/out/external/protobuf_bundle/BUILD:84:15: Installing external/protobuf_bundle/vendor/cache/bundler-2.4.22.gem (@@protobuf_bundle//:bundler-2.4.22) failed: (Exit 1): gem_install_bundler-2.4.22.sh failed: error executing GemInstall command (from target @@protobuf_bundle//:bundler-2.4.22) 
  (cd /workspace/_build/out/sandbox/processwrapper-sandbox/626/execroot/_main && \
  exec env - \
    PATH=/usr/local/rvm/gems/ruby-3.4.1/bin:/usr/local/rvm/gems/ruby-3.4.1@global/bin:/usr/local/rvm/rubies/ruby-3.4.1/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/root/.dotnet/tools:/usr/local/rvm/bin \
  bazel-out/k8-fastbuild/bin/external/protobuf_bundle/gem_install_bundler-2.4.22.sh)
# Configuration: f06f54974fe4ae3926ed7f4362850e99b3c3835650485ceb0f9cae2f7f580429
# Execution platform: @@local_config_platform//:host

Use --sandbox_debug to see verbose messages from the sandbox and retain the sandbox build root for debugging
ERROR:  While executing gem ... (Gem::FilePermissionError)
    You don't have write permissions for the /usr/local/rvm/rubies/ruby-3.4.1/lib/ruby/gems/3.4.0/wrappers directory.
	/usr/local/rvm/rubies/ruby-3.4.1/lib/ruby/gems/3.4.0/gems/gem-wrappers-1.4.0/lib/gem-wrappers/installer.rb:26:in 'GemWrappers::Installer#ensure'
	/usr/local/rvm/rubies/ruby-3.4.1/lib/ruby/gems/3.4.0/gems/gem-wrappers-1.4.0/lib/gem-wrappers.rb:19:in 'GemWrappers.install'
	/usr/local/rvm/rubies/ruby-3.4.1/lib/ruby/gems/3.4.0/gems/gem-wrappers-1.4.0/lib/rubygems_plugin.rb:15:in 'block in <top (required)>'
	/usr/local/rvm/rubies/ruby-3.4.1/lib/ruby/3.4.0/rubygems/installer.rb:367:in 'block in Gem::Installer#run_post_install_hooks'
	/usr/local/rvm/rubies/ruby-3.4.1/lib/ruby/3.4.0/rubygems/installer.rb:366:in 'Array#each'
	/usr/local/rvm/rubies/ruby-3.4.1/lib/ruby/3.4.0/rubygems/installer.rb:366:in 'Gem::Installer#run_post_install_hooks'
	/usr/local/rvm/rubies/ruby-3.4.1/lib/ruby/3.4.0/rubygems/installer.rb:335:in 'Gem::Installer#install'
	/usr/local/rvm/rubies/ruby-3.4.1/lib/ruby/3.4.0/rubygems/resolver/specification.rb:105:in 'Gem::Resolver::Specification#install'
	/usr/local/rvm/rubies/ruby-3.4.1/lib/ruby/3.4.0/rubygems/request_set.rb:281:in 'block in Gem::RequestSet#install_into'
	/usr/local/rvm/rubies/ruby-3.4.1/lib/ruby/3.4.0/rubygems/request_set.rb:273:in 'Array#each'
	/usr/local/rvm/rubies/ruby-3.4.1/lib/ruby/3.4.0/rubygems/request_set.rb:273:in 'Gem::RequestSet#install_into'
	/usr/local/rvm/rubies/ruby-3.4.1/lib/ruby/3.4.0/rubygems/request_set.rb:148:in 'Gem::RequestSet#install'
	/usr/local/rvm/rubies/ruby-3.4.1/lib/ruby/3.4.0/rubygems/commands/install_command.rb:207:in 'Gem::Commands::InstallCommand#install_gem'
	/usr/local/rvm/rubies/ruby-3.4.1/lib/ruby/3.4.0/rubygems/commands/install_command.rb:223:in 'block in Gem::Commands::InstallCommand#install_gems'
	/usr/local/rvm/rubies/ruby-3.4.1/lib/ruby/3.4.0/rubygems/commands/install_command.rb:216:in 'Array#each'
	/usr/local/rvm/rubies/ruby-3.4.1/lib/ruby/3.4.0/rubygems/commands/install_command.rb:216:in 'Gem::Commands::InstallCommand#install_gems'
	/usr/local/rvm/rubies/ruby-3.4.1/lib/ruby/3.4.0/rubygems/commands/install_command.rb:162:in 'Gem::Commands::InstallCommand#execute'
	/usr/local/rvm/rubies/ruby-3.4.1/lib/ruby/3.4.0/rubygems/command.rb:326:in 'Gem::Command#invoke_with_build_args'
	/usr/local/rvm/rubies/ruby-3.4.1/lib/ruby/3.4.0/rubygems/command_manager.rb:253:in 'Gem::CommandManager#invoke_command'
	/usr/local/rvm/rubies/ruby-3.4.1/lib/ruby/3.4.0/rubygems/command_manager.rb:194:in 'Gem::CommandManager#process_args'
	/usr/local/rvm/rubies/ruby-3.4.1/lib/ruby/3.4.0/rubygems/command_manager.rb:152:in 'Gem::CommandManager#run'
	/usr/local/rvm/rubies/ruby-3.4.1/lib/ruby/3.4.0/rubygems/gem_runner.rb:57:in 'Gem::GemRunner#run'
	external/ruby/dist/bin/gem:12:in '<main>'
@p0deje
Copy link
Member

p0deje commented Mar 3, 2025

Bundler gem installation works under system toolchain, we constantly test this on CI - https://github.com/bazel-contrib/rules_ruby/actions/runs/13546882895/job/37864964054#step:6:62. I am not sure what exactly is happening in your builds, but given the Bundler is already installed in this version, we might want to skip its installation altogether. Can you try disabling it and seeing if bundle install would be passing?

To disable, you could comment out the following piece:

# Fetch Bundler and define an `rb_gem_install()` target for it.
_download_gem(repository_ctx, gemfile_lock.bundler, cache_path, gemfile_lock.bundler.sha256)
gem_full_names.append(":%s" % gemfile_lock.bundler.full_name)
gem_install_fragments.append(
_GEM_INSTALL_BUILD_FRAGMENT.format(
name = gemfile_lock.bundler.full_name,
gem = gemfile_lock.bundler.filename,
cache_path = cache_path,
ruby = ruby_toolchain_attr,
),
)

JasonLunn added a commit to protocolbuffers/protobuf that referenced this issue Mar 4, 2025
@JasonLunn
Copy link
Author

Patching rules_ruby to disable the installation of bundler does seem to have a positive impact.

Instead of the stack trace seen in the description, I need now see:

[1,595 / 1,611] Running bundle install (@protobuf_bundle//:protobuf_bundle); 0s remote-cache, processwrapper-sandbox ... (4 actions, 1 running)
[1,604 / 1,611] Running bundle install (@protobuf_bundle//:protobuf_bundle); 1s remote-cache, processwrapper-sandbox ... (4 actions, 1 running)
[1,610 / 1,611] Running bundle install (@protobuf_bundle//:protobuf_bundle); 3s remote-cache, processwrapper-sandbox
[1,610 / 1,611] Running bundle install (@protobuf_bundle//:protobuf_bundle); 12s remote-cache, processwrapper-sandbox
[1,610 / 1,611] Running bundle install (@protobuf_bundle//:protobuf_bundle); 14s remote-cache, processwrapper-sandbox
[1,610 / 1,611] Running bundle install (@protobuf_bundle//:protobuf_bundle); 15s remote-cache, processwrapper-sandbox
INFO: From Running bundle install (@@protobuf_bundle//:protobuf_bundle):
Installing rake 13.2.1
Installing bigdecimal 3.1.9 with native extensions
Installing ffi 1.17.1 with native extensions
Installing ffi-compiler 1.3.2
Installing power_assert 2.0.5
Installing rake-compiler 1.1.9
Installing rake-compiler-dock 1.2.1
Installing test-unit 3.6.7
Bundle complete! 6 Gemfile dependencies, 10 gems now installed.
Bundled gems are installed into `./bazel-out/k8-fastbuild/bin/external/protobuf_bundle/vendor/bundle`

@p0deje
Copy link
Member

p0deje commented Mar 4, 2025

That's good. Unfortunately, I cannot change bundle_fetch to query Bundler version because the Ruby toolchain is not installed at this stage. I'll see if there is any way to work this around (maybe use --conservative flag in gem install).

@JasonLunn
Copy link
Author

Do you need a Docker file with a similar setup for use in troubleshooting / regression testing?

@p0deje
Copy link
Member

p0deje commented Mar 4, 2025

It would be great if you could share one.

JasonLunn added a commit to protocolbuffers/protobuf that referenced this issue Mar 6, 2025
JasonLunn added a commit to protocolbuffers/protobuf that referenced this issue Mar 6, 2025
JasonLunn added a commit to protocolbuffers/protobuf that referenced this issue Mar 6, 2025
@p0deje
Copy link
Member

p0deje commented Mar 8, 2025

I tried to reproduce the issue locally by grabbing the protobuf repository from main, removing the patch you've added (:Disable_bundle_install.patch) and running some tests in //ruby, but everything looks fine. Please share the Dockerfile or image I could use. If it's impossible, I'll figure out how to skip bundler installation but won't be able to verify the fix.

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

No branches or pull requests

2 participants