Skip to content

Ruby

This guide provides a walkthrough for a Ruby based application and how to configure common CI tasks on Razorops platform.

Demo project

To get started quickly, you can refer to our sample ruby based pipeline configuration here.

Choosing Ruby version

Usually the first step before writing CI spec is to decide the language runtime and support for the version compatible with your application. We support most active [versions]((https://www.ruby-lang.org/en/downloads/) of Ruby. You have the following options if you want to pin-down a version of Ruby -

  • For Docker runner environment, you can specify a container image (razorci/ruby or official ruby) with tag.
  • For Linux-VM environment, you can change the version (or install new version if not available) using rbenv.

Selecting Ruby version on Linux-VM environment

In Linux-VM build environment, we use rbenv to manage the various Ruby versions. You can find currently supported versions in toolbox reference. You can also install a different version using rbenv install <version> command if it's not supported by us.

Here are few commands to use, switch and install a version -

    # part of .razorops.yaml file
    steps:
    - commands:
      # list installed versions
      - rbenv versions
        # 2.7.8
        # 3.1.4

      - ruby --version

      - rbenv local 2.7
      - ruby --version
      # ruby 2.7.8pxxx (...) [x86_64-linux]

      # install ruby 3.2
      - rbenv install -l ## list stable versions
      - rbenv install 3.2.2

      - rbenv local 3.2.2
      - ruby --version
      # ruby 3.2.2pxxx (..) [x86_64-linux]

Note

You can also create a special .ruby-version file in your repository, indicating the ruby version that your app uses and can omit rbenv global <version> switch.

Available ruby versions pre-installed via rbenv - 2.7.8 and 3.1.4

Downloading dependencies

You can use official ruby docker image and provide commands to download dependencies -

tasks:
  build-deps:
    runner: ruby:2.7 # or razorci/ruby:2.7
    steps:
    - checkout
    - run: bundle install --deployment

Read more how to use this image on dockerhub docs.

Caching dependencies

You can further speedup the workflow by caching bundler dependencies so that every subsequent run then performs just incremental changes on top of that during bnudle install which may lead to even faster runs.

Here is an example to cache bundler dependencies.

    steps:
    ...
    - cache/pull:
        key: bundle-{{ checksum "Gemfile.lock" }}
        fallback_key: bundle-
    ...

    - cache/push:
        key: bundle-{{ checksum "Gemfile.lock" }}
        paths:
        - vendor/bundle

Execute test suite

Using official ruby docker image:

tasks:
  build-deps:
    runner:
      containers:
      - image: ruby:2.7 # or razorci/ruby:2.7
        environment:
        - DATABASE_URL: postgres://root@db:5432
      - image: postgres:9.6
    steps:
    - checkout
    - commands:
      - bundle install || bundle check
      - bundle exec rspec

You can additionally provide environment variables and provide service dependencies to run your test suite.