Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/lint-and-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ jobs:
- android-runner-host
- org-runner
- no-docker-socket
- tmpfs-mounts
fail-fast: false
max-parallel: 1

Expand Down
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

## [0.1.8] - 2026-11-04
### Added
- `github_runner_tmpfs` (default `[]`): in-memory mounts for the runner container, to keep rebuildable job data off slow disks.
- `tmpfs-mounts` molecule scenario verifying the mounts are applied and the deploy stays idempotent.

## [0.1.7] - 2026-10-13
### Fixed
- The drain gate now actually drains. It used to only poll `busy`, so a runner on a busy fleet picked up a new queued job each time it finished one, and the deploy timed out after `github_runner_drain_timeout_minutes`. When a replace is imminent the role now strips the runner's custom labels first (no new job can route to it), waits out the in-flight job, then replaces it; the new container registers with its configured labels. A failed drain puts the stripped labels back. Read-only labels (`self-hosted`, OS, arch) can't be removed, so a job targeting only those can still land on a draining runner.
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ github_runner_env_filename | the filename of the env file for p
github_runner_github_host | The GITHUB_HOST used for registering the runner (defaults to "github.com")
github_runner_persist_config | whether to persist runner configuration across container restarts using a named volume (defaults to true)
github_runner_mount_docker_socket | whether to mount the host's /var/run/docker.sock into the runner container; set to false for runners whose jobs never use docker to drop the root-equivalent privilege (defaults to true)
github_runner_tmpfs | list of in-memory mounts in docker's "path:options" form, e.g. `/_work:rw,exec,size=10g`; include `exec` because docker's default is noexec; contents are lost when the container stops, and data held in a mount uses host RAM and swap, so set `size` to fit the host (defaults to [])
github_runner_stop_timeout | seconds docker waits after SIGTERM before SIGKILL when stopping the runner container, e.g. while replacing it on an image bump (defaults to 10)
github_runner_docker_timeout | Docker API client timeout in seconds for the deploy task; stopping and removing a crash-looping runner can exceed the SDK's 60s default (defaults to 180)
github_runner_drain_before_replace | when a deploy is about to replace the runner container, strip the runner's custom labels so it takes no new jobs and wait for any in-flight job to finish instead of destroying it (defaults to true). Needs a token that can manage the runner's labels
Expand Down
2 changes: 1 addition & 1 deletion galaxy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ description: "Installs github self hosted repo or org runners within a docker co
can be a vanilla runner, or one with java / android installed."
license_file: LICENSE
readme: README.md
version: 0.1.7
version: 0.1.8
repository: https://github.com/compscidr/ansible-github-runner
tags:
- github
Expand Down
7 changes: 7 additions & 0 deletions molecule/tmpfs-mounts/converge.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
- name: Converge
hosts: all
become: true
gather_facts: true
roles:
- role: github_runner
43 changes: 43 additions & 0 deletions molecule/tmpfs-mounts/molecule.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
---
dependency:
name: galaxy
options:
requirements-file: requirements.yml
driver:
name: docker
platforms:
- name: ubuntu-22.04-tmpfs-mounts
image: geerlingguy/docker-ubuntu2204-ansible:latest
command: ""
volumes:
- /var/run/docker.sock:/var/run/docker.sock
- /sys/fs/cgroup:/sys/fs/cgroup:rw
cgroupns_mode: host
privileged: true
pre_build_image: true
provisioner:
name: ansible
env:
ANSIBLE_ROLES_PATH: ${MOLECULE_PROJECT_DIRECTORY}/roles
playbooks:
prepare: ../default/prepare.yml
converge: converge.yml
verify: verify.yml
inventory:
host_vars:
ubuntu-22.04-tmpfs-mounts:
github_runner_personal_access_token: "test-token-tmpfs-mounts"
github_runner_name: "test-runner-tmpfs-mounts"
github_runner_repo: "test/repo"
github_runner_labels: "self-hosted,jvm"
github_runner_java: true
github_runner_mount_docker_socket: false
github_runner_tmpfs:
- /_work:rw,exec,size=64m
- /root/.gradle:rw,exec,size=64m
# Digest-pinned like Renovate pins it: the idempotence converge fails if
# the drain gate misreads this form as a change (it'd hit the API with
# the fake token).
github_runner_java_image: "compscidr/github-runner-android:latest@sha256:dd3d2e869a352efc027c07da44bab983d3b1878b612d5ff6b725315742eddd85"
verifier:
name: ansible
39 changes: 39 additions & 0 deletions molecule/tmpfs-mounts/verify.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
---
- name: Verify runner with tmpfs mounts
hosts: all
gather_facts: true
become: true
tasks:
- name: Read the runner container
community.docker.docker_container_info:
name: "{{ github_runner_name }}"
register: runner_container

