homek8s/apps/base/forgejo/runner-deploy-arm64.yaml

297 lines
14 KiB
YAML
Raw Normal View History

---
# Second Forgejo Actions runner instance on the Pi, declaring ONLY the
# `deploy-arm64` label.
#
# Why: the Pi's original runner (forgejo-runner-arm64) serves every
# `runs-on: docker` job in the instance, so a long onionwire `ci` build (Rust,
# 20-40 min) holds the only `docker` slot and any site deploy queued behind it
# waits indefinitely - that is exactly how siriusgrowthsolutions.com sat on a
# stale page while deploy-site runs stayed in `waiting` (runs 1163/1164).
#
# Deploys are not CPU-bound the way CI is, so a separate runner instance is
# cheap; the labels are disjoint in both directions, so neither class can
# starve the other. Keep capacity 1: a deploy must not overlap itself (the Pi
# registry tag :latest and the k8s restartedAt patch are last-writer-wins).
#
# Since the arm64 dind cutover this runner has its own in-pod daemon too, so a
# deploy no longer shares the Pi's host Docker with anything.
apiVersion: apps/v1
kind: Deployment
metadata:
name: forgejo-runner-deploy-arm64
namespace: ci-runners
labels:
app: forgejo-runner
arch: arm64
role: deploy
spec:
replicas: 1
selector:
matchLabels:
app: forgejo-runner
role: deploy
# RWO PVC: never two pods on one data-root. Consequence to know before you
# touch this template: a rollout SIGKILLs the job container of any run in
# flight, and Forgejo then reports that run as a plain failure with the log
# cut off mid-step (no `exitcode` line) — seen as a 14 min "failing" push on
# sirius/sirius-growth, card t_29249bf0. Land template changes while the
# runner is idle.
strategy:
type: Recreate
template:
metadata:
labels:
app: forgejo-runner
arch: arm64
role: deploy
spec:
nodeSelector:
kubernetes.io/hostname: rpi
tolerations:
- key: dedicated
operator: Equal
value: network
effect: PreferNoSchedule
# Kata microVM (apps/base/forgejo/kata-runtimeclass.yaml, installed on rpi
# only). The pod is still `privileged: true` — a nested dockerd needs
# SYS_ADMIN+NET_ADMIN in the spec and PSA baseline forbids those two, so
# `ci-runners` stays at enforce: privileged (docs/pod-security.md). Kata
# changes the *consequence*: that privilege is VM root, not rpi's host
# root. Rollback of this whole experiment is this one field.
runtimeClassName: kata-qemu
# Group on the data volume, matching the runner gid (see fix-data-perms).
securityContext:
fsGroup: 1000
initContainers:
# Registration guard, NOT a registration step. The runner's identity
# (`runner.ini`, action_runner id 14 / uuid a41aad73-…) is copied onto
# the PVC from the Pi host before the first start. The previous version
# of this init container registered a *new* runner whenever the file was
# missing, which burns a single-use token and leaves a second
# action_runner row polling under a new uuid. Refuse instead: a missing
# file is an operator error, not something to paper over.
- name: require-registration
image: code.forgejo.org/forgejo/runner:5.0.1
imagePullPolicy: IfNotPresent
securityContext:
runAsUser: 0
command:
- sh
- -c
- |
set -e
if [ ! -s /data/runner.ini ]; then
echo "runner.ini missing on the data PVC — refusing to register a second uuid" >&2
echo "restore it: ssh rpi sudo install -m600 -o root -g root /opt/siriusdevops/runner-deploy/data/runner.ini /opt/local-path-provisioner/forgejo-runner-deploy-arm64-dind/runner.ini" >&2
exit 1
fi
echo "registration present: $(grep -o '\"uuid\": \"[^\"]*\"' /data/runner.ini)"
volumeMounts:
- name: data
mountPath: /data
# The runner container runs as uid 1000 (the image's own user) and needs
# to read its registration and write the actions cache on this PVC.
# Both were created by root before this change, so re-own them once per
# start. Scoped on purpose: a recursive chown of the whole PVC would
# walk the dind data-root.
- name: fix-data-perms
image: docker:27-dind
imagePullPolicy: IfNotPresent
securityContext:
runAsUser: 0
command:
- sh
- -c
- |
set -e
chown 1000:1000 /data
# Re-own the trees the runner itself writes: runner.ini, the act
# cache (cache/) and the action-repo checkout cache (.cache/act/).
# The re-own MUST be recursive. A top-level owner check is exactly
# what let this through once: /data/.cache was already 1000 while
# the git packs inside it were still root:root from the pre-uid-1000
# runner, so the guard skipped the one file that mattered and every
# job died in actions/checkout before any step ran:
# open /data/.cache/act/actions-checkout@v4/.git/objects/pack/
# pack-<id>.pack: permission denied
# (card t_29249bf0: 3 s red X, zero steps.) A few thousand small
# files; the dind data-root (/data/docker, tens of GB) stays
# root-owned and is deliberately not walked.
for d in /data/cache /data/.cache /data/runner.ini; do
if [ -e "$d" ]; then chown -R 1000:1000 "$d"; fi
done
true
volumeMounts:
- name: data
mountPath: /data
containers:
- name: dind
image: docker:27-dind
imagePullPolicy: IfNotPresent
command:
- sh
- -c
- |
set -e
# --- Data root: ext4 on a loop device, not the virtiofs mount ---
# Under Kata every Kubernetes volume is a virtiofs share, and
# overlayfs refuses virtiofs as an upperdir ("failed to mount
# overlay: invalid argument"), which leaves Docker on `vfs`
# (layer copies). A loop-backed ext4 image on the PVC restores
# overlay2: measured inside the guest 2026-11-27, Storage Driver
# overlay2, 16 GiB volume, survives pod restarts because the image
# file lives on the claim. Losing it only costs a cold image cache.
IMG=/data-docker/kata-ext4.img
[ -f "$IMG" ] || fallocate -l 16G "$IMG"
[ -b /dev/loop0 ] || mknod /dev/loop0 b 7 0
if ! losetup -a | grep -q "$IMG"; then
losetup /dev/loop0 "$IMG"
fi
blkid /dev/loop0 | grep -q 'TYPE="ext4"' || mkfs.ext4 -q -F -L katadocker /dev/loop0
mount /dev/loop0 /var/lib/docker
echo "dind data-root: $(df -hT /var/lib/docker | tail -1)"
# --insecure-registry: the Pi registry is plain HTTP on the WG
# hub IP. Docker only treats 127.0.0.0/8 as insecure by default,
# so without this `docker push 10.10.0.1:5000/...` from a job
# fails with "server gave HTTP response to HTTPS client".
dockerd --host=unix:///var/run/docker.sock --tls=false --mtu=1420 \
--group 1000 \
--insecure-registry=10.10.0.1:5000 &
pid=$!
i=0
while [ "$i" -lt 30 ]; do
# Readiness only: ownership is set by `dockerd --group 1000`.
if [ -S /var/run/docker.sock ]; then
break
fi
i=$((i+1))
sleep 1
done
# --- binfmt: the deploy cross-builds linux/amd64 under qemu ---
# deploy-site.yml runs `docker buildx build --platform linux/amd64`
# and until now that worked because the Pi HOST kernel had the
# qemu binfmt handlers registered. A Kata pod has its own guest
# kernel, so nothing is registered and the build dies with
# `exec format error` / `buildkit-qemu-x86_64: not found`.
# Registering inside the guest is per-VM state: it must run on
# every pod start. The tonistiigi/binfmt image is cached in the
# data-root after the first start, and the registration uses the
# F flag (interpreter fd is held by the kernel), so the image can
# exit immediately afterwards.
mount -t binfmt_misc binfmt_misc /proc/sys/fs/binfmt_misc 2>/dev/null || true
if ! grep -q . /proc/sys/fs/binfmt_misc/qemu-x86_64 2>/dev/null; then
i=0
until docker run --rm --privileged tonistiigi/binfmt --install amd64 >/dev/null 2>&1; do
i=$((i+1))
if [ "$i" -ge 3 ]; then
echo "WARNING: could not register qemu-x86_64 binfmt; amd64 cross builds will fail" >&2
break
fi
sleep 3
done
fi
grep -q . /proc/sys/fs/binfmt_misc/qemu-x86_64 2>/dev/null &&
echo "binfmt: qemu-x86_64 registered" || echo "binfmt: NOT registered" >&2
# Job containers must not start before the daemon AND the
# cross-build emulation are ready; the runner waits on this file.
touch /var/run/dind-ready
wait "$pid"
securityContext:
# Still required UNDER KATA: the caps a nested dockerd needs
# (SYS_ADMIN for mounts/overlay, NET_ADMIN for docker0/iptables)
# are caps the pod spec must add, and PSA `baseline` forbids both —
# no runtime works around that (measured: sysbox, gVisor, Kata, see
# docs/pod-security.md). What Kata changes is the blast radius: this
# is root inside a QEMU/KVM microVM, with no host namespaces and no
# host kernel, not root on rpi. On a runc runner the same flag is
# host root.
privileged: true
volumeMounts:
- name: dind-run
mountPath: /var/run
# The claim holds the loop-backed ext4 image (kata-ext4.img) rather
# than being dockerd's data-root directly: see the startup script.
- name: data
mountPath: /data-docker
subPath: docker
resources:
# Deliberately smaller than the shared runner's 4Gi. A deploy is two
# nginx-based site images (112-143 MB each) plus buildx's
# docker-container driver and one `--platform linux/amd64` cross
# build under qemu; nothing like the Rust ci.yml job that peaked at
# 3.10 GiB. The Pi has 7.0 GiB available and capacity 1 per runner
# bounds each runner but nothing bounds both: 4Gi + 2Gi limits leave
# ~1 GiB for kubelet/Cilium/cloudflared/host Docker even if a CI run
# and a deploy overlap, and an OOM here fails one deploy visibly.
# (A 4Gi deploy limit would let two runners claim every byte.)
requests:
cpu: 100m
memory: 256Mi
limits:
memory: 2Gi
- name: runner
image: code.forgejo.org/forgejo/runner:5.0.1
imagePullPolicy: IfNotPresent
securityContext:
# Image default user. The dind socket is 0660 root:1000
# (`dockerd --group 1000`) and fix-data-perms owns the PVC as
# 1000:1000, so no root is needed here.
runAsUser: 1000
runAsGroup: 1000
command:
- sh
- -c
- |
set -e
# Wait for the dind sidecar AND its per-VM extras (loop-backed
# data-root, qemu-x86_64 binfmt) — under Kata both are set up
# inside the guest on every pod start, so the socket alone is not
# "ready". dind touches /var/run/dind-ready last.
i=0
while [ "$i" -lt 90 ]; do
if [ -S /var/run/docker.sock ] && [ -e /var/run/dind-ready ]; then
break
fi
i=$((i+1))
sleep 2
done
exec forgejo-runner --config /config/config.toml daemon
env:
- name: DOCKER_HOST
value: unix:///var/run/docker.sock
volumeMounts:
- name: config-toml
mountPath: /config/config.toml
subPath: deploy-arm64.toml
- name: data
mountPath: /data
- name: dind-run
mountPath: /var/run
resources:
requests:
cpu: 50m
memory: 128Mi
limits:
memory: 512Mi
volumes:
- name: config-toml
configMap:
name: forgejo-runner-config
- name: data
persistentVolumeClaim:
claimName: forgejo-runner-deploy-arm64-dind
- name: dind-run
# tmpfs on purpose, NOT the default disk-backed emptyDir: under Kata a
# disk emptyDir is a virtiofs share, and a unix socket created on
# virtiofs is visible to the other containers in the pod but
# unconnectable. Measured 2026-11-27: the runner crashlooped on
# `cannot ping the docker daemon ... unix:///var/run/docker.sock`
# although `ls -l` showed the socket `srw-rw---- root:1000`, while the
# dind sidecar's own `docker version` on the same path worked. A
# memory-backed emptyDir is a tmpfs inside the guest, so the socket is
# a real inode the runner and the job containers can both connect to,
# and the existing `-v /var/run/docker.sock` job option keeps working.
# 64Mi holds the socket, the `dind-ready` marker and nothing else.
emptyDir:
medium: Memory
sizeLimit: 64Mi