Executing a rake tasks in gitlab folder from GDK fails due to Bundler environment not being cleared up
The following discussion from !3475 (merged) should be addressed:
-
@brodock started a discussion: (+1 comment) @dbalexandre I've tried this on local machine, this is the result I got from running
rake gitlab-db-migrate
first:rake gitlab-db-migrate 677ms 18:23:09 -------------------------------------------------------------------------------- Processing gitlab rails DB migrations -------------------------------------------------------------------------------- rake aborted! LoadError: cannot load such file -- bootsnap/setup <internal:/Users/brodock/.rvm/rubies/ruby-3.1.4/lib/ruby/site_ruby/3.1.0/rubygems/core_ext/kernel_require.rb>:38:in `require' <internal:/Users/brodock/.rvm/rubies/ruby-3.1.4/lib/ruby/site_ruby/3.1.0/rubygems/core_ext/kernel_require.rb>:38:in `require' /Users/brodock/Projetos/Gitlab/gdk-dev/gitlab/config/boot.rb:6:in `<top (required)>' /Users/brodock/Projetos/Gitlab/gdk-dev/gitlab/config/application.rb:2:in `require_relative' /Users/brodock/Projetos/Gitlab/gdk-dev/gitlab/config/application.rb:2:in `<top (required)>' <internal:/Users/brodock/.rvm/rubies/ruby-3.1.4/lib/ruby/site_ruby/3.1.0/rubygems/core_ext/kernel_require.rb>:38:in `require' <internal:/Users/brodock/.rvm/rubies/ruby-3.1.4/lib/ruby/site_ruby/3.1.0/rubygems/core_ext/kernel_require.rb>:38:in `require' /Users/brodock/Projetos/Gitlab/gdk-dev/gitlab/Rakefile:9:in `<top (required)>' /Users/brodock/.rvm/gems/ruby-3.1.4/gems/rake-13.1.0/exe/rake:27:in `<top (required)>' /Users/brodock/.rvm/gems/ruby-3.1.4/bin/ruby_executable_hooks:22:in `eval' /Users/brodock/.rvm/gems/ruby-3.1.4/bin/ruby_executable_hooks:22:in `<main>'
after investigating it a bit, I found out that (because I'm not using
asdf
and therefore the command is not usingasdf exec
, bundler was not getting its environment cleared up.this is what's in
bundler exec --help
documentation:Shelling out Any Ruby code that opens a subshell (like system, backticks, or %x{}) will automatically use the current Bundler environment. If you need to shell out to a Ruby command that is not part of your current bundle, use the with_unbundled_env method with a block. Any subshells created inside the block will be given the environment present before Bundler was activated. For example, Homebrew commands run Ruby, but don´t work inside a bundle:
Bundler.with_unbundled_env do `brew install wget` end Using with_unbundled_env is also necessary if you are shelling out to a different bundle. Any Bundler commands run in a subshell will inherit the current Gemfile, so commands that need to run in the context of a different bundle also need to use with_unbundled_env. Bundler.with_unbundled_env do Dir.chdir "/other/bundler/project" do `bundle exec ./script` end end Bundler provides convenience helpers that wrap system and exec, and they can be used like this:
So I think we need to patch this as well.