This guide provides a walkthrough for a Ruby based application and how to configure common CI tasks. We recommend you use docker based workflow for easier operations and immutable deployment. If not, you can directly jump below to use non-docker based tasks.
Docker based
I assume you are familiar with Docker concepts, if not please refer here to know more about the advantages of Docker.
Build/Test steps
If you have Dockerfile
in the root of your source repository, you can build a container image and use that container image to run your test suit. For example -
tasks:
build-image:
type: build
name: registry.example.com/web
tags: ["${CI_COMMIT_SHA}", "latest"]
rspec:
image: registry.example.com/web:latest
commands:
- bundle exec rspec
Non-Docker based
Downloading dependencies
You can use official ruby docker image and provide commands to download dependencies -
tasks:
build-deps:
image: ruby:2.6
commands:
- bundle install --deployment
Read more how to use this image on dockerhub docs.
TIP
You can further speedup the workflow by caching bundler dependencies so that every subsequent build then performs just incremental changes on top of that during bnudle install
which may lead to even faster builds.
Execute test suite
Using official node docker image:
tasks:
build-deps:
image: ruby:2.6
commands:
- bundle exec rspec
environment:
DATABASE_URL: postgres://root@db:5432
services:
db:
image: postgres:9.6
You can additionally provide environment variables and provide service dependencies to run your test suite.