Gitlab CI/CD Job fails when installing Bundler - ruby-on-rails

I want to run the tests after every commit. When installing the bundler, however, the following error message appears: "You must use Bundler 2 or greater with this lockfile" although I install version 2.2.5
stages:
- test
test-job:
stage: test
image: ruby:2.5.1
script:
- gem install bundler -v 2.2.5
- bundle install
- bundle exec rails test

bundler 1.16.6 is included in ruby:2.5.1 and is used per default as you can see here:
$ gem list bundler
bundler (2.2.5, 1.16.6, default: 1.16.2)
Try this instead:
test-job:
stage: test
image: ruby:2.5.1
before_script:
- gem update --system
script:
- bundle install
- bundle exec rails test

Related

bundler: Using a custom path while using system gems is unsupported

I am using GitLab-CI/CD to build my Rails application. I have noticed my builds are failing due to Using a custom path while using system gems is unsupported error, which were working perfectly fine before.
Tried to check newer update releases but didn't find any issues. Does any one have any idea on recent updates or somthing on mentioned issue?
Bellow is my gitlab-ci.yml
variables:
GIT_SUBMODULE_STRATEGY: recursive
cache:
key: ${CI_JOB_NAME}
paths:
- vendor/ruby
before_script:
- apt-get update -qq
- ruby -v
- which ruby
- gem --version
- git --version
- gem update --system 2.7.6
- gem install bundler -v 2.0.1
- bundle -v
- bundle config ${REPO_URL} ${BUNDLE_GITLAB__TOKEN}
- bundle config --global disable_shared_gems true
- bundle install --jobs $(nproc) "${FLAGS[#]}" --path vendor
rubocop:
tags:
- rubocop
script:
- bundle exec rubocop
# rspec:
# stage: test
# script:
# - bundle exec rspec
And bellow is the brief error I'm getting
$ apt-get update -qq
$ ruby -v
ruby 2.5.5p157 (2019-03-15 revision 67260) [x86_64-linux]
$ which ruby
/usr/local/bin/ruby
$ gem --version
3.0.3
$ git --version
git version 2.20.1
$ gem update --system 2.7.6
Updating rubygems-update
Successfully installed rubygems-update-2.7.6
Installing RubyGems 2.7.6
Bundler 1.16.1 installed
RubyGems 2.7.6 installed
Regenerating binstubs
------------------------------------------------------------------------------
RubyGems installed the following executables:
/usr/local/bin/gem
/usr/local/bin/bundle
RubyGems system software updated
$ gem install bundler -v 2.0.1
Successfully installed bundler-2.0.1
1 gem installed
$ bundle -v
Bundler version 2.0.1
$ bundle config https://gitlab.com/dharshannn/test-star.git ${BUNDLE_GITLAB__TOKEN}
$ bundle config --global disable_shared_gems true
$ bundle install --jobs $(nproc) "${FLAGS[#]}" --path vendor
Using a custom path while using system gems is unsupported.
path:
Set for your local app (/usr/local/bundle/config): "vendor"
path.system:
Set via BUNDLE_PATH__SYSTEM: true
disable_shared_gems:
Set for the current user (/root/.bundle/config): true
ERROR: Job failed: exit code 1
The same happened to me today. I am pretty sure that there was no update to bundler or gem. The Docker image however has been updated (I was using ruby:2.6.3). I also added a new dependency when this started happening, so I suspect it was dependent on a gem which was already installed in the system path thus the error message.
You can get around it by specifying the following configuration variables in your .gitlab-ci.yml:
variables:
BUNDLE_DISABLE_SHARED_GEMS: "true"
BUNDLE_PATH__SYSTEM: "false"
This will configure Bundler to not use shared gems and disable system gems fully.
See https://bundler.io/v2.0/bundle_config.html
disable_shared_gems (BUNDLE_DISABLE_SHARED_GEMS): Stop Bundler from accessing gems installed to RubyGems' normal location.
and
path.system (BUNDLE_PATH__SYSTEM): Whether Bundler will install gems into the default system path (Gem.dir).

You must use Bundler 2 or greater with this lockfile. When running docker-compose up locally

