CircleCI-Public / ruby-orb

The `circleci/ruby` orb source code.
https://circleci.com/developer/orbs/orb/circleci/ruby
MIT License
26 stars 53 forks source link

Setup of ruby 2.7.6 in environment with cimg/base:2022.09 or later as base image causes gem install to fail #115

Closed mkusaka closed 2 years ago

mkusaka commented 2 years ago

Orb version:

2.0.0 (also 1.8.0)

What happened:

After updating cimg/node from 16.17.1 to 16.18.0, the gem installation failed in the environment set up with ruby/install. ruby version was 2.7.6.

Here is the configuration file that reproduces

# Use the latest 2.1 version of CircleCI pipeline process engine.
# See: https://circleci.com/docs/2.0/configuration-reference
version: 2.1

# Orbs are reusable packages of CircleCI configuration that you may share across projects, enabling you to create encapsulated, parameterized commands, jobs, and executors that can be used across multiple projects.
# See: https://circleci.com/docs/2.0/orb-intro/
orbs:
  # https://circleci.com/developer/orbs/orb/circleci/ruby
  ruby: circleci/ruby@2.0.0

# Define a job to be invoked later in a workflow.
# See: https://circleci.com/docs/2.0/configuration-reference/#jobs
jobs:
  build:
    docker:
      - image: cimg/node:16.18.0
    steps:
      - checkout
      - ruby/install:
          version: 2.7.6
      - run: |
          gem install bundler
# Invoke jobs via workflows
# See: https://circleci.com/docs/2.0/configuration-reference/#workflows
workflows:
  sample: # This is the name of the workflow, feel free to change it to better match your workflow.
    # Inside the workflow, you define the jobs you want to run.
    jobs:
      - build

ref. https://github.com/mkusaka/ruby-orb-issue-repro/blob/3a1188dac37599e24814c020058e3b71415c79c8/.circleci/config.yml

The error message was something like this

ERROR:  Loading command: install (LoadError)
    cannot load such file -- openssl
