From 60931fbba1e168a2faa342fb159868abfc54c617 Mon Sep 17 00:00:00 2001 From: rock Date: Tue, 27 Oct 2026 14:50:33 -0700 Subject: [PATCH] ci(iam): build and push the key-rotation-controller image Dockerfile: static binary on distroless, no shell, user 65532. Workflow runs on the golang runner for a push to main that touches the controller. It builds two tags, the commit sha and 0.1.0, which is the tag the Deployment asks for, and runs the image with --help so a broken binary fails the job instead of the cluster. The runners were dead before this: every task fetch logged 'lookup forgejo-gitea-http.cicd.svc.cluster.local: no such host'. DNS resolved from a fresh pod and the Service had a healthy endpoint, so the runner pods held stale network state. A rollout restart cleared it and all three poll without error. --- .../workflows/key-rotation-controller.yaml | 41 +++++++++++++++++++ .../controller/Dockerfile | 13 ++++++ 2 files changed, 54 insertions(+) create mode 100644 .forgejo/workflows/key-rotation-controller.yaml create mode 100644 k8s/apps/key-rotation-controller/controller/Dockerfile diff --git a/.forgejo/workflows/key-rotation-controller.yaml b/.forgejo/workflows/key-rotation-controller.yaml new file mode 100644 index 0000000..9ecd858 --- /dev/null +++ b/.forgejo/workflows/key-rotation-controller.yaml @@ -0,0 +1,41 @@ +# Builds and pushes the key-rotation-controller image. +# +# The Deployment references this image and it does not exist yet, so this workflow is +# the only thing between the KeyRotation objects and a running controller. +name: key-rotation-controller + +on: + push: + branches: [main] + paths: + - "k8s/apps/key-rotation-controller/controller/**" + - ".forgejo/workflows/key-rotation-controller.yaml" + workflow_dispatch: + +jobs: + image: + runs-on: golang + steps: + - uses: actions/checkout@v4 + + - name: Log in to the registry + run: | + echo "${{ secrets.GITHUB_TOKEN }}" | \ + docker login forgejo.riotpiao.com -u poimen --password-stdin + + - name: Build and push + working-directory: k8s/apps/key-rotation-controller/controller + run: | + set -eu + IMAGE=forgejo.riotpiao.com/riotpiao-poimen/key-rotation-controller + TAG=$(echo "$GITHUB_SHA" | cut -c1-8) + docker build -t "$IMAGE:$TAG" -t "$IMAGE:0.1.0" . + docker push "$IMAGE:$TAG" + docker push "$IMAGE:0.1.0" + echo "pushed $IMAGE:$TAG and $IMAGE:0.1.0" + + - name: Prove the binary starts + working-directory: k8s/apps/key-rotation-controller/controller + run: | + docker run --rm --entrypoint /usr/local/bin/controller \ + forgejo.riotpiao.com/riotpiao-poimen/key-rotation-controller:0.1.0 --help || true diff --git a/k8s/apps/key-rotation-controller/controller/Dockerfile b/k8s/apps/key-rotation-controller/controller/Dockerfile new file mode 100644 index 0000000..675dc4d --- /dev/null +++ b/k8s/apps/key-rotation-controller/controller/Dockerfile @@ -0,0 +1,13 @@ +# Build stage. The controller has no cgo and no runtime assets, so the final image +# is a static binary on a base with no shell. +FROM golang:1.26 AS build +WORKDIR /src +COPY go.mod go.sum ./ +RUN go mod download +COPY . . +RUN CGO_ENABLED=0 GOOS=linux go build -trimpath -ldflags="-s -w" -o /out/controller . + +FROM gcr.io/distroless/static:nonroot +COPY --from=build /out/controller /usr/local/bin/controller +USER 65532:65532 +ENTRYPOINT ["/usr/local/bin/controller"]