How to install latest Ruby on Gitlab config for Docker - ruby

Here's how my config looks like:
deploy_hybrid:
stage: deploy
before_script:
- apt update -qq
- apt install ruby-full -qq
- gem install cocoapods
- pod repo update
However, it's always installing Ruby 2.1
WARNING: apt does not have a stable CLI interface yet. Use with
caution in scripts. The following extra packages will be installed:
libruby2.1 libtcl8.5 libtcltk-ruby libtk8.5 libxft2 libxss1 ri ruby
ruby-dev ruby2.1 ruby2.1-dev ruby2.1-doc ruby2.1-tcltk
rubygems-integration

Related

Faraday::Connection without adapter has been made. CICD on Gitlab

everything was going well, before this morning, I'm totally new to cicd and things like that so I write this to deploy my app to heroku
`'API deploy':
stage: deploy back
image: ruby:latest
script:
- apt-get update -qy
- apt-get install -y ruby-dev
- gem install dpl
- cd back
- dpl --provider=heroku --app=$HEROKU_BACK --api-key=$HEROKU_API_KEY --skip_cleanup
only:
refs:
- main
changes:
- back/**/*
- .gitlab-ci.yml`
And I receive this:
An attempt to run a request with a Faraday::Connection without adapter has been made. (RuntimeError)
Please set Faraday.default_adapter or provide one when initializing the connection.
I really don't know how to do it and whats going on as I say yesterday all was good.
Update: It's seems due to the current update Faraday-2.0.0
I faced the same problem today. Apparently there is some problem in the latest version of FARADAY, at the moment. I solved it this way: add manual installation of the previous version of the dependency to your .gitlab.yml, and everything will work. Have a nice day.
before_script:
- apt-get update -qy
- apt-get install -y ruby-dev
- gem install dpl
- gem install faraday -v 1.8.0
I add the step below and it works fine
- gem install faraday -v 1.8.0

You don't have write permissions for the /usr/lib/ruby/gems/2.7.0 directory (Alpine linux docker image)

I can not install ruby's gems on alpine docker image. I've tried different approaches from other questions to solve ERROR: While executing gem ... (Gem::FilePermissionError), but there are solutions either for Ubuntu or for Mac OS.
Part of docker file code:
RUN set -ex \
&& apk add --no-cache --update ruby ruby-dev ruby-bundler \
&& gem install --no-document --source https://rubygems.org --version 3.6.6 inspec
OUTPUT:
+ apk add --no-cache --update ruby ruby-dev ruby-bundler
fetch https://dl-cdn.alpinelinux.org/alpine/v3.14/main/x86_64/APKINDEX.tar.gz
fetch https://dl-cdn.alpinelinux.org/alpine/v3.14/community/x86_64/APKINDEX.tar.gz
(1/11) Installing yaml (0.2.5-r0)
(2/11) Installing ruby-libs (2.7.3-r1)
(3/11) Installing ruby (2.7.3-r1)
(4/11) Installing ruby-etc (2.7.3-r1)
(5/11) Installing ruby-io-console (2.7.3-r1)
(6/11) Installing ruby-bundler (2.2.20-r0)
(7/11) Installing libgmpxx (6.2.1-r0)
(8/11) Installing gmp-dev (6.2.1-r0)
(9/11) Installing libucontext (1.1-r0)
(10/11) Installing libucontext-dev (1.1-r0)
(11/11) Installing ruby-dev (2.7.3-r1)
Executing busybox-1.33.1-r2.trigger
Executing glibc-bin-2.33-r0.trigger
/usr/glibc-compat/sbin/ldconfig: /usr/glibc-compat/lib/ld-linux-x86-64.so.2 is not a symbolic link
OK: 1409 MiB in 141 packages
+ gem install --no-document --source https://rubygems.org --version 3.6.6 inspec
ERROR: While executing gem ... (Gem::FilePermissionError)
You don't have write permissions for the /usr/lib/ruby/gems/2.7.0 directory.
The command '/bin/sh -c set -ex && apk add --no-cache --update ruby ruby-dev ruby-bundler && gem install --no-document --source https://rubygems.org --version 3.6.6 inspec' returned a non-zero code: 1 ```
This seems to be a problem with docker versions earlier than 20.10.4, and at the time of writing this, DockerHub runs an older version.
Option 1:
If you have control over the version of your docker engine, upgrade it to the latest version (comments suggest at least version 20.10.4).
Option 2:
Use FROM alpine:3.13.
With the latest alpine (3.14) it breaks.
Option 3:
Use the official ruby alpine image. I tested with FROM ruby:3-alpine.
References:
The issue opened on alpine/aports
The relevant release notes section for alpine 3.14

How can I install ruby 2.7.2 (Dockerfile) in Ubuntu 18.04?

I am creating a Dockerfile and somehow I can't install the ruby version I need: 2.7.2 . Since I just need this version, I don't want to install ruby through rbenv or rvm. I tried "apt install ruby", "apt get install ruby 2.7.2", "apt install ruby-full" and the version installed is always 2.5.1. Any Ideas?
This is how my Dockerfile looks like:
FROM nvidia/cuda:10.1-base-ubuntu18.04
LABEL version="0.0.1"
LABEL maintainer="mjg"
RUN apt update \
&& apt install -y python3.6 python3-pip \
&& apt install -y ruby
WORKDIR /cvlib
RUN pip3 install --upgrade pip; \
pip3 install opencv-python tensorflow cvlib; \
apt install -y libsm6 libxext6 libxrender-dev libgl1-mesa-glx; \
apt remove -y python3-pip
WORKDIR /app
COPY . .
VOLUME [ "/app/blurred-images", "app/source-images" ]
Using apt install ruby will install ruby version from distribution repository, which in your case in ruby 2.5.1. You should consider installing it with ruby version managers like rbenv or rvm, because they allow you to specify specific version that you want to install.

How can I get SASS/Compass into the DDEV web container?

A client needs Compass for SASS compilation inside the DDEV-Local web container. How can I get compass in there?
Compass requires ruby and rubygems, and rubygems requires a full build environment to build compass. (See http://compass-style.org/install/)
You can get all that with a .ddev/web-build/Dockerfile like this:
ARG BASE_IMAGE
FROM $BASE_IMAGE
RUN apt-get update
RUN DEBIAN_FRONTEND=noninteractive apt-get install -y -o Dpkg::Options::="--force-confold" --no-install-recommends --no-install-suggests build-essential ruby-full rubygems
RUN gem install compass
A slightly smaller approach would be to just add webimage_extra_packages: [ ruby-full, rubygems, build-essential ] to your .ddev/config.yaml and then use ddev exec sudo gem install compass when you need compass.

GitLab CI failing due to gem load error

I have a ruby script that fails the GitLab CI build with:
/usr/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require': cannot load such file -- git (LoadError)
The ruby script:
require 'git'
Here's the .gitlab-ci.yml file:
image: gitlab/gitlab-ce:latest
job1:
script:
- apt-get update && apt-get -y install ruby && apt-get install git
- gem install git
- ./script.rb
I've also tried adding a gemfile with the git gem and running:
image: gitlab/gitlab-ce:latest
job1:
script:
- apt-get update && apt-get -y install ruby && apt-get install git
- gem install bundler
- bundle install
- ./script.rb
But I get the same error
So it was quite simple.
Needed to sudo the gem install:
image: gitlab/gitlab-ce:latest
job1:
script:
- apt-get update && apt-get -y install ruby && apt-get install git
- sudo gem install git
- ./script.rb

Resources