homek8s/docs/site-image-pinning.md
Lance Walters 5273a993f2 apps: pin every first-party site image to an immutable ref
Replace ':latest' + imagePullPolicy: Always on all seven site images with a
pinned tag (or digest) and IfNotPresent, so the image a Deployment runs is
chosen by this repo and rolled by Flux, not by CI patching restartedAt.

Every pin is the image that was already running, so the change is a no-op for
visitors: each pinned tag's manifest/config digest equals the running pod's
imageID (siriusdevops-* f0dde2f4, growth-site ea306b7, growth-portal d9e558c4,
phs-site 5b590cd).

sirius-growth-contact and phs-contact have no CI build path (no workflow has
ever pushed anything but :latest for them), so they are pinned by @sha256:
digest rather than inventing a pipeline; documented in
docs/site-image-pinning.md along with the operator flow.
2026-11-02 17:17:36 -05:00

5.6 KiB

Site images: immutable sha tags pinned in git

Every first-party site image runs from a tag pinned in this repo and is rolled by Flux. CI builds and pushes :<commit-sha> and prints the exact ref; the operator copies that ref into the Deployment manifest. There are no cluster credentials in any site repo — CI cannot roll a Deployment and cannot read a kubeconfig.

This replaces the old model (:latest + imagePullPolicy: Always + CI patching kubectl.kubernetes.io/restartedAt through a site-deployer ServiceAccount token). That path is gone: the SA/Role/RoleBinding were removed and the KUBE_CONFIG action secrets deleted.

Operator flow

  1. Push to a site repo (or workflow_dispatch it). The workflow builds the amd64 image, pushes <registry>/<image>:<sha>, and ends with a ### Pin this in sirius/homek8s … step that prints the ref. It also pushes :latest, but nothing in the cluster reads :latest — it is a convenience pointer for humans only.

  2. Edit the Deployment in apps/base/<app>/deployment*.yaml:

    image: forgejo.siriusdevops.com/sirius/<image>:<sha>
    imagePullPolicy: IfNotPresent
    
  3. Commit + push master, then force the Flux recheck (gitrepository first, kustomization second — an apps annotate that still reports the previous sha has not fetched the commit):

    kubectl -n flux-system annotate gitrepository flux-system reconcile.fluxcd.io/requestedAt="$(date +%s)" --overwrite
    kubectl -n flux-system annotate kustomization apps reconcile.fluxcd.io/requestedAt="$(date +%s)" --overwrite
    
  4. Verify: the pod template changed, so the Deployment rolls within ~1m and the pod reports the pinned ref.

    kubectl -n <ns> get pods -o jsonpath='{range .items[*]}{.metadata.name}{"\t"}{.status.containerStatuses[0].imageID}{"\n"}{end}'
    

    imageID must name :<sha> and carry the digest the registry returns for that tag (Docker-Content-Digest, below).

Rollback is git revert of the pin commit — Flux reconciles back in ~1m.

Why the site repos are not Flux sources

The only GitRepository cluster-wide is flux-system → sirius/homek8s. Flux owns the manifests; the site repos own only their image builds. The content revision a visitor sees is therefore chosen by the tag committed here, not by whatever CI pushed last. A site repo push alone changes nothing in the cluster.

Current pins

Namespace Deployment Image ref
siriusdevops siriusdevops-site siriusdevops-site:f0dde2f48c8224fb80d801ecb0d155c93332dc13
siriusdevops siriusdevops-contact siriusdevops-contact:f0dde2f48c8224fb80d801ecb0d155c93332dc13
sirius-growth sirius-growth-site sirius-growth-site:ea306b73b0d7c9ae8c33393a420e6d1d452b802b
sirius-growth sirius-growth-portal sirius-growth-portal:d9e558c4e0922d3ecd28214f7698ec0994170481
sirius-growth sirius-growth-contact sirius-growth-contact@sha256:cba0a5c67fee639dea78b568cbdf5889b2c78cc2c9cf85b02964ce17d60aab31
piedmont piedmont-site phs-site:5b590cddab6d7889fdd3c272255f28c4560e752e
piedmont piedmont-contact phs-contact@sha256:da61fc7943881f801fe6201749c01e364df6475d2460d6d17c8a6b48009f0056

Each pin was chosen as the tag whose manifest is the image already running (identical config digest), so pinning was a no-op for visitors.

The two digest-pinned contact APIs

sirius-growth-contact and phs-contact have no CI build path: neither sirius-growth/.forgejo/workflows/* nor sirius/websites/.forgejo/workflows/deploy-handyman.yml builds them (the source dirs contact-api/ and phs-contact-api/ exist, but no workflow pushes them; the registry only ever held :latest). They were built by hand before the workflows were trimmed. Per the no-invented-pipelines rule they are pinned by @sha256: digest — immutable, but there is no tag for an operator to bump. If a build step is ever added for them, move them to :<sha> like the rest. Both deployments run the same image content their pods already ran.

Registry facts

  • Registry: forgejo.siriusdevops.com (Forgejo packages, [packages] ENABLED = true).

  • Reads/writes need a read:package / write:package scoped token; the stored ~/.git-credentials oauth2 token is git-scoped and is rejected by /v2/.

  • Tags do not expire. package_cleanup_rule has zero rows and app.ini has no cleanup cron, so a pinned :<sha> stays resolvable.

  • Prove a pin T for image I without pulling anything:

    curl -s -u "sirius:$TOK" -H 'Accept: application/vnd.oci.image.index.v1+json,application/vnd.docker.distribution.manifest.list.v2+json,application/vnd.docker.distribution.manifest.v2+json' \
      -D - -o /dev/null "https://forgejo.siriusdevops.com/v2/sirius/$I/manifests/$T" | grep -i docker-content-digest
    

Pitfalls

  • docker buildx imagetools create (the :latest promote step) wraps a single-arch image in an index, so the :latest digest differs from the :<sha> digest even though the content is identical. Compare the config digest, or compare the running pod's digest to the :<sha> tag, never :latest vs the sha tag.
  • The amd64 runner's job image (node:20-bullseye) has no docker CLI, so the site workflows download a static client each run. That download has been observed to stall for the full 300s (curl: (28) … 0 out of 0 bytes) and fail the run. It is transient — re-dispatch the workflow instead of debugging the network.
  • runs-on matters: site images are linux/amd64 and only siriussec serves them. Build them on docker-amd64 / deploy-arm64, never on the arm64 docker runner.