mkosi-based Gitea runner OS and job image
os / os (push) Failing after 45s
job / job (push) Failing after 1m3s

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Job79andClaude Opus 5.5 committed 2026-11-12 22:43:46 +01:00
commit d4eebeb01f
33 files changed
+529

No files matched your search

@@ -0,0 +1,32 @@
# The runner's configuration (gitea-runner.service).
# Every option: `gitea-runner config generate`.
runner:
# Parallel jobs, asked at first boot (stored in /etc/gitea-runner/runner.env).
capacity: ${GITEA_RUNNER_CAPACITY}
# On stop (before an update reboot), take no new jobs and give running ones this long to finish.
shutdown_timeout: 30m
envs:
# podman in jobs: the job's own storage plus the shared base images (see volumes below).
CONTAINERS_STORAGE_CONF: /usr/lib/gitea-runner/job/storage.conf
labels:
# Our job image (job/Containerfile): git, node, skopeo and podman.
- "linux:docker://git.plabble.org/job79/git-runner-mkosi-job:latest"
# Plain Fedora; our own build workflows use it, so a broken job image can't block its own fix.
- "fedora:docker://quay.io/fedora/fedora:45"
container:
# Jobs build OS images, which needs root: they run privileged on root's podman.
privileged: true
# podman can't keep its storage, or build contexts, on the job's own overlay root.
options: --volume /var/lib/containers --volume /var/tmp
# Jobs run their own podman, never the runner's.
docker_host: "-"
volumes:
# Base images, pulled at boot by gitea-runner-images.service; podman in jobs uses them read-only.
- /var/lib/containers/base-images:/var/lib/base-images:ro
# podman storage settings for jobs (see the file).
- /usr/lib/gitea-runner/job:/usr/lib/gitea-runner/job:ro
force_pull: true
cache:
# Jobs reach the cache on the host through their bridge; the firewall allows this port.
host: host.containers.internal
port: 8088
@@ -0,0 +1,22 @@
# Firewall: drop all incoming traffic except replies, loopback, ICMP and DHCPv6.
# Loaded by nftables.service. Jobs live on podman bridges (podman*): they may reach the
# internet, DNS on their bridge, and the runner's cache server (config.yaml), nothing else here.
destroy table inet firewall
table inet firewall {
chain input {
type filter hook input priority filter; policy drop;
ct state established,related accept
ct state invalid drop
iif lo accept
meta l4proto { icmp, ipv6-icmp } accept
ip6 saddr fe80::/10 udp dport 546 accept
iifname "podman*" meta l4proto { tcp, udp } th dport 53 accept
iifname "podman*" tcp dport 8088 accept
}
chain forward {
type filter hook forward priority filter; policy drop;
ct state established,related accept
ct state invalid drop
iifname "podman*" accept
}
}
@@ -0,0 +1,9 @@
# podman storage in jobs (CONTAINERS_STORAGE_CONF). The job's own images go to the /var/lib/containers
# volume; the base images the host pulls at boot are shared read-only, so jobs don't download them.
[storage]
driver = "overlay"
graphroot = "/var/lib/containers/storage"
runroot = "/run/containers/storage"
[storage.options]
additionalimagestores = ["/var/lib/base-images"]
@@ -0,0 +1,4 @@
# Grow the root partition to fill the disk at boot (systemd-repart); systemd-growfs then grows
# its filesystem (GrowFileSystem= in mkosi.repart/30-root.conf).
[Partition]
Type=root
@@ -0,0 +1,31 @@
# Hardening, mostly the KSPP recommendations that Talos also sets by default.
# Left out on purpose: user.max_user_namespaces=0 breaks podman in jobs, and kernel.modules_disabled=1
# breaks loading the network modules podman needs.
# Hide kernel addresses in /proc and logs, even from root; they help exploits bypass KASLR.
kernel.kptr_restrict = 2
# Only root may read the kernel log (it leaks addresses and hardware details).
kernel.dmesg_restrict = 1
# No perf events for non-root users. Upstream kernels treat 3 like 2 (the strictest they know).
kernel.perf_event_paranoid = 3
# Harden the BPF JIT against JIT spraying, for every user. Small cost when BPF is used.
net.core.bpf_jit_harden = 2
# No BPF for non-root users, and it can't be switched back on at runtime (Fedora's default 2 can).
kernel.unprivileged_bpf_disabled = 1
# No kexec: nobody can boot another kernel without going through Secure Boot.
kernel.kexec_load_disabled = 1
# No core dumps of setuid programs; they can contain secrets.
fs.suid_dumpable = 0
# Don't load TTY line disciplines on demand; old ones have had exploitable bugs.
dev.tty.ldisc_autoload = 0
# userfaultfd only for root; it is used to make kernel race exploits reliable.
vm.unprivileged_userfaultfd = 0
# Don't open FIFOs and regular files owned by someone else in sticky directories like /tmp.
fs.protected_fifos = 2
fs.protected_regular = 2
# A process may only ptrace its own descendants (gdb ./prog works, gdb -p <other pid> doesn't).
kernel.yama.ptrace_scope = 1
# Performance: Fedora allows 128 inotify instances per user. Many containers (file watchers,
# systemd inside containers) run out of those; 8192 is common on Kubernetes nodes.
fs.inotify.max_user_instances = 8192
@@ -0,0 +1,8 @@
# DHCP on the real network cards. Kind=!* skips virtual links like the veths of podman's bridges,
# which netavark manages.
[Match]
Type=ether
Kind=!*
[Network]
DHCP=yes
@@ -0,0 +1,9 @@
# Services enabled in the image (mkosi runs systemctl preset-all).
enable systemd-networkd.service
enable systemd-resolved.service
enable nftables.service
enable podman.socket
enable gitea-runner-setup.service
enable gitea-runner.service
enable systemd-sysupdate-update.timer
enable systemd-sysupdate-reboot.timer
@@ -0,0 +1,17 @@
# Pulls the base images that jobs share read-only (see /usr/lib/gitea-runner/config.yaml) before the
# runner starts, so no job uses them while they change. Hosts reboot to update, so this runs about
# as often as there are updates.
[Unit]
Description=Base images for Gitea Actions jobs
Wants=network-online.target
After=network-online.target
Before=gitea-runner.service
[Service]
Type=oneshot
Environment=IMAGES=/var/lib/containers/base-images
# Without network the runner still starts, with the images it has.
ExecStart=-/usr/bin/podman --root ${IMAGES} --runroot /run/containers/base-images pull -q --policy newer \
quay.io/fedora/fedora:45 quay.io/fedora/fedora-minimal:45
ExecStart=/usr/bin/podman --root ${IMAGES} --runroot /run/containers/base-images image prune -f
TimeoutStartSec=30min
@@ -0,0 +1,17 @@
# First boot: asks for the root password and the runner's registration on the console (tty1).
[Unit]
Description=Gitea runner first-boot setup
ConditionPathExists=!/etc/gitea-runner/runner.env
Before=getty@tty1.service kmsconvt@tty1.service
[Service]
Type=oneshot
ExecStart=/usr/libexec/gitea-runner-setup
StandardInput=tty
StandardOutput=tty
TTYPath=/dev/tty1
TTYReset=yes
TTYVHangup=yes
[Install]
WantedBy=multi-user.target
@@ -0,0 +1,24 @@
# The Gitea Actions runner. Registers itself on its first start.
[Unit]
Description=Gitea Actions runner
Wants=network-online.target gitea-runner-images.service
After=network-online.target podman.socket gitea-runner-images.service
Requires=podman.socket
[Service]
# The runner drives root's podman (podman.socket.d gives this user the socket). The jobs it starts
# never get the socket (see config.yaml).
User=gitea-runner
WorkingDirectory=/var/lib/gitea-runner
EnvironmentFile=/etc/gitea-runner/runner.env
Environment=DOCKER_HOST=unix:///run/podman/podman.sock
# Register once; the result is kept in .runner.
ExecStartPre=/bin/sh -c '[ -f .runner ] || exec gitea-runner register --no-interactive --config /usr/lib/gitea-runner/config.yaml --instance "$GITEA_INSTANCE_URL"'
ExecStart=/usr/bin/gitea-runner daemon --config /usr/lib/gitea-runner/config.yaml
Restart=on-failure
# A bit longer than runner.shutdown_timeout, so running jobs can finish on stop.
TimeoutStopSec=35min
RestartSec=10s
[Install]
WantedBy=multi-user.target
@@ -0,0 +1,6 @@
# Load our firewall (/usr/lib/gitea-runner/firewall.nft) instead of /etc/sysconfig/nftables.conf.
[Service]
ExecStart=
ExecStart=/usr/sbin/nft -f /usr/lib/gitea-runner/firewall.nft
ExecReload=
ExecReload=/usr/sbin/nft -f /usr/lib/gitea-runner/firewall.nft
@@ -0,0 +1,4 @@
# The runner may use root's podman. Jobs never get this socket.
[Socket]
SocketGroup=gitea-runner
SocketMode=0660
@@ -0,0 +1,5 @@
# Daily at about 04:10, reboot into a downloaded update. Stop the runner first: it takes no new
# jobs and lets running ones finish (runner.shutdown_timeout).
[Service]
ExecStartPre=/bin/sh -c '/usr/lib/systemd/systemd-sysupdate pending || exit 0; systemctl stop gitea-runner'
TimeoutStartSec=40min
@@ -0,0 +1,18 @@
# Updates /usr: writes the next version to the unused /usr partition.
[Transfer]
ProtectVersion=%A
# Not signed: the Secure Boot signed UKI pins the hash of /usr (usrhash=).
Verify=no
[Source]
Type=url-file
Path=https://git.plabble.org/api/packages/job79/generic/git-runner-mkosi/latest/
MatchPattern=git-runner_@v.usr-%a.raw.zst
[Target]
Type=partition
Path=auto
MatchPattern=git-runner_@v
MatchPartitionType=usr
PartitionFlags=0
ReadOnly=1
@@ -0,0 +1,17 @@
# Updates the dm-verity hashes of /usr, next to 10-usr.transfer.
[Transfer]
ProtectVersion=%A
Verify=no
[Source]
Type=url-file
Path=https://git.plabble.org/api/packages/job79/generic/git-runner-mkosi/latest/
MatchPattern=git-runner_@v.usr-%a-verity.raw.zst
[Target]
Type=partition
Path=auto
MatchPattern=git-runner_@v_verity
MatchPartitionType=usr-verity
PartitionFlags=0
ReadOnly=1
@@ -0,0 +1,20 @@
# Installs the next UKI, which systemd-boot boots by default. If it fails to boot 3 times,
# systemd-boot falls back to the previous one.
[Transfer]
ProtectVersion=%A
Verify=no
[Source]
Type=url-file
Path=https://git.plabble.org/api/packages/job79/generic/git-runner-mkosi/latest/
MatchPattern=git-runner_@v.efi
[Target]
Type=regular-file
Path=/EFI/Linux
PathRelativeTo=boot
MatchPattern=git-runner_@v+@l-@d.efi git-runner_@v+@l.efi git-runner_@v.efi
Mode=0444
TriesLeft=3
TriesDone=0
InstancesMax=2
@@ -0,0 +1,2 @@
# The runner's user.
u gitea-runner - "Gitea Actions runner" /var/lib/gitea-runner
@@ -0,0 +1,9 @@
# The runner's directories, and a clean container storage on every boot.
# Home directory; holds the registration (.runner) and the actions cache.
d /var/lib/gitea-runner 0700 gitea-runner gitea-runner -
# podman's own line makes this 0700; the runner needs to reach podman.sock inside (podman.socket.d).
# This file sorts before podman.conf, so its line wins.
D! /run/podman 0750 root gitea-runner -
# Wipe all job containers, volumes and images on every boot. The shared base images
# (/var/lib/containers/base-images) stay; gitea-runner-images.service updates them.
R /var/lib/containers/storage
+25
View File
@@ -0,0 +1,25 @@
#!/bin/bash
# First boot: ask for the root password and the runner's registration.
set -euo pipefail
echo "== Gitea runner setup =="
while :; do
read -rsp "Root password: " pw; echo
read -rsp "Again: " pw2; echo
[[ -n $pw && $pw == "$pw2" ]] && break
echo "Passwords do not match, try again."
done
echo "root:$pw" | chpasswd
read -rp "Hostname (also the runner name): " name
read -rp "Gitea URL (e.g. https://gitea.example.com): " url
read -rp "Runner registration token: " token
read -rp "Parallel jobs [1]: " capacity
[[ $capacity =~ ^[1-9][0-9]*$ ]] || capacity=1
hostnamectl hostname "$name"
install -D -m 0640 -g gitea-runner /dev/stdin /etc/gitea-runner/runner.env <<ENV
GITEA_INSTANCE_URL=$url
GITEA_RUNNER_REGISTRATION_TOKEN=$token
GITEA_RUNNER_CAPACITY=$capacity
ENV
echo "Done. The runner registers itself within a few seconds."