How to change the version of bundler used in Cloud Functions deployment? - ruby

Context
Deployments to Cloud Functions have been failing since a few days ago.
Gemfile
source "https://rubygems.org"
ruby "~> 2.7.0"
git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
gem "google-cloud-firestore"
Deployment script
$ gcloud functions deploy my_func --region=us-central1 --memory=128MB --runtime=ruby27
(snip)
ERROR: (gcloud.functions.deploy) OperationError: code=3, message=Build failed: Fetching gem metadata from https://rubygems.org/..........
Resolving dependencies...
Bundler found conflicting requirements for the Ruby version:
In Gemfile:
Ruby (~> 2.7.0)
google-cloud-firestore was resolved to 2.4.1, which depends on
google-cloud-firestore-v1 (~> 0.0) was resolved to 0.4.0, which depends on
gapic-common (~> 0.3) was resolved to 0.4.0, which depends on
google-protobuf (~> 3.15, >= 3.15.2) was resolved to 3.15.5, which
depends on
Ruby (< 3.1.dev, >= 2.3)
google-cloud-firestore was resolved to 2.4.1, which depends on
google-cloud-firestore-v1 (~> 0.0) was resolved to 0.4.0, which depends on
gapic-common (~> 0.3) was resolved to 0.4.0, which depends on
grpc (~> 1.36) was resolved to 1.36.0, which depends on
Ruby (< 3.1.dev, >= 2.4); Error ID: af32a539
Why?
This is bundler's regression since bundler v2.2.8.
https://github.com/rubygems/rubygems/issues/4366
And this is fixed at bundler v2.2.10
https://github.com/rubygems/rubygems/blob/master/bundler/CHANGELOG.md#2210-february-15-2021
https://github.com/rubygems/rubygems/pull/4371
So I want the bundler version to be less than v2.2.8 or more than v2.2.10.
Cloud Functions deployment ( gcloud functions deploy ) automatically runs bundle install and uses bundler which installed in deployment task.
Current bundler version in deployment task is v2.2.9
Verification code
Gemfile
source "https://rubygems.org"
ruby "~> 2.7.0"
git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
gem "bundler", "!= 2.2.8", "!= 2.2.9"
Deployment script
$ gcloud functions deploy my_func --region=us-central1 --memory=128MB --runtime=ruby27
(snip)
Resolving dependencies...
Bundler could not find compatible versions for gem "bundler":
In Gemfile:
bundler (!= 2.2.8, != 2.2.9)
Current Bundler version:
bundler (2.2.9)
Main subject
gcloud functions deploy doesn't have some arguments to change bundler version...
https://cloud.google.com/sdk/gcloud/reference/functions/deploy?hl=ja
How to change the version of bundler used in Cloud Functions deployment?

I ran into a similar issue as well, however the error output was slightly different. One thing in common was the line:
Bundler found conflicting requirements for the Ruby version:
After doing some digging and troubleshooting, I found that Google Cloud Functions locks the bundled platform on our behalf. I'm not a ruby expert, but I suspect this will impact how information from the Gemfile will be read along with the Ruby version.
Example Log from Google Cloud Functions:
2021-03-10 13:13:01.764 PST
Step #4 - "builder": Done "bundle lock --add-platform x86_64-linux"
Solution:
Update bundler locally (I updated to 2.2.14). Delete your Gemfile.lock file and rerun bundle install to generate Gemfile.lock. This should fix dependencies if there is anything to fix.
Most importantly, it will update the Platforms section in your Gemfile.lock to match what Google expects.
In my case, the platform was updated from Ruby to x86_64-darwin-19.
Or the other approach may be to just update the platform with bundle if possible.

