How to use specific bundler version in V2?

I was excited to see the build cache feature, which needs the v2 build system enabled. In v1, the version of bundler is detected from the Gemfile.lock file, but in v2 this seems not to be the case. At https://developers.cloudflare.com/pages/platform/language-support-and-tools/ it shows "Corresponds with Ruby version" for Supported versions, but there aren't any instructions about configuring it. What's the appropriate way to configure the version of bundler?
13:02:37.153 /opt/buildhome/.asdf/installs/ruby/2.6.2/lib/ruby/2.6.0/rubygems.rb:283:in `find_spec_for_exe': Could not find 'bundler' (2.1.4) required by your /opt/buildhome/repo/Gemfile.lock. (Gem::GemNotFoundException)
13:02:37.153 /opt/buildhome/.asdf/installs/ruby/2.6.2/lib/ruby/2.6.0/rubygems.rb:283:in `find_spec_for_exe': Could not find 'bundler' (2.1.4) required by your /opt/buildhome/repo/Gemfile.lock. (Gem::GemNotFoundException)
I have tried updating the version, and using BUNDLER_VERSION env variable, but same result.
15:36:19.526 /opt/buildhome/.asdf/installs/ruby/2.6.2/lib/ruby/2.6.0/rubygems.rb:283:in `find_spec_for_exe': Could not find 'bundler' (2.4.21) required by your /opt/buildhome/repo/Gemfile.lock. (Gem::GemNotFoundException)
15:36:19.526 /opt/buildhome/.asdf/installs/ruby/2.6.2/lib/ruby/2.6.0/rubygems.rb:283:in `find_spec_for_exe': Could not find 'bundler' (2.4.21) required by your /opt/buildhome/repo/Gemfile.lock. (Gem::GemNotFoundException)
16:20:14.985 /opt/buildhome/.asdf/installs/ruby/2.6.2/lib/ruby/2.6.0/rubygems.rb:283:in `find_spec_for_exe': Could not find 'bundler' (2.4.21) required by `$BUNDLER_VERSION`. (Gem::GemNotFoundException)
16:20:14.985 /opt/buildhome/.asdf/installs/ruby/2.6.2/lib/ruby/2.6.0/rubygems.rb:283:in `find_spec_for_exe': Could not find 'bundler' (2.4.21) required by `$BUNDLER_VERSION`. (Gem::GemNotFoundException)
4 Replies
JohnDotAwesome
JohnDotAwesome14mo ago
I'm not super familiar with the ruby/bundler ecosystem - How do projects typically ensure the correct version of bundler is installed? We should probably consider exposing a BUNDLER_VERSION but in the meantime, here's what you can do set a specific bundler version: Add a new environment variable to your project called UNSTABLE_PRE_BUILD with the value:
asdf plugin-add bundler [email protected]:jonathanmorley/asdf-bundler.git && asdf install bundler 2.1.4 && asdf global bundler 2.1.4
asdf plugin-add bundler [email protected]:jonathanmorley/asdf-bundler.git && asdf install bundler 2.1.4 && asdf global bundler 2.1.4
Leon
LeonOP14mo ago
@JohnDotAwesome To be honest I'm not super familiar with the ecosystem either - we are only using it for a couple of sites with jekyll. I can say that our repo build instructions don't include anything special for setting the bundler version, so I assume it's normally picked up automatically. The UNSTABLE_PRE_BUILD suggestion did indeed get the bundler working. Though, then a new problem:
10:41:47.276 Executing user command: jekyll build
10:41:47.671 No preset version installed for command jekyll
10:41:47.671 Please install a version by running one of the following:
10:41:47.671
10:41:47.671 asdf install ruby 2.6.2
10:41:47.672
10:41:47.672 or add one of the following versions in your config file at /opt/buildhome/.tool-versions
10:41:47.681 ruby 3.2.2
10:41:47.683 Failed: Error while executing user command. Exited with error code: 126
10:41:47.695 Failed: build command exited with code: 1
10:41:48.672 Failed: error occurred while running build command
10:41:47.276 Executing user command: jekyll build
10:41:47.671 No preset version installed for command jekyll
10:41:47.671 Please install a version by running one of the following:
10:41:47.671
10:41:47.671 asdf install ruby 2.6.2
10:41:47.672
10:41:47.672 or add one of the following versions in your config file at /opt/buildhome/.tool-versions
10:41:47.681 ruby 3.2.2
10:41:47.683 Failed: Error while executing user command. Exited with error code: 126
10:41:47.695 Failed: build command exited with code: 1
10:41:48.672 Failed: error occurred while running build command
I tried a couple of solutions without success: 1. Add asdf install ruby 2.6.2 && to UNSTABLE_PRE_BUILD 2. Add .tool-versions file to the repo But what did get it working was changing the build command from jekyll build to bundle exec jekyll build Performance with V2 is quite a lot worse than V1. For this site, V1 builds in 1m34s, and V2 5m50s. Now I realise that build caching doesn't yet support Jekyll. Whoops!
JohnDotAwesome
JohnDotAwesome14mo ago
The reason why it's slower for you is it's having to install (build) a custom ruby version. v2 ships with ruby versions 2.7.8 and 3.2.2
Leon
LeonOP14mo ago
Now 1m10s when using v2 with ruby 2.7.8, and the bundler hack is not needed either. You should mention on Language support and tools that 2.7.8 is preinstalled
Want results from more Discord servers?
Add your server