rules_ruby icon indicating copy to clipboard operation
rules_ruby copied to clipboard

Attempt to install bundler fails

Open JasonLunn opened this issue 10 months ago • 6 comments

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>'

JasonLunn avatar Mar 02 '25 18:03 JasonLunn

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: https://github.com/bazel-contrib/rules_ruby/blob/d7cd5d675f42e59a9a9706d00e6896fc918c7eba/ruby/private/bundle_fetch.bzl#L170-L180

p0deje avatar Mar 03 '25 01:03 p0deje

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`

JasonLunn avatar Mar 04 '25 16:03 JasonLunn

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).

p0deje avatar Mar 04 '25 16:03 p0deje

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

JasonLunn avatar Mar 04 '25 16:03 JasonLunn

It would be great if you could share one.

p0deje avatar Mar 04 '25 17:03 p0deje

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.

p0deje avatar Mar 08 '25 02:03 p0deje