ci(cd): call the shared build-image script instead of inlining it (infra#309)
CD / Detect unsubstituted template (push) Successful in 1s
CD / Lint / Test / Vet (push) Skipped
CD / Build & Import (push) Skipped
CD / Deploy via GitOps (push) Skipped

Same change as template-go-agent. A template that carries the build LOGIC
manufactures a private fork of it in every generated repo; one that
carries a CALL manufactures nothing. That distinction is what made
infra#241 a nine-repo sprint plus two rediscoveries in the templates.

Invoked as `bash .gitea/build-image.sh` -- files written through the
Gitea API land 0644, and CI that depends on a file mode is a trap for
every repo generated from here.
This commit is contained in:
2026-08-25 08:53:23 +00:00
parent ef4e47bf00
commit 650644ebe3
+26 -33
View File
@@ -20,6 +20,10 @@ jobs:
- uses: actions/checkout@v4 - uses: actions/checkout@v4
- id: detect - id: detect
run: | run: |
# Grep the PLACEHOLDER, never the value substitution writes. A guard
# that greps its own substituted module path matches forever and
# skips every job below it -- see harg-bygglov-go#8, where that cost
# five weeks of empty green runs on a repo that never compiled.
if grep -q '__MODULE_PATH__' go.mod; then if grep -q '__MODULE_PATH__' go.mod; then
echo "is_template=true" >> "$GITHUB_OUTPUT" echo "is_template=true" >> "$GITHUB_OUTPUT"
else else
@@ -65,40 +69,29 @@ jobs:
SHA=$(git rev-parse --short HEAD) SHA=$(git rev-parse --short HEAD)
echo "sha-tag=${SHA}" >> "$GITHUB_OUTPUT" echo "sha-tag=${SHA}" >> "$GITHUB_OUTPUT"
- name: Build and push to local registry # infra#309: the implementation lives in .gitea/build-image.sh, a
run: | # byte-identical copy of mathias/infra's ci-templates/build-image.sh.
set -e # Do not edit it here -- edit the canonical file, run `task ci:sync`,
# infra#241: buildctl, NOT buildah. Rootless buildah in gitea-runner's # and infra's drift gate will name any repo still carrying an old copy.
# hardened securityContext cannot remap the UID/GID range
# newuidmap/newgidmap need on a fresh base-image pull, and the pod has
# no OCI runtime at all. buildctl talks to the host's buildkitd over a
# socket, so the privileged extraction happens on the host. Same
# pattern as mathias/infra's segment-embedder.yml.
# #
# Highest-leverage place to fix it: every repo generated from this # This matters more in a template than anywhere else: every repo
# template inherits this CI, so a buildah-based template manufactures # generated from here inherits its CI, so a template that carries the
# new instances of the bug. Warm layers mask it, so a generated repo # build LOGIC manufactures a new copy of every bug in it. That is
# builds fine until its first genuinely cold base-image pull. # precisely how rootless buildah (infra#241) reached a dozen repos, and
BUILDKIT_HOST="unix:///run/buildkit/buildkitd.sock" # why the fix then had to be rediscovered here weeks later. A template
REGISTRY="localhost:5000" # that carries a CALL manufactures nothing.
REF="${REGISTRY}/${{ env.IMAGE }}:${{ steps.meta.outputs.sha-tag }}" #
TAR_FILE="$(mktemp)" # NEW REPOS: add yourself to mathias/infra's ci-templates/adopters.txt so
trap 'rm -f "$TAR_FILE"' EXIT # the gate keeps this copy current. Until you do, the copy is unmanaged
# and will silently fall behind.
buildctl --addr "$BUILDKIT_HOST" build \ #
--frontend dockerfile.v0 \ # `bash <script>` rather than executing it directly: files written via
--local context=. \ # the Gitea API land 0644, and CI that depends on a file mode is a trap.
--local dockerfile=. \ - name: Build and push to local registry
--opt label:org.opencontainers.image.revision="${{ github.sha }}" \ env:
--output type=oci,dest="$TAR_FILE" SHA_TAG: ${{ steps.meta.outputs.sha-tag }}
GIT_SHA: ${{ github.sha }}
# buildctl has no registry-push equivalent to `buildah push`; skopeo run: bash .gitea/build-image.sh
# copies the OCI archive up. Twice, to keep the :sha and :latest tags.
skopeo copy --dest-tls-verify=false \
oci-archive:"$TAR_FILE" docker://${REF}
skopeo copy --dest-tls-verify=false \
oci-archive:"$TAR_FILE" docker://${REGISTRY}/${{ env.IMAGE }}:latest
echo "✓ Image pushed to ${REF} and :latest"
deploy: deploy:
name: Deploy via GitOps name: Deploy via GitOps