Skip to main content

CI/CD with Rig

With the Rig CLI you can easily integrate Rig with any CI/CD system. In guide we will go through how use Rig specifically with Github Actions or GitLab CI/CD pipelines.

Github Actions

In addition to using the CLI "as is" in your Github Actions workflows, we have a setup action that makes it even easier.

Preparing variables

We recommend that you define the following variables to be available for Github actions.

  • RIG_HOST containing the full URL to your Rig API.
  • RIG_CLIENT_ID containing the client ID of your service account.
  • RIG_CLIENT_SECRET containing the client secret of your service account. This should be stored as a secret variable in Github.

For more information about how to set variables and secrets please refer to the official Github documentation for configuration variables and secrets.

Setup Step

For easy access to the Rig CLI in any GitHub Actions workflow, use our rig setup action rigdev/setup-rig@v1:

jobs:
deploy:
steps:
# Ensure that the rig CLI is installed and that the service account is
# activated. This will enable you to use the CLI on behalf of the service
# account.
- name: Setup Rig
uses: rigdev/setup-rig@v1
with:
# specify what version of the rig CLI you need. If left empty we use
# the latest release.
version: 1.12.7
host: ${{ vars.RIG_HOST }}
client-id: ${{ vars.CLIENT_ID }}
client-secret: ${{ secrets.CLIENT_SECRET }}
# With the CLI installed and service account activated you can use the
# CLI to send commands to the Rig API.
- run: |
rig deploy ...

Now that you are able to run the rig CLI you can either checkout our general documentation about using the CLI in CI/CD systems or read through the below example.

Example workflow: Build and deploy docker image

This example will show a full GitHub Actions workflow which builds a docker image, and deploys it using the rig CLI.

In the workflow we will go through the following steps

  1. Build a Docker image from a new commit
  2. Push that Docker image GitHub container registry
  3. Deploy the image in to a capsule named the same as the repository in the rig project 'my-project' for the production environment.
on: [push]

jobs:
build-and-deploy:
runs-on: ubuntu
env:
IMAGE_NAME: "ghcr.io/${{ github.repository_owner }}/${{ github.repository }}:${{ github.sha }}"
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Login to GitHub container registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build and push
uses: docker/build-push-action@v5
with:
push: true
tags: ${{ env.IMAGE_NAME }}

- name: Setup Rig
uses: rigdev/setup-rig@v1
with:
version: 1.12.7
host: ${{ vars.RIG_HOST }}
client-id: ${{ vars.RIG_CLIENT_ID }}
client-secret: ${{ secrets.RIG_CLIENT_SECRET }}

- name: Deploy Capsule to production
run: |
rig deploy ${{ github.repository }} \
--project my-project \
--environment production \
--image ${{ env.IMAGE_NAME }}

GitLab CI/CD Pipelines

When using GitLab, we recommend that the rig CLI is used in its docker image format.

Preparing variables

We recommend that you define the following variables to be available for pipelines.

  • RIG_HOST containing the full URL to your Rig API.
  • RIG_CLIENT_ID containing the client ID of your service account.
  • RIG_CLIENT_SECRET containing the client secret of your service account.

For more information about how to set variables please refer to the GitLab CI/CD Variables documentation.

Using rig CLI in a job

The easiest way to use the Rig CLI in your GitLab jobs is by running your job in our CLI image. See the following for a simple example of a GitLab Pipeline.

deploy:
image: ghcr.io/rigdev/rig:1.12.7
script:
# Activate the service account from RIG_CLIENT_ID, RIG_CLIENT_SECRET and
# RIG_HOST. This will enable you to use the CLI on behalf of the service
# account.
- rig auth activate-service-account -H $RIG_HOST
# When the service account is activated you can go ahead and issue commands
# on the CLI.
- rig capsule deploy ...

Now that you know how to run the rig CLI in GitLab. You can go ahead and checkout our documentation for how to effectively use the CLI in CI Systems.