Skip to content

Commit

Permalink
Integrate gitlab_runner role into hifis toolkit
Browse files Browse the repository at this point in the history
  • Loading branch information
tobiashuste committed May 16, 2024
1 parent c1c2b9a commit 134b0e3
Show file tree
Hide file tree
Showing 35 changed files with 2,286 additions and 1 deletion.
6 changes: 6 additions & 0 deletions .github/labeler.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@
# SPDX-License-Identifier: Apache-2.0

---
gitlab_runner:
- changed-files:
- any-glob-to-any-file:
- "roles/gitlab_runner/**"
- "molecule/gitlab_runner/**"
- ".github/workflows/gitlab_runner.yml"
ssh_keys:
- changed-files:
- any-glob-to-any-file:
Expand Down
74 changes: 74 additions & 0 deletions .github/workflows/gitlab_runner.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
# SPDX-FileCopyrightText: Helmholtz Centre for Environmental Research (UFZ)
# SPDX-FileCopyrightText: Helmholtz-Zentrum Dresden-Rossendorf (HZDR)
#
# SPDX-License-Identifier: Apache-2.0

---
name: "hifis.toolkit.gitlab_runner"

on:
pull_request:
paths:
- '.github/workflows/gitlab_runner.yml'
- 'roles/gitlab_runner/**'
- 'molecule/gitlab_runner/**'
- 'Pipfile'
- 'Pipfile.lock'
push:
branches:
- "main"
tags:
- "v*.*.*"
paths:
- '.github/workflows/gitlab_runner.yml'
- 'roles/gitlab_runner/**'
- 'molecule/gitlab_runner/**'
- 'Pipfile'
- 'Pipfile.lock'
schedule:
- cron: "0 0 * * *"
env:
PY_COLORS: 1
ANSIBLE_FORCE_COLOR: 1

jobs:

test:
name: Run Molecule tests.

Check failure on line 37 in .github/workflows/gitlab_runner.yml

View workflow job for this annotation

GitHub Actions / Ansible Lint

yaml[quoted-strings]

String value is not quoted with any quotes
runs-on: ubuntu-24.04

Check failure on line 38 in .github/workflows/gitlab_runner.yml

View workflow job for this annotation

GitHub Actions / Ansible Lint

yaml[quoted-strings]

String value is not quoted with any quotes
env:
PY_COLORS: 1
ANSIBLE_FORCE_COLOR: 1
strategy:
fail-fast: false
matrix:
image:
- "ghcr.io/hifis-net/ubuntu-systemd:20.04"
- "ghcr.io/hifis-net/ubuntu-systemd:22.04"
- "ghcr.io/hifis-net/ubuntu-systemd:24.04"
- "ghcr.io/hifis-net/debian-systemd:10"
- "ghcr.io/hifis-net/debian-systemd:11"
- "ghcr.io/hifis-net/debian-systemd:12"

steps:
- name: "Check out the codebase."
uses: "actions/checkout@v4"
with:
path: "ansible_collections/hifis/toolkit"

- name: "Prepare the job environment."
uses: "./ansible_collections/hifis/toolkit/.github/workflows/prepare-action"

# https://github.com/ansible/molecule/issues/3806
- name: "Help molecule to find the dependencies"
run: |
mkdir -p /home/runner/.ansible
ln -s /home/runner/work/ansible-collection-toolkit/ansible-collection-toolkit/ansible_collections/hifis/toolkit/roles \
/home/runner/.ansible/roles
- name: "Run Molecule tests."
run: "pipenv run molecule test -s gitlab_runner"
env:
MOLECULE_IMAGE: "${{ matrix.image }}"
AUTHENTICATION_TOKEN: ${{ secrets.authentication_token }}

Check failure on line 73 in .github/workflows/gitlab_runner.yml

View workflow job for this annotation

GitHub Actions / Ansible Lint

yaml[quoted-strings]

String value is not quoted with any quotes
working-directory: "ansible_collections/hifis/toolkit"
2 changes: 1 addition & 1 deletion .github/workflows/prepare-action/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ runs:
uses: "actions/setup-python@v5"
id: "setup-python"
with:
python-version: "3.10"
python-version: "3.12"
cache: "pipenv"

- name: "Install dependencies via pipenv."
Expand Down
12 changes: 12 additions & 0 deletions molecule/gitlab_runner/converge.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# SPDX-FileCopyrightText: Helmholtz Centre for Environmental Research (UFZ)
# SPDX-FileCopyrightText: Helmholtz-Zentrum Dresden - Rossendorf (HZDR)
#
# SPDX-License-Identifier: Apache-2.0

---
- name: Converge

Check failure on line 7 in molecule/gitlab_runner/converge.yml

View workflow job for this annotation

GitHub Actions / Ansible Lint

yaml[quoted-strings]

String value is not quoted with any quotes
hosts: all

Check failure on line 8 in molecule/gitlab_runner/converge.yml

View workflow job for this annotation

GitHub Actions / Ansible Lint

yaml[quoted-strings]