ERROR:  While executing gem ... (NoMethodError)
    undefined method `invoke_with_build_args' for nil:NilClass

Exited with code exit status 1

ref. https://app.circleci.com/pipelines/github/mkusaka/ruby-orb-issue-repro/2/workflows/bbc2c09a-36d2-4bb0-b926-9cb3b3123c58/jobs/2

As the error message shows, this seems to be caused by openssl.

Expected behavior:

I want gem install to not fail after install ruby2.7.6 with ruby/install even in an environment with cimb/base:2022.09 as the base image.

Additional Information:

After some investigation, I found that cimg/node 16.17.1 uses openssl 1.1.1f (ubuntu 20.04) and cimg/node 16.18.0 uses openssl 3.0.2 (ubuntu 22.04).

``` ~/src/github.com/mkusaka/ruby-orb-issue-repro ❯ docker run -it --rm cimg/node:16.17.1 openssl version OpenSSL 1.1.1f 31 Mar 2020 ~/src/github.com/mkusaka/ruby-orb-issue-repro ❯ docker run -it --rm cimg/node:16.17.1 cat /etc/os-release NAME="Ubuntu" VERSION="20.04.4 LTS (Focal Fossa)" ID=ubuntu ID_LIKE=debian PRETTY_NAME="Ubuntu 20.04.4 LTS" VERSION_ID="20.04" HOME_URL="https://www.ubuntu.com/" SUPPORT_URL="https://help.ubuntu.com/" BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/" PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy" VERSION_CODENAME=focal UBUNTU_CODENAME=focal ~/src/github.com/mkusaka/ruby-orb-issue-repro ❯ docker run -it --rm cimg/node:16.18.0 openssl version OpenSSL 3.0.2 15 Mar 2022 (Library: OpenSSL 3.0.2 15 Mar 2022) ~/src/github.com/mkusaka/ruby-orb-issue-repro ❯ docker run -it --rm cimg/node:16.18.0 cat /etc/os-release PRETTY_NAME="Ubuntu 22.04.1 LTS" NAME="Ubuntu" VERSION_ID="22.04" VERSION="22.04.1 LTS (Jammy Jellyfish)" VERSION_CODENAME=jammy ID=ubuntu ID_LIKE=debian HOME_URL="https://www.ubuntu.com/" SUPPORT_URL="https://help.ubuntu.com/" BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/" PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy" UBUNTU_CODENAME=jammy ```

This is caused by cimg/base changing the base image from ubuntu 20.04 to 22.04 at the time of 2022.08 to 2022.09, and cimg/node changing the base image from cimg/base 2022.08 to 2022.10 at the time of 16.17.1.

``` ~/src/github.com/mkusaka/ruby-orb-issue-repro workaround ❯ docker run -it --rm cimg/base:2022.08 cat /etc/os-releases NAME="Ubuntu" VERSION="20.04.4 LTS (Focal Fossa)" ID=ubuntu ID_LIKE=debian PRETTY_NAME="Ubuntu 20.04.4 LTS" VERSION_ID="20.04" HOME_URL="https://www.ubuntu.com/" SUPPORT_URL="https://help.ubuntu.com/" BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/" PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy" VERSION_CODENAME=focal UBUNTU_CODENAME=focal ~/src/github.com/mkusaka/ruby-orb-issue-repro ❯ docker run -it --rm cimg/base:2022.09 cat /etc/os-release PRETTY_NAME="Ubuntu 22.04.1 LTS" NAME="Ubuntu" VERSION_ID="22.04" VERSION="22.04.1 LTS (Jammy Jellyfish)" VERSION_CODENAME=jammy ID=ubuntu ID_LIKE=debian HOME_URL="https://www.ubuntu.com/" SUPPORT_URL="https://help.ubuntu.com/" BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/" PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy" UBUNTU_CODENAME=jammy ``` refs. - cimg/node: pull request for 16.17.1 https://github.com/CircleCI-Public/cimg-node/pull/287/files#diff-738cfd4e614e111fe1a85b42bef9824f5b776b425d1484fa6ae55188977d6cfcL5 - cimg/node: pull request for 16.18.0 https://github.com/CircleCI-Public/cimg-node/pull/293/files#diff-9da88322f2b0b246bd3e90ac45962946d0b906bf4861efbb0a84813f4b83ecc1R8

The problem related to openssl 3.0.0 (ubuntu22.04) seems to be a known issue in ruby and in case of ruby-build, a solution has been found . However, the current installation of the ruby-orb script (based on rvm) does not work, and it seems that we need to re-install via script.

At this moment, there are several workarounds.

A. Re-install via rvm

Change the configuration file as follows

# Use the latest 2.1 version of CircleCI pipeline process engine.
# See: https://circleci.com/docs/2.0/configuration-reference
version: 2.1

# Orbs are reusable packages of CircleCI configuration that you may share across projects, enabling you to create encapsulated, parameterized commands, jobs, and executors that can be used across multiple projects.
# See: https://circleci.com/docs/2.0/orb-intro/
orbs:
  # https://circleci.com/developer/orbs/orb/circleci/ruby
  ruby: circleci/ruby@2.0.0

# Define a job to be invoked later in a workflow.
# See: https://circleci.com/docs/2.0/configuration-reference/#jobs
jobs:
  build:
    docker:
      - image: cimg/node:16.18.0
    steps:
      - checkout
      - ruby/install:
          version: 2.7.6
      - run: |
          rvm pkg install openssl
          rvm reinstall ruby-2.7.6 --with-openssl-dir=$HOME/.rvm/usr
      - run: |
          gem install aws-sdk

# Invoke jobs via workflows
# See: https://circleci.com/docs/2.0/configuration-reference/#workflows
workflows:
  sample: # This is the name of the workflow, feel free to change it to better match your workflow.
    # Inside the workflow, you define the jobs you want to run.
    jobs:
      - build

ref. https://github.com/mkusaka/ruby-orb-issue-repro/blob/6f15e0fb1ec57903e211d187659f83256f1fd5fb/.circleci/config.yml

The problem with this workarond is reinstallation via rvm is very slow (about 4minutes).

B. Stop using cimg/node and change cimg/base with ubuntu 20.04

Change the configuration file as follows

# Use the latest 2.1 version of CircleCI pipeline process engine.
# See: https://circleci.com/docs/2.0/configuration-reference
version: 2.1

# Orbs are reusable packages of CircleCI configuration that you may share across projects, enabling you to create encapsulated, parameterized commands, jobs, and executors that can be used across multiple projects.
# See: https://circleci.com/docs/2.0/orb-intro/
orbs:
  # https://circleci.com/developer/orbs/orb/circleci/ruby
  ruby: circleci/ruby@2.0.0
  # https://circleci.com/developer/orbs/orb/circleci/node
  node: circleci/node@5.0.3

# Define a job to be invoked later in a workflow.
# See: https://circleci.com/docs/2.0/configuration-reference/#jobs
jobs:
  build:
    docker:
      - image: cimg/base:2022.10-20.04
    steps:
      - checkout
      - node/install:
          yarn-version: 1.22.19
          install-yarn: true
          node-version: 16.18.0
      - ruby/install:
          version: 2.7.6
      - run: |
          gem install bundler

# Invoke jobs via workflows
# See: https://circleci.com/docs/2.0/configuration-reference/#workflows
workflows:
  sample: # This is the name of the workflow, feel free to change it to better match your workflow.
    # Inside the workflow, you define the jobs you want to run.
    jobs:
      - build

ref. https://github.com/mkusaka/ruby-orb-issue-repro/blob/1bdb39845afe3fe799e067e3e55578b2ba3cbd3f/.circleci/config.yml

The problem with this workarond is that it requires more effort to create an environment equivalent to a convenience image such as cimg/node:16.18.0-browsers.

Jaryt commented 2 years ago

Hi @mkusaka Thank you for raising this!

I will look into working a solution into the orb asap.

Jaryt commented 2 years ago

As stated in the associated PR, we'll be implementing the rvm package fix. bundle will also be configured with the rvm openssl directory. This should prevent any issues with packages that require ssl to install.

I'll be implementing the option to cache the rvm folder next so that the install is a onetime problem. This will also be beneficial for caching ruby versions as well.