Eventually I have successfully deployed with followings.
gem install bundler --no-doc
Delete Gemfile.lock
re-create Gemfile.lock ( bundle install )
diff
$ git --no-pager diff main
diff --git a/Gemfile.lock b/Gemfile.lock
index 5e7502b..b5642ab 100644
--- a/Gemfile.lock
+++ b/Gemfile.lock
## -57,7 +57,6 ## GEM
gapic-common (~> 0.3)
google-cloud-errors (~> 1.0)
grpc-google-iam-v1 (>= 0.6.10, < 2.0)
- google-protobuf (3.15.5)
google-protobuf (3.15.5-universal-darwin)
googleapis-common-protos (1.3.11)
google-protobuf (~> 3.14)
## -72,9 +71,6 ## GEM
multi_json (~> 1.11)
os (>= 0.9, < 2.0)
signet (~> 0.14)
- grpc (1.36.0)
- google-protobuf (~> 3.14)
- googleapis-common-protos-types (~> 1.0)
grpc (1.36.0-universal-darwin)
google-protobuf (~> 3.14)
googleapis-common-protos-types (~> 1.0)
## -160,7 +156,6 ## GEM
PLATFORMS
ruby
- x86_64-darwin-17
DEPENDENCIES
dotenv
## -180,4 +175,4 ## RUBY VERSION
ruby 2.7.2p137
BUNDLED WITH
- 2.1.4
+ 2.2.14

Related

I am not able to install any new gem in my rails application.Its a issue related to bundler

Bundler could not find compatible versions for gem "bundler":
In Gemfile:
rails (~> 5.2) was resolved to 5.2.3, which depends on
bundler (>= 1.3.0)
solargraph was resolved to 0.38.0, which depends on
bundler (>= 1.17.2)
Current Bundler version:
bundler (1.16.2)
This Gemfile requires a different version of Bundler.
Perhaps you need to update Bundler by running `gem install bundler`?
Could not find gem 'bundler (>= 1.17.2)', which is required by gem 'rails (~> 5.2)', in any of the sources.
ERROR: 6
I am using ruby version 2.5.1 on my device and rvm is not installed earlier the version of ruby 3.0.2 but our project is of version 2.5.1. But while installing any new gem and hitting bundle install it shows this particular error
sudo docker-compose run --rm --no-deps web bundle install

Gem::InstallError: nokogiri requires Ruby version < 2.7.dev, >= 2.3 on Pentestbox

when I try to run metasploit on pentestbox last version I get the below error
could not find compatible versions for gem "activesupport": In snapshot (Gemfile.lock): activesupport (= 4.2.11) In Gemfile: metasploit-framework x86-mingw32 was resolved to 5.0.5, which depends on activerecord (~> 4.2.6) x86-mingw32 was resolved to 4.2.10, which depends on activesupport (= 4.2.10) x86-mingw32 rspec-rails x86-mingw32 was resolved to 3.8.2, which depends on railties (>= 3.0) was resolved to 4.2.11, which depends on activesupport (= 4.2.11) x86-mingw32 Running bundle update will rebuild your snapshot from scratch, using only the gems in your Gemfile, which may resolve the conflict.
I tried running the command "bundle update", but got this error
Fetching nokogiri 1.10.1 (x86-mingw32) Installing nokogiri 1.10.1 (x86-mingw32) Gem::InstallError: nokogiri requires Ruby version < 2.7.dev, >= 2.3. An error occurred while installing nokogiri (1.10.1), and Bundler cannot continue. Make sure that gem install nokogiri -v '1.10.1' succeeds before bundling
after that I try run command "bundle install" I get same Error
I also got the same error in my Windows 10 and I was able to install the nokogori successfully. Below is my Ruby environment.
RubyGems Environment:
- RUBYGEMS VERSION: 2.4.5
- RUBY VERSION: 2.2.2 (2015-04-13 patchlevel 95) [x64-mingw32]
- INSTALLATION DIRECTORY: C:/Ruby222-x64/lib/ruby/gems/2.2.0
- RUBY EXECUTABLE: C:/Ruby222-x64/bin/ruby.exe
- EXECUTABLE DIRECTORY: C:/Ruby222-x64/bin
- SYSTEM CONFIGURATION DIRECTORY: C:/ProgramData
- RUBYGEMS PLATFORMS:
- ruby
- x64-mingw32
- GEM PATHS:
- C:/Ruby222-x64/lib/ruby/gems/2.2.0
To solved the issue I just updated my Gemfile. I added this line:
gem 'nokogiri', '~> 1.6.8'
I am using Windows 10, I installed nokogiri prerelease version in which this is fixed.
gem inst nokogiri --pre
Then I changed the dependency in the gemfile.lock file:
nokogiri (1.11.0.rc2-x64-mingw32)
Reference:
https://github.com/sparklemotion/nokogiri/issues/1961