String value is not quoted with any quotes
tasks:
- name: "Include gitlab_runner role"
ansible.builtin.include_role:
name: "hifis.toolkit.gitlab_runner"
137 changes: 137 additions & 0 deletions molecule/gitlab_runner/molecule.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
# SPDX-FileCopyrightText: Helmholtz Centre for Environmental Research (UFZ)
# SPDX-FileCopyrightText: Helmholtz-Zentrum Dresden - Rossendorf (HZDR)
#
# SPDX-License-Identifier: Apache-2.0

---
dependency:
name: galaxy

Check failure on line 8 in molecule/gitlab_runner/molecule.yml

View workflow job for this annotation

GitHub Actions / Ansible Lint

yaml[quoted-strings]

String value is not quoted with any quotes
options:
requirements-file: "molecule/gitlab_runner/requirements.yml"
driver:
name: podman

Check failure on line 12 in molecule/gitlab_runner/molecule.yml

View workflow job for this annotation

GitHub Actions / Ansible Lint

yaml[quoted-strings]

String value is not quoted with any quotes
platforms:
- name: instancegitlabciopenstack1

Check failure on line 14 in molecule/gitlab_runner/molecule.yml

View workflow job for this annotation

GitHub Actions / Ansible Lint

yaml[quoted-strings]

String value is not quoted with any quotes
image: ${MOLECULE_IMAGE:-ghcr.io/hifis-net/ubuntu-systemd:24.04}

Check failure on line 15 in molecule/gitlab_runner/molecule.yml

View workflow job for this annotation

GitHub Actions / Ansible Lint

yaml[quoted-strings]

String value is not quoted with any quotes
pre_build_image: true
override_command: false
privileged: true # Required to run Docker in Podman
systemd: true
tty: true
- name: instancegitlabciopenstack2

Check failure on line 21 in molecule/gitlab_runner/molecule.yml

View workflow job for this annotation

GitHub Actions / Ansible Lint

yaml[quoted-strings]

String value is not quoted with any quotes
image: ${MOLECULE_IMAGE:-ghcr.io/hifis-net/ubuntu-systemd:24.04}
pre_build_image: true
override_command: false
privileged: true # Required to run Docker in Podman
systemd: true
tty: true
provisioner:
name: ansible
playbooks:
prepare: prepare.yml
converge: converge.yml
inventory:
hosts:
all:
vars:
gitlab_runner_concurrent: 4
host_vars:
instancegitlabciopenstack1:
gitlab_runner_version: "16.11.0"
gitlab_runner_deb_file: "https://packages.gitlab.com/runner/gitlab-runner/packages/{{ ansible_distribution | lower }}/{{ ansible_distribution_release | lower }}/gitlab-runner_{{ gitlab_runner_pkg_version }}_amd64.deb/download.deb"
gitlab_runner_install_docker: true
gitlab_runner_ssh_public_key: "test_key.pub"
gitlab_runner_ssh_private_key: "test_key"
gitlab_runner_sentry_dsn: "https://public@sentry.example.com/1"
gitlab_runner_registry_mirrors:
- "http://registry-mirror1.example"
- "https://registry-mirror2.example"
gitlab_runner_insecure_registries:
- "registry-mirror1.example"
gitlab_runner_enable_session_server: true
gitlab_runner_list:
- name: "test01"
url: "https://gitlab.com"
description: "Molecule test runner"
authentication_token: ${AUTHENTICATION_TOKEN}
executor: "docker"
environment: ["CI_CPUS=8", "DOCKER_TLS_CERTDIR=/certs"]
docker_security_opts: ["seccomp=unconfined"]
docker_volumes: ["/cache", "/certs/client"]
docker_devices: ["/dev/kfd", "/dev/dri"]
docker_cpus: 2
docker_gpus: "all"
docker_memory: "2g"
docker_image: "python:3.8"
docker_network_mtu: 1442
tags: ["docker", "hifis"]
locked: True
limit: 10
instancegitlabciopenstack2:
gitlab_runner_version: "16.11.0"
gitlab_runner_install_docker: false
gitlab_runner_ssh_public_key: ""
gitlab_runner_ssh_private_key: ""
gitlab_runner_registry_mirror: "https://registry-mirror.example"
gitlab_runner_listen_address: "127.0.0.1:9252"
gitlab_runner_set_default_network_opts: true
gitlab_runner_list:
- name: "test01"
url: "https://gitlab.com"
description: "Molecule test runner"
authentication_token: ${AUTHENTICATION_TOKEN}
executor: "docker+machine"
environment: ["CI_CPUS=8", "DOCKER_TLS_CERTDIR=/certs"]
docker_volumes: ["/cache", "/certs/client", "/opt/docker/daemon.json:/etc/docker/daemon.json:ro"]
docker_image: "python:3.8"
docker_shm_size: 2147483648
docker_disable_cache: True
tags: ["docker", "hifis"]
locked: True
limit: 10
machine_idle_count: 5
machine_idle_time: 7200
machine_max_builds: 4
machine_max_growth_rate: 2
machine_driver: "openstack"
machine_name: "auto-scale-%s"
machine_options:
- "openstack-auth-url=https://openstack.example:5000/v3"
- "openstack-image-id=73f07dd3-fa8b-468f-b6bc-b0cd4510f5d0"
- "openstack-flavor-name=m1.small"
- "openstack-net-id=7834deeb-8bd5-4fc7-b35b-24035d8f47a7"
- "openstack-username=gitlab-runner"
- "openstack-password=secret"
- "openstack-tenant-id=123456"
- "openstack-domain-name=default"
- "openstack-ssh-user=core"
- "openstack-sec-groups=Internal"
- "openstack-keypair-name=runners-internal"
- "openstack-private-key-file=/etc/gitlab-runner/gitlab_runner_key"
- "openstack-user-data-file=/etc/gitlab-runner/ignition.json"
- "openstack-active-timeout=300"
- "engine-registry-mirror=https://registry-mirror.example"
cache_type: "s3"
cache_server_address: "https://cache.example"
cache_access_key: "key"
cache_secret_key: "secret"
cache_bucket_name: "bucket"
cache_bucket_location: "eu-west-1"
cache_insecure: "false"
verifier:
name: ansible
scenario:
name: gitlab_runner
test_sequence:
- destroy
- dependency
- syntax
- create
- prepare
- check
- converge
- idempotence
- check
- side_effect
- verify
- destroy
39 changes: 39 additions & 0 deletions molecule/gitlab_runner/prepare.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# SPDX-FileCopyrightText: Helmholtz Centre for Environmental Research (UFZ)
# SPDX-FileCopyrightText: Helmholtz-Zentrum Dresden-Rossendorf (HZDR)
#
# SPDX-License-Identifier: Apache-2.0

