GitLab Hosted Ruby Version Issue - ruby-on-rails

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

Related

Gitlab CI/CD Job fails when installing Bundler

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

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.

Cucumber on Travis CI container

I am trying to get Cucumber to run tests on my builds on Travis CI with following minimal .travis.yml:
language: ruby
sudo: required
services: docker
before_install:
- sudo apt-get update -qq
- sudo apt-get install -qq cucumber
script:
- cucumber --version
But the build fails with
/usr/local/rvm/rubies/ruby-2.2.3/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require': cannot load such file -- cucumber/rspec/disable_option_parser (LoadError)
from /usr/local/rvm/rubies/ruby-2.2.3/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require'
from /usr/bin/cucumber:10:in `<main>'
Do I need to install other packages than cucumber?
It seems all the packages are being installed, the problem here I think is that sudo apt-get install -qq cucumber installed ruby 1.9.3 and then cucumber (check the log), calling cucumber tries to execute using ruby 2.2 (travis default)
Maybe you should stick to using bundler or rake to install the cuke.

Travis build fails in Yeoman Angular generated app

I'm not being able to build an angular application generated with Yeoman using angular-generator. It fails when uses compass gem. I've already added the compass gem installation to the build descriptor.
This is my .travis.yml file:
language: node_js
node_js:
- '0.8'
- '0.10'
before_script:
- 'gem update --system'
- 'gem install compass'
- 'npm install -g bower grunt-cli'
- 'bower install'
The error I'm getting is the following:
Warning: /home/travis/.rvm/rubies/ruby-1.9.3-p484/lib/ruby/site_ruby/1.9.1/rubygems/core_ext/kernel_require.rb:55:in `require': cannot load such file -- sass/script/node (LoadError)
I solved similar problem following this link.
In short, I put the following versions in the .travis.yml file:
'gem install sass --version "=3.2.12"'
'gem install compass --version "=0.12.2"'

Resources