Template
ci: build with buildctl instead of buildah (infra#241)
Rootless buildah in gitea-runner's hardened securityContext (capabilities:
drop [ALL], allowPrivilegeEscalation: false) 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 layer extraction happens on the host and the pod's securityContext
stops being in the picture. Same pattern as mathias/infra's segment-embedder.yml.
A template is the highest-leverage place to fix this: every repo generated from
here inherits its CI, so a buildah-based template does not merely carry the bug,
it manufactures new instances. The failure is latent — warm base-image layers
mask it — so a generated repo builds fine until its first genuinely cold pull,
which is precisely the situation a new repo is in.
Verification is PARTIAL here, and the limit is worth stating rather than
implying a green build. Running the exact command against this repo's real
context reaches step 8 and fails inside the Dockerfile:
RUN templ generate && go build ... -o /out/app ./cmd/__PROJECT_NAME__
error: failed to solve: ... exit code: 1
That failure is the template's own placeholder path, which cannot resolve on the
raw template — the same reason the guard job gates check/build/deploy off here
(is_template detects __MODULE_PATH__ in go.mod). What it does prove is that
buildctl resolved the frontend, the context and the Dockerfile and began
executing stages; every part of the buildctl integration worked, and only the
template's unsubstituted content did not.
template-go-agent's Dockerfile has no placeholder in its build path, so there the
same command produced a complete 6.8MB OCI archive. The first generated repo from
this template is where this one gets its end-to-end proof.
skopeo copy replaces `buildah push` — buildctl has no registry-push equivalent —
and runs twice to preserve the :sha and :latest tags.
This commit is contained in:
+30
-8
@@ -67,16 +67,38 @@ jobs:
|
||||
|
||||
- name: Build and push to local registry
|
||||
run: |
|
||||
set -e
|
||||
# infra#241: buildctl, NOT buildah. Rootless buildah in gitea-runner's
|
||||
# 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
|
||||
# template inherits this CI, so a buildah-based template manufactures
|
||||
# new instances of the bug. Warm layers mask it, so a generated repo
|
||||
# builds fine until its first genuinely cold base-image pull.
|
||||
BUILDKIT_HOST="unix:///run/buildkit/buildkitd.sock"
|
||||
REGISTRY="localhost:5000"
|
||||
REF="${REGISTRY}/${{ env.IMAGE }}:${{ steps.meta.outputs.sha-tag }}"
|
||||
buildah build \
|
||||
--label "org.opencontainers.image.revision=${{ github.sha }}" \
|
||||
-t ${REF} \
|
||||
-t ${REGISTRY}/${{ env.IMAGE }}:latest \
|
||||
.
|
||||
buildah push --tls-verify=false ${REF}
|
||||
buildah push --tls-verify=false ${REGISTRY}/${{ env.IMAGE }}:latest
|
||||
echo "✓ Image pushed to ${REF}"
|
||||
TAR_FILE="$(mktemp)"
|
||||
trap 'rm -f "$TAR_FILE"' EXIT
|
||||
|
||||
buildctl --addr "$BUILDKIT_HOST" build \
|
||||
--frontend dockerfile.v0 \
|
||||
--local context=. \
|
||||
--local dockerfile=. \
|
||||
--opt label:org.opencontainers.image.revision="${{ github.sha }}" \
|
||||
--output type=oci,dest="$TAR_FILE"
|
||||
|
||||
# buildctl has no registry-push equivalent to `buildah push`; skopeo
|
||||
# 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:
|
||||
name: Deploy via GitOps
|
||||
|
||||
Reference in New Issue
Block a user