---
- name: Prepare
hosts: all
tasks:
- name: Install necessary packages
when: ansible_os_family == 'Debian'
block:
- name: Install missing dependencies
ansible.builtin.apt:
name:
- sudo # for `become` privilege escalation
- iproute2 # for gathering network facts
- ca-certificates # for Gitlab-Runner download
- gpg
- python3-debian
state: present
update_cache: yes
- name: Set up iptables
when: ansible_distribution == 'Debian'
block:
- name: "Install missing dependencies"
ansible.builtin.apt:
name:
- "iptables"
state: "present"
update_cache: yes
- name: "Use legacy iptables"
community.general.alternatives:
name: "iptables"
path: "/usr/sbin/iptables-legacy"
- name: "Use legacy ip6tables"
community.general.alternatives:
name: "ip6tables"
path: "/usr/sbin/ip6tables-legacy"
8 changes: 8 additions & 0 deletions molecule/gitlab_runner/requirements.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# SPDX-FileCopyrightText: Helmholtz Centre for Environmental Research (UFZ)
# SPDX-FileCopyrightText: Helmholtz-Zentrum Dresden - Rossendorf (HZDR)
#
# SPDX-License-Identifier: Apache-2.0

---
roles:
- name: geerlingguy.docker
7 changes: 7 additions & 0 deletions molecule/gitlab_runner/test_key
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
-----BEGIN OPENSSH PRIVATE KEY-----
b3BlbnNzaC1rZXktdjEAAAAABG5vbmUAAAAEbm9uZQAAAAAAAAABAAAAMwAAAAtzc2gtZW
QyNTUxOQAAACAZxWIoT1CX3FFjc3+Em53Hy5ht8AbF8QHWQb25c3H2hQAAAJCiuPqvorj6
rwAAAAtzc2gtZWQyNTUxOQAAACAZxWIoT1CX3FFjc3+Em53Hy5ht8AbF8QHWQb25c3H2hQ
AAAEBQMNsWaiJGO+9HM245p+bcdI6mucBBHnD+880/zEOOERnFYihPUJfcUWNzf4SbncfL
mG3wBsXxAdZBvblzcfaFAAAACXVzZXJAaG9zdAECAwQ=
-----END OPENSSH PRIVATE KEY-----
4 changes: 4 additions & 0 deletions molecule/gitlab_runner/test_key.license
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
SPDX-FileCopyrightText: Helmholtz Centre for Environmental Research (UFZ)
SPDX-FileCopyrightText: Helmholtz-Zentrum Dresden - Rossendorf (HZDR)

SPDX-License-Identifier: Apache-2.0
1 change: 1 addition & 0 deletions molecule/gitlab_runner/test_key.pub
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIBnFYihPUJfcUWNzf4SbncfLmG3wBsXxAdZBvblzcfaF
4 changes: 4 additions & 0 deletions molecule/gitlab_runner/test_key.pub.license
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
SPDX-FileCopyrightText: Helmholtz Centre for Environmental Research (UFZ)
SPDX-FileCopyrightText: Helmholtz-Zentrum Dresden - Rossendorf (HZDR)

SPDX-License-Identifier: Apache-2.0
Loading

0 comments on commit 134b0e3

Please sign in to comment.