ci(cd): build with buildctl instead of rootless buildah (infra#241)
Rootless buildah in the containerized gitea-runner pod cannot remap UID/GID on a fresh base-image pull and has no OCI runtime, so this Dockerfile's `RUN apk add` / `RUN go build` cannot execute there at all. The last green run here (2026-07-22) predates the runner's containerization (infra#233, 2026-07-29), so the build has been latently broken since. buildctl hands the build to koala's host buildkitd over the socket the pod already mounts; skopeo pushes the resulting OCI archive once per tag, since buildctl has no `buildah push` equivalent. The VERSION build-arg carries over as `--opt build-arg:VERSION=`, so the ldflags version stamp is unchanged. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011PL5XcG68SvQqz3vGVbWbf
This commit is contained in:
+38
-14
@@ -62,24 +62,48 @@ jobs:
|
|||||||
|
|
||||||
- name: Build and push to local registry
|
- name: Build and push to local registry
|
||||||
run: |
|
run: |
|
||||||
|
set -e
|
||||||
|
# infra#241: buildctl, not buildah. 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 -- so this Dockerfile's `RUN apk add` / `RUN go
|
||||||
|
# build` could not execute there either. buildctl is a thin client
|
||||||
|
# that hands the build to the host's buildkitd over a socket, so the
|
||||||
|
# privileged layer work happens on the host and this pod's
|
||||||
|
# securityContext stops being in the picture. Same pattern as
|
||||||
|
# mathias/infra's segment-embedder.yml.
|
||||||
|
BUILDKIT_HOST="unix:///run/buildkit/buildkitd.sock"
|
||||||
REGISTRY="localhost:5000"
|
REGISTRY="localhost:5000"
|
||||||
REF="${REGISTRY}/${{ env.IMAGE }}:${{ steps.meta.outputs.sha-tag }}"
|
REF="${REGISTRY}/${{ env.IMAGE }}:${{ steps.meta.outputs.sha-tag }}"
|
||||||
# Stamp the real build version: the git tag on a v* build, else the short sha.
|
# Stamp the real build version: the git tag on a v* build, else the short sha.
|
||||||
VERSION="${{ steps.meta.outputs.version-tag }}"
|
VERSION="${{ steps.meta.outputs.version-tag }}"
|
||||||
[ -z "$VERSION" ] && VERSION="${{ steps.meta.outputs.sha-tag }}"
|
# `if`, not `[ -z ] &&`: under `set -e` the && form exits the step
|
||||||
buildah build \
|
# whenever VERSION is already set.
|
||||||
--build-arg VERSION="${VERSION}" \
|
if [ -z "$VERSION" ]; then VERSION="${{ steps.meta.outputs.sha-tag }}"; fi
|
||||||
--label "org.opencontainers.image.revision=${{ github.sha }}" \
|
TAR_FILE="$(mktemp)"
|
||||||
--label "org.opencontainers.image.source=${{ github.repositoryUrl }}" \
|
trap 'rm -f "$TAR_FILE"' EXIT
|
||||||
-t ${REF} \
|
|
||||||
-t ${REGISTRY}/${{ env.IMAGE }}:latest \
|
buildctl --addr "$BUILDKIT_HOST" build \
|
||||||
.
|
--frontend dockerfile.v0 \
|
||||||
buildah push --tls-verify=false ${REF}
|
--local context=. \
|
||||||
buildah push --tls-verify=false ${REGISTRY}/${{ env.IMAGE }}:latest
|
--local dockerfile=. \
|
||||||
[[ -n "${{ steps.meta.outputs.version-tag }}" ]] && \
|
--opt build-arg:VERSION="${VERSION}" \
|
||||||
buildah push --tls-verify=false \
|
--opt label:org.opencontainers.image.revision="${{ github.sha }}" \
|
||||||
${REF} \
|
--opt label:org.opencontainers.image.source="${{ github.repositoryUrl }}" \
|
||||||
${REGISTRY}/${{ env.IMAGE }}:${{ steps.meta.outputs.version-tag }} || true
|
--output type=oci,dest="$TAR_FILE"
|
||||||
|
|
||||||
|
# buildctl has no registry-push equivalent to `buildah push`; skopeo
|
||||||
|
# copies the OCI archive up, once per tag.
|
||||||
|
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
|
||||||
|
if [ -n "${{ steps.meta.outputs.version-tag }}" ]; then
|
||||||
|
skopeo copy --dest-tls-verify=false \
|
||||||
|
oci-archive:"$TAR_FILE" \
|
||||||
|
docker://${REGISTRY}/${{ env.IMAGE }}:${{ steps.meta.outputs.version-tag }}
|
||||||
|
fi
|
||||||
echo "✓ Image pushed to ${REF}"
|
echo "✓ Image pushed to ${REF}"
|
||||||
|
|
||||||
- name: Smoke test
|
- name: Smoke test
|
||||||
|
|||||||
Reference in New Issue
Block a user