- name: Verify the runner is running with its tmpfs mounts
ansible.builtin.assert:
that:
- runner_container.exists
- runner_container.container.State.Running
- runner_tmpfs.get('/_work') == 'rw,exec,size=64m'
- runner_tmpfs.get('/root/.gradle') == 'rw,exec,size=64m'
vars:
runner_tmpfs: "{{ runner_container.container.HostConfig.Tmpfs | default({}, true) }}"

# Rolling back has to clear the mounts, and the docker module doesn't do
# that unless the role compares them strictly.
- name: Deploy again without tmpfs mounts
ansible.builtin.include_role:
name: github_runner
vars:
github_runner_tmpfs: []
github_runner_drain_before_replace: false

- name: Read the redeployed runner container
community.docker.docker_container_info:
name: "{{ github_runner_name }}"
register: redeployed_container

- name: Verify the tmpfs mounts are gone
ansible.builtin.assert:
that:
- redeployed_container.container.HostConfig.Tmpfs | default({}, true) | length == 0
9 changes: 9 additions & 0 deletions roles/github_runner/defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,15 @@ github_runner_network_mode: default
# Chrome requests on that host with ERR_NETWORK_CHANGED).
github_runner_mount_docker_socket: true

# In-memory mounts for the runner container, in docker's "path:options" form,
# to keep rebuildable job data off slow disks. For example:
# - /_work:rw,exec,size=10g
# Set `exec`, since docker's tmpfs default is noexec and would stop jobs running
# gradlew or native modules. Contents are lost whenever the container stops, and
# a mount hides anything the image has at that path. Data held in a mount uses
# host RAM and swap, and a full mount fails the job, so set `size` to fit the host.
github_runner_tmpfs: []

github_runner_github_host: "github.com"

github_runner_persist_config: true
Expand Down
8 changes: 8 additions & 0 deletions roles/github_runner/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@
devices: "{{ ['/dev/bus/usb:/dev/bus/usb:rwm'] if (github_runner_java and github_runner_java_mount_usb) else omit }}"
device_cgroup_rules: "{{ ['c 189:* rmw'] if (github_runner_java and github_runner_java_mount_usb) else omit }}"
volumes: "{{ github_runner_volumes }}"
tmpfs: "{{ github_runner_tmpfs }}"
# Without strict, removing an entry leaves the mount on the container.
comparisons:
tmpfs: strict
restart_policy: unless-stopped
stop_timeout: "{{ github_runner_stop_timeout }}"
timeout: "{{ github_runner_docker_timeout }}"
Expand Down Expand Up @@ -174,6 +178,10 @@
devices: "{{ ['/dev/bus/usb:/dev/bus/usb:rwm'] if (github_runner_java and github_runner_java_mount_usb) else omit }}"
device_cgroup_rules: "{{ ['c 189:* rmw'] if (github_runner_java and github_runner_java_mount_usb) else omit }}"
volumes: "{{ github_runner_volumes }}"
tmpfs: "{{ github_runner_tmpfs }}"
# Without strict, removing an entry leaves the mount on the container.
comparisons:
tmpfs: strict
restart_policy: unless-stopped
# Replacing an existing container (image bump) stops and removes it first.
# A crash-looping or wedged runner can take well over the Docker SDK's
Expand Down
Loading