From e77b49ea8b61b0d5315054090f62b94294f3a449 Mon Sep 17 00:00:00 2001 From: DevMiner Date: Thu, 21 Nov 2024 14:38:05 +0100 Subject: [PATCH] feat: support specifying `--docker-volumes` --- README.md | 1 + defaults/main.yml | 1 + tasks/registration.yml | 21 +++++++++++++++++++++ 3 files changed, 23 insertions(+) diff --git a/README.md b/README.md index 35ee8b9..58675f3 100644 --- a/README.md +++ b/README.md @@ -64,6 +64,7 @@ Ansible Collections startup. - `runner_stop_timeout`: Optional. Timeout in seconds for the service stop command after which systemd will just `SIGKILL` the process. +- `runner_docker_volumes`: Optional. List of volumes to mount into the CI jobs. - `runner_user`: Optional. User that will be used to run the runner. Only used if `runner_executor` is set to `shell`. diff --git a/defaults/main.yml b/defaults/main.yml index b9040f0..d9c5304 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -21,6 +21,7 @@ runner_docker_volume_mount_ssl: "/etc/ssl/certs:/etc/ssl/certs:ro" runner_docker_image: "docker:stable" runner_docker_privileged: false runner_docker_services_timeout: 90 +runner_docker_volumes: [] runner_user: gitlab-runner runner_home: /home/gitlab-runner diff --git a/tasks/registration.yml b/tasks/registration.yml index 5425cbc..7f4ec68 100644 --- a/tasks/registration.yml +++ b/tasks/registration.yml @@ -39,6 +39,26 @@ when: registered_runners.stderr.find('\n%s %s%s' | format(runner_name, '#', item)) == -1 register: runner +- name: "Registration | test" + ansible.builtin.command: > + gitlab-runner register + --non-interactive + --name "{{ runner_name }} #{{ item }}" + --url '{{ gitlab_url }}' + --token '{{ runner.results[item - 1].runner.token }}' + --executor '{{ runner_executor }}' + --docker-volumes='{{ runner_docker_volume_mount_daemon }}' + --docker-volumes='{{ runner_docker_volume_mount_ssl }}' + --env 'COMPOSE_HTTP_TIMEOUT={{ env_compose_http_timeout }}' + --env 'DOCKER_DRIVER={{ env_docker_driver }}' + --env 'DOCKER_TLS_CERTDIR={{ env_docker_tls_certdir }}' + {{ '--docker-image ' + runner_docker_image if runner_executor == 'docker' else '' }} + {{ runner_docker_volumes | default([]) | map('regex_replace', '^(.*)$', '--docker-volumes \\1') | join(' ') }} + {{ '--docker-privileged ' if runner_executor == 'docker' and runner_docker_privileged else '' }} + {{ '--docker-wait-for-services-timeout ' + + runner_docker_services_timeout | string if runner_executor == 'docker' else '' }} + loop: "{{ range(1, runner_count + 1, 1) | list }}" + - name: "Registration | Register Runner" ansible.builtin.command: > gitlab-runner register @@ -53,6 +73,7 @@ --env 'DOCKER_DRIVER={{ env_docker_driver }}' --env 'DOCKER_TLS_CERTDIR={{ env_docker_tls_certdir }}' {{ '--docker-image ' + runner_docker_image if runner_executor == 'docker' else '' }} + {{ runner_docker_volumes | default([]) | map('regex_replace', '^(.*)$', '--docker-volumes \\1') | join(' ') }} {{ '--docker-privileged ' if runner_executor == 'docker' and runner_docker_privileged else '' }} {{ '--docker-wait-for-services-timeout ' + runner_docker_services_timeout | string if runner_executor == 'docker' else '' }}