Runners
A is a program installed on a machine. It regularly asks GitLab "do you have a job for me?", runs it and sends back the logs. The project uses its own runners, installed on its two .
The three runners
| Runner | Machine | Tag | Runs | |
|---|---|---|---|---|
trinity-dev-runner | trinity-dev | docker, privileged | none | api:*, web:* (lint, tests, build), docs:build |
trinity-dev-deploy | trinity-dev | shell | dev | deploy-dev |
trinity-prod-deploy | trinity-prod | shell | prod | deploy-prod |
The arrows start from the runners: they contact GitLab, over outgoing HTTPS. No port is opened for GitLab on the servers.
Why two kinds of executor
CI runner (docker) | Deploy runners (shell) | |
|---|---|---|
| Where the job runs | in a throwaway container | directly on the machine |
| Why | each job starts from a clean environment (node:22-alpine, python:3.11-slim) | deployment must drive the machine's Docker |
| Privileged | yes, for in the *:build jobs | not applicable |
| Docker access | the job's dind daemon | the gitlab-runner user is in the docker group |
Why a shell runner on each server, rather than a job that connects over SSH?
With SSH, a private key granting access to the server would have to be stored in GitLab's variables. Here, the runner is already on the machine: no deploy key exists, so none can leak.
Installing and configuring the runners
Everything is automated by the gitlab-runner Ansible role. The steps, in order:
1. Create the runners in GitLab
In the project: Settings → CI/CD → Runners → New project runner.
| Runner | Tags | "Run untagged jobs" |
|---|---|---|
| CI | none | checked |
| deploy dev | dev | unchecked |
| deploy prod | prod | unchecked |
GitLab shows a glrt-… token for each. Copy it right away.
A runner token is a secret
With this token, anyone can plug in a machine that will receive the project's jobs, and therefore its secret variables. It goes only into Ansible Vault.
2. Store the tokens in the Vault
cd infra/ansible
ansible-vault edit group_vars/all/vault.ymlThe decrypted file contains:
gitlab_runner_token: glrt-... # CI runner
deploy_runner_tokens:
trinity-dev: glrt-... # dev deploy runner
trinity-prod: glrt-... # prod deploy runner3. Run the role
ansible-playbook playbook.yml --tags gitlab-runner --ask-vault-passThe role:
---
- name: Add GitLab Runner GPG key
get_url:
url: https://packages.gitlab.com/runner/gitlab-runner/gpgkey
dest: /etc/apt/keyrings/gitlab-runner.asc
mode: '0644'
- name: Add GitLab Runner repository
apt_repository:
repo: "deb [signed-by=/etc/apt/keyrings/gitlab-runner.asc] https://packages.gitlab.com/runner/gitlab-runner/ubuntu/ {{ ansible_distribution_release }} main"
state: present
filename: gitlab-runner
update_cache: yes
- name: Install GitLab Runner
apt:
name: gitlab-runner
state: present
- name: Let deploy jobs use Docker
user:
name: gitlab-runner
groups: docker
append: yes
- name: Remove the logout script that makes shell jobs fail
file:
path: /home/gitlab-runner/.bash_logout
state: absent
- name: Read the registered runners
command: cat /etc/gitlab-runner/config.toml
register: gitlab_runner_config
changed_when: false
failed_when: false
- name: Register the CI runner
command: >
gitlab-runner register
--non-interactive
--url "https://gitlab.com"
--token "{{ gitlab_runner_token }}"
--executor "docker"
--docker-image "alpine:3.21"
--docker-privileged
--docker-volumes "/certs/client"
--description "{{ gitlab_runner_name }}"
when: "'dev' in group_names and gitlab_runner_name not in gitlab_runner_config.stdout"
no_log: true
- name: Register the deploy runner
command: >
gitlab-runner register
--non-interactive
--url "https://gitlab.com"
--token "{{ deploy_runner_tokens[inventory_hostname] }}"
--executor "shell"
--description "{{ inventory_hostname }}-deploy"
when: (inventory_hostname + '-deploy') not in gitlab_runner_config.stdout
no_log: true
- name: Start and enable GitLab Runner
systemd:
name: gitlab-runner
state: started
enabled: yes| Task | Why |
|---|---|
| Official APT repository | To get GitLab's version, not Ubuntu's |
gitlab-runner in the docker group | The shell runner runs docker compose and docker stack |
Removing .bash_logout | On Ubuntu, this file makes every shell job fail at the end ("prepare environment") |
Reading config.toml before registering | Makes the task : re-running the playbook does not register a duplicate runner |
--docker-privileged and --docker-volumes /certs/client | Needed for Docker-in-Docker with TLS in the *:build jobs |
no_log: true | The token does not appear in Ansible's output |
4. Check the connection
On the server:
sudo gitlab-runner verify
sudo gitlab-runner listIn GitLab, Settings → CI/CD → Runners: all three runners must have a green dot ("online").
For end-to-end proof, push a commit to a feature/* branch that changes web/: web:lint and web:test must run on trinity-dev-runner (the runner name is written at the top of the job log).
Disable GitLab's shared runners
In Settings → CI/CD → Runners, disable "Instance runners". Otherwise, an untagged job can run on a GitLab.com runner, and the proof that our runners work is no proof at all.
Runner troubleshooting is in Troubleshooting.