diff --git a/.forgejo/workflows/backup-image.yml b/.forgejo/workflows/backup-image.yml new file mode 100644 index 0000000..c55aadd --- /dev/null +++ b/.forgejo/workflows/backup-image.yml @@ -0,0 +1,80 @@ +name: backup-image +# Builds the backup tooling image used by the three nightly CronJobs +# (monitoring/grafana-backup, forgejo/cluster-backup, sirius-growth/leadgen-backup). +# +# Why this is a CI build at all (card t_9d0428d8): the jobs used to run +# `apk add rsync openssh-client` at container start, so the backup depended on +# the Alpine CDN at run time. Everything is baked here instead, from a base +# image pinned by digest, and the manifests pin the resulting image by digest. +# +# CI has no cluster credentials: this job only pushes an immutable :$sha tag to +# the in-cluster Forgejo registry and prints the digest to pin. The operator +# copies that digest into the three CronJob manifests in this same repo. +# +# amd64 only, on purpose: all three Jobs are nodeSelector'd to siriussec and +# the baked kubectl release checksum is amd64. Nothing here runs on rpi. + +on: + push: + branches: [master] + paths: + - 'images/backup/**' + - '.forgejo/workflows/backup-image.yml' + workflow_dispatch: + +jobs: + build: + runs-on: docker-amd64 + steps: + - uses: actions/checkout@v4 + + # The job image (node:20-bullseye) has no docker CLI of its own; the + # runner mounts the dind sidecar's client and cli-plugins. Verify both + # instead of assuming, and fail loudly rather than half-pushing. + - name: Verify docker CLI + buildx + run: | + set -euo pipefail + command -v docker + docker version + docker buildx version + + - name: Build and push (amd64, no attestation manifests) + env: + REG_USER: ${{ secrets.REGISTRY_USER }} + REG_PASS: ${{ secrets.REGISTRY_TOKEN }} + run: | + set -euo pipefail + sha=$(git rev-parse HEAD) + image=forgejo.siriusdevops.com/sirius/backup-tools + user="${REG_USER:-sirius}" + pass="${REG_PASS:-${{ github.token }}}" + echo "$pass" | docker login forgejo.siriusdevops.com -u "$user" --password-stdin + # --provenance=false --sbom=false: the tag must resolve to the single + # amd64 image manifest, so the digest a CronJob pins is exactly the + # image the pod runs (an index digest would resolve per-arch). + docker buildx build --platform linux/amd64 \ + --provenance=false --sbom=false \ + -t "$image:$sha" \ + --push images/backup + echo "pushed $image:$sha" + + - name: Print the digest to pin + env: + REG_USER: ${{ secrets.REGISTRY_USER }} + REG_PASS: ${{ secrets.REGISTRY_TOKEN }} + run: | + set -euo pipefail + sha=$(git rev-parse HEAD) + image=forgejo.siriusdevops.com/sirius/backup-tools + user="${REG_USER:-sirius}" + pass="${REG_PASS:-${{ github.token }}}" + echo "$pass" | docker login forgejo.siriusdevops.com -u "$user" --password-stdin + digest=$(docker buildx imagetools inspect "$image:$sha" --format '{{.Manifest.Digest}}') + echo "BACKUP_TOOLS_DIGEST=$digest" + { + echo "### Pin this in the three backup CronJob manifests" + echo "" + echo '```' + echo "$image@$digest" + echo '```' + } | tee -a "${GITHUB_STEP_SUMMARY:-/dev/stdout}" diff --git a/images/backup/Dockerfile b/images/backup/Dockerfile new file mode 100644 index 0000000..66b6bd6 --- /dev/null +++ b/images/backup/Dockerfile @@ -0,0 +1,49 @@ +# Backup tooling image for the three nightly state-backup CronJobs +# (monitoring/grafana-backup, forgejo/cluster-backup, sirius-growth/leadgen-backup). +# +# Why this exists (card t_9d0428d8): every one of those jobs used to run +# `apk add --no-cache rsync openssh-client` at container start, which dialled +# dl-cdn.alpinelinux.org (Fastly anycast 151.101.x.132:443) on every run. That +# made the nightly backup depend on the public internet, tripped the +# `egress-new-dst` flow alert whenever Fastly rotated an address, and put a +# package install on the one pod that carries the Grafana PVC and an SSH key. +# The toolchain is baked in at build time instead, and the pods get an egress +# NetworkPolicy that admits DNS + the backup host only. +# +# Base image is pinned by digest (multi-arch index digest; this build is +# linux/amd64 because all three jobs are nodeSelector'd to siriussec). +FROM python:3.12-alpine@sha256:c5ba3deef00c7758561a0f03c26f44f10589263d40e732b8748e0d1f38f6dd89 + +# kubectl is needed by forgejo/cluster-backup only (CNPG `get cluster` + +# `exec` pg_dump); the cluster runs v1.36.4, so the client is pinned to the +# same minor and its release checksum is verified at build time. +ARG KUBECTL_VERSION=v1.36.4 +ARG KUBECTL_SHA256=8b8f088da2dab964f853b38464033b1be15ede2839eca751482357c45abdd05a + +LABEL org.opencontainers.image.title="backup-tools" \ + org.opencontainers.image.description="python3.12-alpine + rsync + openssh-client + bash + kubectl for the nightly state backups" \ + org.opencontainers.image.source="https://forgejo.siriusdevops.com/sirius/homek8s" + +RUN set -eux; \ + # bash: cluster-backup and leadgen-backup use arrays, `set -o pipefail` + # and `tee >(...)` process substitution, so /bin/sh (busybox ash) is not + # enough -- the CronJob entrypoints stay /bin/bash, unchanged. + apk add --no-cache rsync openssh-client bash; \ + test "${TARGETARCH:-amd64}" = "amd64" || { echo "kubectl pin is amd64-only; the backup jobs run on siriussec" >&2; exit 1; }; \ + apk add --no-cache --virtual .fetch curl ca-certificates; \ + curl -fsSL -o /usr/local/bin/kubectl \ + "https://dl.k8s.io/release/${KUBECTL_VERSION}/bin/linux/amd64/kubectl"; \ + echo "${KUBECTL_SHA256} /usr/local/bin/kubectl" | sha256sum -c -; \ + chmod 0755 /usr/local/bin/kubectl; \ + apk del .fetch; \ + rm -rf /var/cache/apk/* + +# Build-time proof that nothing has to be installed at run time. +RUN set -eux; \ + rsync --version | head -1; \ + ssh -V; \ + bash --version | head -1; \ + python3 --version; \ + kubectl version --client + +CMD ["/bin/sh"]