mullholland.gitlab_runner_docker

Ansible role gitlab_runner_docker

Install and configures GitLab Runner in a docker container

GitHub Downloads Version
github downloads Version

Example Playbook

This example is taken from molecule/default/converge.yml and is tested on each push, pull request and release.

---
- name: Converge
  hosts: all
  become: true
  gather_facts: true
  vars:
    gitlab_runner_docker_instances:
      - name: "group"
        image: "registry.gitlab.com/gitlab-org/gitlab-runner:alpine"
        server: "https:/gitlab.example.com"
        token: "glrt-GnhtWxnfAxn3GnT4ExiK"
        env:
          - "KEY1: VALUE1"
        register_env:
          - "KEY2: VALUE2"
        # command: ""
        volumes:
          - "/tmp:/tmp"
        ports:
          - "8080:8080"
        labels:
          - "Label1=Tag1"
        state: present
      - name: "group2"
        image: "registry.gitlab.com/gitlab-org/gitlab-runner:alpine"
        server: "https:/gitlab.example.com"
        token: "glrt-GnhtWxnfAxn3GnT4ExiK"
        env:
          - "KEY1: VALUE1"
        register_env:
          - "KEY2: VALUE2"
        # command: ""
        volumes:
          - "/tmp:/tmp"
        ports:
          - "8080:8080"
        labels:
          - "Label1=Tag1"
        state: present
      - name: "group3"
        state: absent

  roles:
    - role: "mullholland.gitlab_runner_docker"

The machine needs to be prepared. In CI this is done using molecule/default/prepare.yml:

---
- name: Prepare
  hosts: all
  become: true
  gather_facts: true
  vars:
    pip_packages:
      - "docker"

  roles:
    - role: mullholland.docker
    - role: mullholland.repository_epel
    - role: mullholland.pip

Role Variables

The default values for the variables are set in defaults/main.yml:

---
# General config
gitlab_runner_docker_network_name: "gitlab"
gitlab_runner_docker_base_path: "/opt"
gitlab_runner_docker_timezone: "Europe/Berlin"

# User/Group of the stack. Everything is mapped to this, instead of root.
gitlab_runner_docker_user: "homelab"
gitlab_runner_docker_uid: "900"
gitlab_runner_docker_group: "homelab"
gitlab_runner_docker_gid: "900"
gitlab_runner_docker_user_system: true

# options
# https://docs.gitlab.com/runner/commands/index.html#using-environment-variables
# gitlab-runner install --help
gitlab_runner_docker_registration_envs:
  - "REGISTER_LOCKED: true"
  - "RUNNER_EXECUTOR: docker"
  - "DOCKER_IMAGE: docker"
  - "DOCKER_VOLUMES: '/var/run/docker.sock:/var/run/docker.sock'"

gitlab_runner_docker_instances:
  - name: ""          # (required). Name of the GitLab runner instance
    image: ""         # (optional). Which image to use. Defaults to "registry.gitlab.com/gitlab-org/gitlab-runner:alpine".
    server: ""        # (required). GitLab serer URL
    token: ""         # (required). GitLab registration token.
    env: []           # (optional). Add additional environment variables only for gitlab runner.
    register_env: []  # (optional). Add additional environment variables only for runner registration. see option with 'gitlab-runner install --help'
    register_cmd: []  # (optional). Add additional commandline options for runner registration
    volumes: []       # (optional). Add additional volume mappings.
    ports: []         # (optional). Map docker port to the Host, can be used to exposed metrics or similar.
    labels: []        # (optional). Add container labels.

Requirements

State of used roles

The following roles are used to prepare a system. You can prepare your system in another way.

Requirement GitHub GitLab
mullholland.repository_epel Build Status GitHub Build Status GitLab
mullholland.docker Build Status GitHub Build Status GitLab
mullholland.pip Build Status GitHub Build Status GitLab

Context

This role is a part of many compatible roles. Have a look at the documentation of these roles for further information.

Here is an overview of related roles: dependencies

Compatibility

This role has been tested on these container images:

container tags
EL all
Fedora 38, 39
Ubuntu all
Debian all

The minimum version of Ansible required is 2.10, tests have been done to:

  • The previous version.
  • The current version.
  • The development version.

If you find issues, please register them in GitHub.

License

MIT.

Author Information

mullholland

About

Install and configures GitLab Runner in a docker container

Install
ansible-galaxy install mullholland.gitlab_runner_docker
GitHub repository
License
apache-2.0
Downloads
96