docker-services/tasks/gitlab-runner.yml

90 lines
2.8 KiB
YAML
Raw Normal View History

2023-09-19 12:32:42 +02:00
---
2023-09-29 18:03:24 +02:00
- name: gitlab-runner | check vars are defined
assert:
that:
- gitlab_domain is defined
2023-09-29 18:07:00 +02:00
- gitlab_runner_register_token is defined
2023-09-29 18:03:24 +02:00
tags: ['docker_gitlab-runner']
- include_tasks: base.yml
tags: ['docker_gitlab']
2023-09-29 18:19:49 +02:00
- name: gitlab-runner | create docker network
docker_network:
name: 'gitlab-runner'
tags: ['docker_gitlab-runner']
- name: gitlab-runner | create docker volumes
2023-09-19 12:32:42 +02:00
docker_volume:
name: '{{ item }}'
with_items:
- gitlab-runner-dind__var_lib_docker
2023-09-29 18:03:24 +02:00
- gitlab-runner-dind__certs
2023-09-19 12:32:42 +02:00
- gitlab-runner__home_gitlab-runner
2023-09-29 18:03:24 +02:00
- gitlab-runner__etc_gitlab-runner
2023-09-29 17:43:17 +02:00
tags: ['docker_gitlab-runner']
2023-09-19 12:32:42 +02:00
2023-09-29 18:19:49 +02:00
- name: gitlab-runner | register to gitlab
2023-09-19 12:32:42 +02:00
uri:
2023-09-29 18:07:00 +02:00
url: 'https://{{ gitlab_domain }}/api/v4/runners'
2023-09-19 12:32:42 +02:00
method: POST
body:
token: '{{ gitlab_runner_register_token }}'
description: '{{ inventory_hostname }}'
status_code: 201
body_format: json
register: register_gitlab_runner_register
when:
- 'gitlab_runner_register_token is defined'
2023-09-29 17:43:17 +02:00
tags: ['docker_gitlab-runner']
2023-09-19 12:32:42 +02:00
2023-09-29 18:19:49 +02:00
- name: gitlab-runner | configure config.toml
2023-09-19 12:32:42 +02:00
copy:
dest: '/var/lib/docker/volumes/gitlab-runner__etc_gitlab-runner/_data/config.toml'
2023-09-19 12:32:42 +02:00
mode: '0600'
content: |
concurrent = "{{ (ansible_processor_cores * ansible_processor_count)|int }}"
2023-09-19 12:32:42 +02:00
check_interval = 0
2023-09-19 12:32:42 +02:00
[session_server]
session_timeout = 1800
2023-09-19 12:32:42 +02:00
[[runners]]
name = "{{ inventory_hostname }}"
url = "https://{{ gitlab_domain }}/"
token = "{{ register_gitlab_runner_register.json.token }}"
executor = "docker"
[runners.docker]
host = "tcp://docker:2376/"
tls_cert_path = "/certs/client"
tls_verify = true
2023-09-19 12:32:42 +02:00
image = "debian:stable-slim"
privileged = true
2023-09-19 12:32:42 +02:00
disable_entrypoint_overwrite = false
oom_kill_disable = false
disable_cache = false
volumes = ["/certs/client", "/var/run/docker.sock:/var/run/docker.sock:rw", "/cache", "/builds:/builds"]
2023-09-19 12:32:42 +02:00
shm_size = 0
pull_policy = ["always", "if-not-present"]
2023-09-29 18:05:53 +02:00
notify: 'gitlab-runner-restart'
2023-09-19 12:32:42 +02:00
when:
- 'gitlab_runner_register_token is defined'
- 'register_gitlab_runner_register.json.token is defined'
2023-09-29 17:43:17 +02:00
tags: ['docker_gitlab-runner']
2023-09-19 12:32:42 +02:00
2023-09-29 18:19:49 +02:00
- name: gitab-runner | configure cron garbage in dind
2023-09-19 12:32:42 +02:00
cron:
name: "gitlab_runner_garbage"
minute: "50"
hour: "*/2"
job: "/usr/bin/docker exec docker docker system prune -f; /usr/bin/docker exec docker docker volume prune -f 2>&1 |logger -t gitlab-runner"
2023-09-29 17:43:17 +02:00
tags: ['docker_gitlab-runner']
2023-09-19 12:32:42 +02:00
2023-09-29 18:19:49 +02:00
- name: gitab-runner | purge dind cache
2023-09-19 12:32:42 +02:00
cron:
name: "purge_dind_ci_cache"
minute: "30"
hour: "04"
job: "/usr/bin/docker exec -t docker /usr/bin/find /cache -mindepth 1 -mtime +7 -delete 2>&1 |logger -t gitlab-runner"
2023-09-29 17:43:17 +02:00
tags: ['docker_gitlab-runner']