Runner: optional deployment on a dedicated Docker host
Demo / hello (push) Successful in 53s

Adds tasks/actions_host.yaml, which runs the Gitea Actions runner on a
host outside the cluster with Docker Compose: a private DinD daemon for
jobs (its own data directory, CPU and memory caps, lower CPU weight than
the host's other containers), the runner, and the S5 cleanup script.
Capacity, timeouts, pinned job images and cleanup settings are shared
with the in-cluster runner. It registers once with a token fetched from
the cluster and deletes the token file afterwards.

Not used by the main play; a playbook targeting the host imports it with
tasks_from.

Refs DevOps/software-infrastructure#45

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-12 18:56:37 -05:00
co-authored by Claude Opus 5.5
parent 4d7b0b9e01
commit 9f768ed621
5 changed files with 264 additions and 0 deletions
+26
View File
@@ -131,3 +131,29 @@ gitea_actions_abandoned_job_timeout: 12h
# Days to keep job logs and uploaded artifacts. [365] and [90]
gitea_actions_log_retention_days: 90
gitea_actions_artifact_retention_days: 30
# Runner on a dedicated Docker host outside the cluster (tasks/actions_host.yaml,
# I3). Applied by its own playbook against that host; the settings above
# (capacity, timeouts, job images, cleanup) apply to it too.
gitea_actions_host_dir: /opt/gitea-runner
gitea_actions_host_instance_url: https://gitea.eom.dev
gitea_actions_host_runner_name: "{{ inventory_hostname }}"
# Inventory host that can run kubectl against the cluster; used once, to get
# a registration token when the runner isn't registered yet.
gitea_actions_host_token_from: alpha-control-plane
# Same images as chart gitea/actions 0.1.2 deploys in the cluster.
gitea_actions_host_runner_image: docker.gitea.com/runner:2.0.1
gitea_actions_host_dind_image: docker.io/docker:29.5.2-dind
# Where the private Docker daemon keeps images, containers and volumes. Docker
# can't cap a bind mount, so the cleanup threshold below keeps it in bounds,
# and the role refuses a first deploy with less free space than min_free_gb.
gitea_actions_host_docker_data: /var/lib/gitea-runner/docker
gitea_actions_host_min_free_gb: 60
gitea_actions_host_prune_images_above_gb: 40
# Job budget. 4 of 6 CPUs and 16 GB suit inspiron-3670 (6 cores, 62 GB),
# leaving room for the host's other services.
gitea_actions_host_dind_cpus: 4
gitea_actions_host_dind_cpu_shares: 512
gitea_actions_host_dind_memory: 16g
# shutdown_timeout + report_close_timeout plus a margin.
gitea_actions_host_stop_grace_period: 40s
+126
View File
@@ -0,0 +1,126 @@
---
# 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_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 }}"
become: false
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
+6
View File
@@ -12,3 +12,9 @@
import_tasks: actions.yaml
when: gitea_actions_enabled | bool
tags: [actions]
# Not part of the cluster play: a playbook targeting the runner host imports
# this with tasks_from, for example ci-runner.yaml in software-infrastructure.
# - import_role:
# name: ericomeehan.gitea
# tasks_from: actions_host.yaml
+84
View File
@@ -0,0 +1,84 @@
# {{ ansible_managed }}
# Gitea Actions runner on a dedicated host (tasks/actions_host.yaml).
name: gitea-runner
x-logging: &logging
driver: json-file
options:
max-size: 10m
max-file: "3"
services:
# Private Docker daemon for jobs, separate from the host's own Docker.
dind:
image: {{ gitea_actions_host_dind_image }}
privileged: true
restart: unless-stopped
command: ["--host=unix:///run/dind/docker.sock"]
environment:
# No TCP listener, so no TLS certificates are needed.
DOCKER_TLS_CERTDIR: ""
volumes:
- {{ gitea_actions_host_docker_data }}:/var/lib/docker
- docker-socket:/run/dind
healthcheck:
test: ["CMD", "docker", "-H", "unix:///run/dind/docker.sock", "info", "--format", "{{ '{{' }}.ID{{ '}}' }}"]
interval: 10s
timeout: 10s
retries: 30
start_period: 10s
# Jobs run inside this container, so these caps are the jobs' budget.
# cpu_shares below the default 1024 lets the host's other containers win
# when CPU is short.
cpus: {{ gitea_actions_host_dind_cpus }}
cpu_shares: {{ gitea_actions_host_dind_cpu_shares }}
mem_limit: {{ gitea_actions_host_dind_memory }}
memswap_limit: {{ gitea_actions_host_dind_memory }}
logging: *logging
runner:
image: {{ gitea_actions_host_runner_image }}
restart: unless-stopped
# Jobs that are running get shutdown_timeout to finish and
# report_close_timeout to report; give both before Docker kills it.
stop_grace_period: {{ gitea_actions_host_stop_grace_period }}
depends_on:
dind:
condition: service_healthy
environment:
GITEA_INSTANCE_URL: {{ gitea_actions_host_instance_url }}
GITEA_RUNNER_NAME: {{ gitea_actions_host_runner_name }}
GITEA_RUNNER_REGISTRATION_TOKEN_FILE: /token/registration-token
CONFIG_FILE: /runner/config.yaml
DOCKER_HOST: unix:///run/dind/docker.sock
TZ: Etc/UTC
volumes:
- ./config.yaml:/runner/config.yaml:ro
- ./data:/data
- ./token:/token:ro
- docker-socket:/run/dind
mem_limit: 512m
logging: *logging
prune:
image: {{ gitea_actions_prune_image }}
restart: unless-stopped
entrypoint: ["/bin/sh", "/prune/docker-prune.sh"]
depends_on:
dind:
condition: service_healthy
environment:
DOCKER_HOST: unix:///run/dind/docker.sock
PRUNE_INTERVAL_SECONDS: "{{ gitea_actions_prune_interval_seconds }}"
PRUNE_MAX_AGE_MINUTES: "{{ gitea_actions_prune_max_age_minutes }}"
PRUNE_IMAGES_ABOVE_GB: "{{ gitea_actions_host_prune_images_above_gb }}"
PRUNE_KEEP_IMAGES: "{{ gitea_actions_prune_keep_images | join(' ') }}"
volumes:
- ./docker-prune.sh:/prune/docker-prune.sh:ro
- docker-socket:/run/dind
cpus: 0.2
mem_limit: 128m
logging: *logging
volumes:
docker-socket:
+22
View File
@@ -0,0 +1,22 @@
# {{ ansible_managed }}
# Runner config for the dedicated runner host (tasks/actions_host.yaml).
# Kept in step with the in-cluster runner's config in tasks/actions.yaml.
log:
level: info
cache:
enabled: false
container:
require_docker: true
docker_timeout: 300s
# Use the cached job image; the labels below pin its version.
force_pull: false
runner:
capacity: {{ gitea_actions_runner_capacity }}
timeout: {{ gitea_actions_runner_job_timeout }}
shutdown_timeout: {{ gitea_actions_runner_shutdown_timeout }}
report_close_timeout: {{ gitea_actions_runner_report_close_timeout }}
fetch_timeout: {{ gitea_actions_runner_fetch_timeout }}
labels:
{% for label in gitea_actions_runner_labels %}
- "{{ label }}"
{% endfor %}