diff --git a/apps/base/forgejo/kustomization.yaml b/apps/base/forgejo/kustomization.yaml index 5b47247..2a9827c 100644 --- a/apps/base/forgejo/kustomization.yaml +++ b/apps/base/forgejo/kustomization.yaml @@ -11,3 +11,4 @@ resources: - runner-arm64.yaml - runner-amd64.yaml - runner-deploy-arm64.yaml + - prune-cronjob.yaml diff --git a/apps/base/forgejo/prune-cronjob.yaml b/apps/base/forgejo/prune-cronjob.yaml new file mode 100644 index 0000000..e560771 --- /dev/null +++ b/apps/base/forgejo/prune-cronjob.yaml @@ -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 diff --git a/apps/base/forgejo/runner-configmap.yaml b/apps/base/forgejo/runner-configmap.yaml index 4ae981e..9110668 100644 --- a/apps/base/forgejo/runner-configmap.yaml +++ b/apps/base/forgejo/runner-configmap.yaml @@ -27,7 +27,7 @@ data: # No docker_host here: setting it makes the runner inject the host socket # bind into the job container itself, which collides with the explicit # -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: - "**" # Dedicated runner for site deploys. It declares ONLY the `deploy-arm64` @@ -54,7 +54,11 @@ data: privileged: true # 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. - 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: - "**" diff --git a/apps/base/forgejo/runner-deploy-arm64.yaml b/apps/base/forgejo/runner-deploy-arm64.yaml index dc67abb..3c55816 100644 --- a/apps/base/forgejo/runner-deploy-arm64.yaml +++ b/apps/base/forgejo/runner-deploy-arm64.yaml @@ -55,6 +55,11 @@ spec: # dies with "exec format error" on the Pi. image: code.forgejo.org/forgejo/runner:5.0.1 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: - sh - -c