forgejo: let the deploy runner's init container write runner.ini; cap job memory; prune nightly

- init container runs as root: kubelet creates the hostPath /data as root:root
  and the runner image's default user cannot write runner.ini there.
- container.options --memory 3g on both Pi runners: two concurrent jobs must not
  take the 8 GiB Pi (already using swap) to OOM. Caps the job container only.
- forgejo-runner-prune CronJob: exited containers >48h, images >168h, builder
  cache >72h, so the single 917G / volume stops climbing.
This commit is contained in:
Sirius DevOps 2026-10-22 23:55:21 -04:00
commit 741b9f13a7
4 changed files with 79 additions and 2 deletions

View file

@ -11,3 +11,4 @@ resources:
- runner-arm64.yaml - runner-arm64.yaml
- runner-amd64.yaml - runner-amd64.yaml
- runner-deploy-arm64.yaml - runner-deploy-arm64.yaml
- prune-cronjob.yaml

View file

@ -0,0 +1,67 @@
---
# Disk hygiene for the Pi's build host.
#
# Every push builds images on the Pi's own docker daemon (deploy-site's arm64
# image, onionwire's ci build containers) and nothing ever removed them: the
# single / volume sat at 76% (666G/917G) with weeks of exited job containers
# and superseded image layers. On one volume that is a slow-motion outage.
#
# Prune keeps a week of images (a rollback window), 48h of exited containers,
# and 72h of builder cache. It runs against the host socket, so it sees exactly
# the containers the runners created.
apiVersion: batch/v1
kind: CronJob
metadata:
name: forgejo-runner-prune
namespace: forgejo
labels:
app: forgejo-runner
role: prune
spec:
schedule: "17 4 * * *"
timeZone: "Etc/UTC"
concurrencyPolicy: Forbid
successfulJobsHistoryLimit: 3
failedJobsHistoryLimit: 3
jobTemplate:
spec:
backoffLimit: 1
activeDeadlineSeconds: 1800
template:
spec:
restartPolicy: Never
nodeSelector:
kubernetes.io/hostname: rpi
tolerations:
- key: dedicated
operator: Equal
value: network
effect: PreferNoSchedule
containers:
- name: prune
image: docker:27-cli
imagePullPolicy: IfNotPresent
command:
- sh
- -c
- |
set -e
echo "== before"; docker system df
docker container prune -f --filter until=48h || true
docker image prune -af --filter until=168h || true
docker builder prune -af --filter until=72h || true
echo "== after"; docker system df
volumeMounts:
- name: docker-sock
mountPath: /var/run/docker.sock
resources:
requests:
cpu: 10m
memory: 32Mi
limits:
memory: 128Mi
volumes:
- name: docker-sock
hostPath:
path: /var/run/docker.sock
type: Socket

View file

@ -27,7 +27,7 @@ data:
# No docker_host here: setting it makes the runner inject the host socket # No docker_host here: setting it makes the runner inject the host socket
# bind into the job container itself, which collides with the explicit # bind into the job container itself, which collides with the explicit
# -v /var/run/docker.sock in options ("Duplicate mount point"). # -v /var/run/docker.sock in options ("Duplicate mount point").
options: -v /usr/local/bin/docker-static:/usr/bin/docker:ro -v /opt/siriusdevops/runner/cli-plugins:/usr/local/lib/docker/cli-plugins:ro -v /var/run/docker.sock:/var/run/docker.sock options: -v /usr/local/bin/docker-static:/usr/bin/docker:ro -v /opt/siriusdevops/runner/cli-plugins:/usr/local/lib/docker/cli-plugins:ro -v /var/run/docker.sock:/var/run/docker.sock --memory 3g --memory-swap 3g
valid_volumes: valid_volumes:
- "**" - "**"
# Dedicated runner for site deploys. It declares ONLY the `deploy-arm64` # Dedicated runner for site deploys. It declares ONLY the `deploy-arm64`
@ -54,7 +54,11 @@ data:
privileged: true privileged: true
# Same injection as arm64.toml: the job container is node:20-bullseye, # Same injection as arm64.toml: the job container is node:20-bullseye,
# which has no docker CLI and no buildx, and deploy-site.yml needs both. # which has no docker CLI and no buildx, and deploy-site.yml needs both.
options: -v /usr/local/bin/docker-static:/usr/bin/docker:ro -v /opt/siriusdevops/runner/cli-plugins:/usr/local/lib/docker/cli-plugins:ro -v /var/run/docker.sock:/var/run/docker.sock # buildx is the host's cli-plugins binary and binfmt/QEMU is registered on
# the Pi host, so amd64 cross-builds work here exactly as on the arm64
# runner. --memory caps the job container only (sibling `docker run`
# containers a workflow spawns are outside the runner's control).
options: -v /usr/local/bin/docker-static:/usr/bin/docker:ro -v /opt/siriusdevops/runner/cli-plugins:/usr/local/lib/docker/cli-plugins:ro -v /var/run/docker.sock:/var/run/docker.sock --memory 3g --memory-swap 3g
valid_volumes: valid_volumes:
- "**" - "**"

View file

@ -55,6 +55,11 @@ spec:
# dies with "exec format error" on the Pi. # dies with "exec format error" on the Pi.
image: code.forgejo.org/forgejo/runner:5.0.1 image: code.forgejo.org/forgejo/runner:5.0.1
imagePullPolicy: IfNotPresent imagePullPolicy: IfNotPresent
# The hostPath /data dir is created root:root by kubelet, and the
# runner image's default user cannot write runner.ini into it.
securityContext:
runAsUser: 0
runAsGroup: 0
command: command:
- sh - sh
- -c - -c