docker-services/tasks/gitlab-runner.yml

77 lines
2.8 KiB
YAML

---
- name: gitlab-runner | check vars are defined
assert:
that:
- gitlab_domain is defined
tags: ['docker_gitlab-runner']
- include_tasks: base.yml
tags: ['docker_gitlab-runner']
- name: gitlab-runner | create docker network
docker_network:
name: 'gitlab-runner'
tags: ['docker_gitlab-runner']
- name: gitlab-runner | create docker volumes
docker_volume:
name: '{{ item }}'
with_items:
- gitlab-runner-dind__var_lib_docker
- gitlab-runner-dind__certs
- gitlab-runner__home_gitlab-runner
- gitlab-runner__etc_gitlab-runner
tags: ['docker_gitlab-runner']
- name: gitlab-runner | configure config.toml
copy:
dest: '/var/lib/docker/volumes/gitlab-runner__etc_gitlab-runner/_data/config.toml'
mode: '0600'
content: |
concurrent = {{ gitlab_runner_concurrent | default(1) | int }}
check_interval = 0
[session_server]
session_timeout = 1800
[[runners]]
name = "{{ inventory_hostname }}"
url = "https://{{ gitlab_domain }}/"
{% if gitlab_runner_register_token is defined %}
token = "{{ gitlab_runner_register_token }}"
{% endif %}
executor = "docker"
[runners.docker]
host = "tcp://docker:2376/"
tls_cert_path = "/certs/client"
tls_verify = {{ gitlab_runner_tls_verify | default("true") }}
image = "{{ gitlab_runner_image | default('debian:stable-slim') }}"
privileged = {{ gitlab_runner_privileged | default("true") }}
disable_entrypoint_overwrite = {{ gitlab_runner_disable_entrypoint_overwrite | default("false") }}
oom_kill_disable = {{ gitlab_runner_oom_kill_disable | default("false") }}
disable_cache = {{ gitlab_runner_disable_cache | default("false") }}
volumes = ["/certs/client", "/var/run/docker.sock:/var/run/docker.sock:rw", "/cache:/cache", "/builds:/builds"]
shm_size = 0
pull_policy = ["always", "if-not-present"]
{% if gitlab_runner_extra_hosts is defined %}
extra_hosts = [{% for host in gitlab_runner_extra_hosts %}"{{ host }}"{{ ", " if not loop.last else "" }}{% endfor %}]
{% endif %}
notify: 'gitlab-runner-restart'
tags: ['docker_gitlab-runner']
- name: gitab-runner | configure cron garbage in dind
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"
tags: ['docker_gitlab-runner']
# - name: gitab-runner | purge dind cache
# 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"
# tags: ['docker_gitlab-runner']