New to docker, I have been trying to use it with my rails project but haven't been able to start it up.
Tried changing ruby versions, and searching the web, but most questions involved deploying the app to heroku, which is not my case.
Docker file:
FROM ruby:2.4.1
RUN mkdir /zssn
WORKDIR /zssn
COPY Gemfile /zssn/Gemfile
COPY Gemfile.lock /zssn/Gemfile.lock
RUN gem install bundler
RUN bundle --version
RUN bundle install
COPY . /zssn
CMD ["rails", "server"]
docker-compose-yml
version: '3'
services:
web:
build: .
command: rails s -p 3000 -b '0.0.0.0'
volumes:
- .:/zssn
ports:
- "3000:3000"
docker build . --no-cache, seems to be working fine when running the bundler command to install it.
---> Running in d4650608f428
Successfully installed bundler-2.0.1
Any ideas?
Adding this line before RUN bundle install to the Dockerfile did the trick for me.
RUN gem install bundler -v 2.0.1
Leaving this here for future reference!
You need to update Rubygems:
RUN gem update --system
Apart of being sure that you have the correct bundler version, run:
RUN gem install bundler -v 2.0.1
Here you can find a deeply explanation.
Ruby image comes with installed bundler.
Environment variable BUNDLER_VERSION is set to preinstalled version of bundler by default. Even if you uninstall this version, bundle will check for this environment variable and
raise error "You must use Bundler 2 or greater with this lockfile" if there is a v1/v2 mismatch
Ensure that your Gemfile.lock bundled with needed version:
BUNDLED WITH
2.1.4
If you have another version, you can upgrade your application to the latest installed version of Bundler by running bundle update --bundler https://bundler.io/man/bundle-update.1.html
In Dockerfile override environment variable BUNDLER_VERSION to needed version of bundler and install it:
ENV BUNDLER_VERSION=2.1.4
RUN gem update --system && \
gem install bundler:2.1.4 && \
bundle install
in your Gemfile.lock, at the bottom, you may find bundle version:
BUNDLED WITH
2.0.1
Please make sure you bundled it with the correct version that you have
I think you need to either upgrade to a ruby image that comes with bundler 2 (e.g. FROM ruby:2.6.3) or rebundle your Gemfile.lock with the bundler version you want to use. Or at least that's what worked for me.
It did not work to tweak the environment variables as suggested by the Bundler guides.
This github issue makes me think this is expected behavior, but I could be totally wrong.

Bitbucket Pipelines - Failed to build gem native extension

Am I missing build tools in my configuration file?
I'm trying to integrate Bitbucket Pipelines with a Ruby project.
I am unable to build native gem extensions. My C knowledge is limited. If anyone has experience with this input is appreciated. The build fails where trying to install faraday
Installing faraday 0.9.2
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.
...
Makefile:241: recipe for target 'fast.o' failed
make: *** [fast.o] Error 1
make failed, exit code 2
My bitbucket-piplines.yml looks like
image: ruby:2.4.0
pipelines:
default:
- step:
caches:
- bundler
script:
- echo $PRIVATE_KEY > ~/.ssh/id_rsa.tmp
- base64 -d ~/.ssh/id_rsa.tmp > ~/.ssh/id_rsa
- chmod 600 ~/.ssh/id_rsa
- base64 ~/.ssh/id_rsa
- gem install oj -v '2.9.9'
- gem install faraday -v '0.9.2'
- bundle config git.allow_insecure true
- bundle install
- bundle exec rspec
definitions:
caches:
bundler: ./vendor
So it was an issue with my Ruby version. Fixnum is no longer a function in Ruby 2.4. It was a matter of downgrading the Ruby Docker image, or updating the failing gems. I downgraded while I'm getting my tests set up to image: ruby:2.3.4

GitLab Hosted Ruby Version Issue

I'm testing out a simple Rails project with hosted GitLab. My repository has Ruby version 2.3.0 and Rails version 5.0.1. I created the basic gitlab-ci.yml file with the below code for CI. When GitLab goes to run this file through the pipeline to add it I get the error:
activesupport-5.0.1 requires ruby version >= 2.2.2, which is incompatible with
the current version, ruby 2.1.10p492
I'm not sure how to change the version of Ruby that GitLab is using. Any suggestions on how to resolve this issue?
gitlab-ci.yml
before_script:
- apt-get update -qq && apt-get install -y -qq sqlite3 libsqlite3-dev nodejs
- ruby -v
- which ruby
- gem install bundler --no-ri --no-rdoc
- bundle install --jobs $(nproc) "${FLAGS[#]}"
rspec:
script:
- bundle exec rspec
rubocop:
script:
- bundle exec rubocop
You define the environment in which the code is run by using a Docker image.
Try adding
image: ruby:2.3.0
to the top of your .gitlab-ci.yml file

Travis CI Ruby Version conflict

I'm currently trying to use TravisCI properly for my rails app but I'm a bit stuck with the problem I'm facing.
In my .travis.yml
I've got this :
language: ruby
before_install:
- gem install bundler
rvm:
- 2.0.0
env:
- DB=sqlite
- DB=mysql
- DB=postgresql
script:
- rake db:migrate
- rake db:test:prepare
And in my Gemfile I precise Ruby version : ruby "2.0.0"
With this .travis.yml the tests fails saying to me :
$ gem --version
2.0.3
$ bundle install --deployment
Your Ruby version is 1.9.3, but your Gemfile specified 2.0.0
But when I modify my .travis.yml like this :
language: ruby
before_install:
- gem install bundler
rvm:
- 1.9.3
- 2.0.0
env:
- DB=sqlite
- DB=mysql
- DB=postgresql
script:
- rake db:migrate
- rake db:test:prepare
Travis CI runs the test twice (once for 1.9.3 version and once for 2.0.0 version)
and fails with 1.9.3 version and succeed with 2.0.0 version.
What am I doing wrong in order to just pass the test with 2.0.0 ruby version ?
Cordially rob
I found what was wrong, TravisCI was looking for a .travis.yml in each branch but I only had one in my master branch (I thought TravisCI was only checking master branch).
I added a .travis.yml and all was ok.
I had a similar issue with the same error message even though my .travis.yml was included. The solution that worked for me was to include the generated Gemfile.lock in the repo as well.

Resources