Bundler could not find compatible versions for gem even if I change versions

I am trying to update to the latest google vision, and so I add in Gemfile:
gem 'google-cloud-vision', '~> 0.28.0'
But when I run bundle install, I get the following error:
Bundler could not find compatible versions for gem "faraday": In
Gemfile:
google-cloud-vision (~> 0.28.0) ruby depends on
google-cloud-core (~> 1.2) ruby depends on
google-cloud-env (~> 1.0) ruby depends on
faraday (~> 0.11) ruby
forecast_io (>= 0) ruby depends on
faraday (0.9.2)
I tried using the latest version of forecast too:
gem 'forecast_io', '~> 2.0', '>= 2.0.2'
I understand that two different gems require two different versions of faraday. But isn't bundler supposed to resolve this?
According to bundler documentation
Update the gems specified (all gems, if none are specified), ignoring the previously installed gems specified in the Gemfile.lock. In general, you should use bundle install(1) to install the same exact gems and versions across machines.
You would use bundle update to explicitly update the version of a gem.
So use bundle update google-cloud-vision for update gem to new version.

How to install newest version of gems not mentioned in Gemfile.lock with bundler

When I add a gem to a project's Gemfile for the first time, but I have installed the gem previously while working on another project, it uses the existing version of the gem, rather than the latest version of the gem available.
For example, using bundler version 1.11.2, I added gem 'rubocop' to a project's Gemfile, and running bundle install resulted in it using RuboCop version 0.42.0, rather than the current (as of 21 October 2016) version of 0.44.1:
rubocop (0.42.0)
parser (>= 2.3.1.1, < 3.0)
powerpack (~> 0.1)
rainbow (>= 1.99.1, < 3.0)
ruby-progressbar (~> 1.7)
unicode-display_width (~> 1.0, >= 1.0.1)
Running bundle update rubocop resulted in version 0.44.1 being used, without any pre-existing gems having their version changed. This indicates there weren't any constraints shopping me from using RuboCop version 0.44.1.
rubocop (0.44.1)
parser (>= 2.3.1.1, < 3.0)
powerpack (~> 0.1)
rainbow (>= 1.99.1, < 3.0)
ruby-progressbar (~> 1.7)
unicode-display_width (~> 1.0, >= 1.0.1)
When running bundle install, how can I tell it, for gems that aren't mentioned in Gemfile.lock, to download the newest compatible version of the gem, rather than use an older version which happens to be available on the local machine?
I tried looking at http://bundler.io/v1.13/man/bundle-install.1.html but nothing there seemed to be relevant.
If you want to have newest version gem, remove version in Gemfile and run bundle install again.

Dependency Error in Ruby

I am trying to install a Gem named spiceweasel (https://github.com/mattray/spiceweasel). When running it I get the following error:
$ sudo gem install spiceweasel
ERROR: While executing gem ... (Gem::DependencyError)
Unable to resolve dependencies: ridley requires buff-extensions (~> 0.3); buff-config requires buff-extensions (~> 0.3); varia_model requires buff-extensions (~> 1.0)
Is there a way to circumvent this?
Looks like you have a conflict in your dependencies:
ridley requires buff-extensions (~> 0.3)
varia_model requires buff-extensions (~> 1.0)
Ie: two gems depends on conflicting versions of a third one ("~>" in Bundler means that another minor version is correct, but not a major one).
What you can do:
If your project does not require both ridley & varia_model, you may use RVM to create a specific Gemset for it.
Update ridley (the newest version is also using buff-extension 1.0).
Install the buff-extensions gem. It's currently at version 1.0, which should satisfy all of the other items that have dependencies on it.

Resources