Demo / hello (push) Successful in 16s
The runner's built-in cache server now backs actions/cache. - In the cluster, cache blobs go on a new PVC (gitea-actions-cache, 20Gi, default storage class) mounted at /cache in the runner container, so the cache survives runner restarts. The role creates the PVC before the Helm release. NFS doesn't enforce the size; the runner's own expiry (unused 7 days, or older than 30 days) keeps it bounded. - Fixed port 8088. Job containers reach it at the pod IP, which DinD's per-job networks route to because DinD shares the pod's network. - The dedicated-host runner gets the same config, with the cache on a bind mount under gitea_actions_host_dir. - gitea_actions_cache_enabled: false turns it all off again. Refs DevOps/software-infrastructure#56 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
127 lines
4.5 KiB
YAML
127 lines
4.5 KiB
YAML
---
|
|
# Deploys a Gitea Actions runner on a dedicated Docker host, outside the
|
|
# cluster (I3, DevOps/software-infrastructure#45). Same runner and settings
|
|
# as the in-cluster one in actions.yaml (capacity, timeouts, pinned job
|
|
# images, scheduled cleanup), as two Compose services:
|
|
# dind a private Docker daemon that holds every job container, with its
|
|
# own data directory. Jobs never see the host's Docker daemon or the
|
|
# other containers on the host.
|
|
# runner the runner itself, talking to dind over a socket in a shared volume.
|
|
# prune files/docker-prune.sh against dind, as in S5.
|
|
# Run it with the playbook that targets the host, for example
|
|
# ansible-playbook ci-runner.yaml
|
|
# Rerunning it recreates only the containers whose settings changed; a
|
|
# recreated dind or runner cancels the job that was running.
|
|
|
|
- name: require Docker with the Compose plugin on the runner host
|
|
ansible.builtin.command: docker compose version --short
|
|
register: runner_host_compose
|
|
changed_when: false
|
|
|
|
- name: create the runner directories
|
|
ansible.builtin.file:
|
|
path: "{{ item }}"
|
|
state: directory
|
|
owner: root
|
|
group: root
|
|
mode: "0700"
|
|
loop:
|
|
- "{{ gitea_actions_host_dir }}"
|
|
- "{{ gitea_actions_host_dir }}/data"
|
|
- "{{ gitea_actions_host_dir }}/token"
|
|
- "{{ gitea_actions_host_cache_dir }}"
|
|
- "{{ gitea_actions_host_docker_data }}"
|
|
|
|
- name: check whether the runner is already registered
|
|
ansible.builtin.stat:
|
|
path: "{{ gitea_actions_host_dir }}/data/.runner"
|
|
register: runner_host_state
|
|
|
|
- name: check free disk for Docker data
|
|
ansible.builtin.command: df --output=avail -B1G {{ gitea_actions_host_docker_data | quote }}
|
|
register: runner_host_df
|
|
changed_when: false
|
|
when: not runner_host_state.stat.exists
|
|
|
|
# Only before the first deploy: once dind runs, its own data uses the space.
|
|
- name: require enough free disk for Docker data
|
|
ansible.builtin.assert:
|
|
that: (runner_host_df.stdout_lines[-1] | trim | int) >= (gitea_actions_host_min_free_gb | int)
|
|
fail_msg: >-
|
|
{{ gitea_actions_host_docker_data }} has
|
|
{{ runner_host_df.stdout_lines[-1] | trim }} GB free; the runner needs at
|
|
least {{ gitea_actions_host_min_free_gb }} GB. Point
|
|
gitea_actions_host_docker_data at a bigger filesystem, or lower
|
|
gitea_actions_prune_images_above_gb together with this check.
|
|
quiet: true
|
|
when: not runner_host_state.stat.exists
|
|
|
|
- name: write a registration token for the first start
|
|
when: not runner_host_state.stat.exists
|
|
block:
|
|
- name: generate instance-level runner registration token
|
|
ansible.builtin.command: >-
|
|
kubectl -n gitea exec deployment/gitea -c gitea --
|
|
gitea actions generate-runner-token
|
|
delegate_to: "{{ gitea_actions_host_token_from }}"
|
|
register: runner_host_token
|
|
retries: 5
|
|
delay: 10
|
|
until: runner_host_token.rc == 0 and (runner_host_token.stdout | trim | length) > 0
|
|
changed_when: false
|
|
no_log: true
|
|
|
|
- name: store the registration token for the runner container
|
|
ansible.builtin.copy:
|
|
dest: "{{ gitea_actions_host_dir }}/token/registration-token"
|
|
content: "{{ runner_host_token.stdout | trim }}"
|
|
owner: root
|
|
group: root
|
|
mode: "0600"
|
|
no_log: true
|
|
|
|
- name: write the runner config
|
|
ansible.builtin.template:
|
|
src: runner-config.yaml.j2
|
|
dest: "{{ gitea_actions_host_dir }}/config.yaml"
|
|
owner: root
|
|
group: root
|
|
mode: "0644"
|
|
|
|
- name: install the Docker cleanup script
|
|
ansible.builtin.copy:
|
|
src: docker-prune.sh
|
|
dest: "{{ gitea_actions_host_dir }}/docker-prune.sh"
|
|
owner: root
|
|
group: root
|
|
mode: "0755"
|
|
|
|
- name: write the Compose file
|
|
ansible.builtin.template:
|
|
src: runner-compose.yaml.j2
|
|
dest: "{{ gitea_actions_host_dir }}/compose.yaml"
|
|
owner: root
|
|
group: root
|
|
mode: "0644"
|
|
validate: docker compose -f %s config --quiet
|
|
|
|
- name: start or update the runner
|
|
ansible.builtin.command:
|
|
cmd: docker compose up --detach --remove-orphans --wait --wait-timeout 300
|
|
chdir: "{{ gitea_actions_host_dir }}"
|
|
register: runner_host_up
|
|
changed_when: >-
|
|
(runner_host_up.stderr ~ runner_host_up.stdout)
|
|
is search('(Created|Recreated|Started|Removed)')
|
|
|
|
- name: wait for the runner to register
|
|
ansible.builtin.wait_for:
|
|
path: "{{ gitea_actions_host_dir }}/data/.runner"
|
|
timeout: 120
|
|
|
|
# Registration is stored in data/.runner; the token isn't needed again.
|
|
- name: remove the registration token
|
|
ansible.builtin.file:
|
|
path: "{{ gitea_actions_host_dir }}/token/registration-token"
|
|
state: absent
|