From 76c8f890fa88ed6d47a15f68aca6f342c46fa813 Mon Sep 17 00:00:00 2001 From: Myasnikov Daniil Date: Thu, 9 Jul 2026 18:36:50 +0500 Subject: [PATCH] fix(ci): export OCI archives for buildx calls that bypass image-tags (#3257) Fork PRs build images to per-image OCI archives instead of pushing, gated on OCI_EXPORT_DIR. The `--output type=oci` was appended only inside the `image-tags` macro, so `packages/system/capi-providers-cpprovider`, whose `image:` recipe uses a hardcoded `--tag` and never calls `image-tags`, ran buildx with no exporter under export mode (PUSH/LOAD forced to 0). No archive was written, and the fork build's `if-no-files-found: error` upload then failed the whole build. Its `--cache-to type=inline` also needs an image exporter. - hack/common-envs.mk: extract the OCI-output snippet from `image-tags` into a reusable `oci-output ` macro so any buildx call can opt in; `image-tags` now ends with `$(call oci-output,$(1))` (no-op for the ~33 conforming packages). Move `comma :=` above its first user. - packages/system/capi-providers-cpprovider/Makefile: add `$(call oci-output,cluster-api-control-plane-provider-kamaji)` (archive base name equals the OCIR repo the privileged push keys on) and drop the inline cache under export (`--cache-to type=inline` gated off). - .github/workflows/pull-requests.yaml: wrap the `E2E Tests` check-run creation in try/catch. On error, `core.setFailed` so the required merge gate fails loudly and fail-closed instead of silently succeeding. Repo-wide audit of every `docker buildx build` reachable from the root `build:` matrix confirms capi was the only recipe bypassing both `image-tags` and `oci-output`. Assisted-By: Claude Co-Authored-By: Claude Opus 4.8 Signed-off-by: Myasnikov Daniil --- .github/workflows/pull-requests.yaml | 26 ++++++++++------ hack/common-envs.mk | 31 +++++++++++++------ .../system/capi-providers-cpprovider/Makefile | 3 +- 3 files changed, 41 insertions(+), 19 deletions(-) diff --git a/.github/workflows/pull-requests.yaml b/.github/workflows/pull-requests.yaml index 7ba15b80b..12131568c 100644 --- a/.github/workflows/pull-requests.yaml +++ b/.github/workflows/pull-requests.yaml @@ -917,13 +917,21 @@ jobs: conclusion = 'failure'; summary = `in-tree e2e did not pass (result: ${E2E_RESULT})`; } - await github.rest.checks.create({ - owner: context.repo.owner, - repo: context.repo.repo, - name: 'E2E Tests', - head_sha: HEAD_SHA, - status: 'completed', - conclusion, - output: { title: 'E2E Tests', summary }, - }); + try { + await github.rest.checks.create({ + owner: context.repo.owner, + repo: context.repo.repo, + name: 'E2E Tests', + head_sha: HEAD_SHA, + status: 'completed', + conclusion, + output: { title: 'E2E Tests', summary }, + }); + } catch (err) { + // The 'E2E Tests' check-run is the required merge gate. If we + // cannot publish it, fail loudly and fail-closed: setFailed keeps + // the job (and thus the gate) red so the PR stays non-mergeable. + core.setFailed(`Failed to report E2E Tests check-run: ${err}`); + return; + } core.info(`E2E Tests → ${conclusion}: ${summary}`); diff --git a/hack/common-envs.mk b/hack/common-envs.mk index a4cc20868..8c48ff2af 100644 --- a/hack/common-envs.mk +++ b/hack/common-envs.mk @@ -83,13 +83,27 @@ BUILDX_ARGS := --provenance=false --push=$(PUSH) --load=$(LOAD) \ # for cluster-side pulls; the versioned and floating tags exist for human # discoverability and downstream tooling on releases. # When OCI_EXPORT_DIR is set it also appends a per-image `--output type=oci` -# so the build writes /.oci.tar (the tag becomes the archive's image -# name). Every package's buildx call routes its tags through this macro, so this -# is the single point that turns the whole build into an artifact-export build. -# $(comma) escapes the literal comma so make does not read it as an $(if …) -# argument separator; it is defined below and resolves at $(call) time. +# (via the oci-output macro) so the build writes /.oci.tar (the tag +# becomes the archive's image name). Every package's buildx call routes its tags +# through this macro, so this is the single point that turns the whole build into +# an artifact-export build — except recipes that bypass image-tags, which must +# call oci-output directly (see #3257). + +# comma emits a literal comma inside the lazily-expanded macros below +# (oci-output, cache-args) without make mis-reading it as an $(if …)/$(call …) +# argument separator. Defined here, above its first user, so it is unambiguously +# in scope wherever those macros are $(call)ed from a recipe. +comma := , + +# oci-output — when OCI_EXPORT_DIR is set, expands to a per-image +# `--output type=oci,dest=/.oci.tar`; empty otherwise. EVERY buildx +# call reachable from a fork build must include this — via image-tags, or +# directly for recipes that bypass image-tags (#3257). A missing archive is +# caught loudly by the fork build's `if-no-files-found: error` upload. +oci-output = $(if $(strip $(OCI_EXPORT_DIR)), --output type=oci$(comma)dest=$(OCI_EXPORT_DIR)/$(subst /,-,$(1)).oci.tar) + define image-tags ---tag $(REGISTRY)/$(1):$(IMAGE_TAG)$(if $(filter 1,$(PUBLISH_VERSIONED)),$(if $(filter-out $(IMAGE_TAG),$(strip $(2))), --tag $(REGISTRY)/$(1):$(strip $(2))))$(if $(filter 1,$(PUBLISH_FLOATING)), --tag $(REGISTRY)/$(1):latest)$(if $(strip $(OCI_EXPORT_DIR)), --output type=oci$(comma)dest=$(OCI_EXPORT_DIR)/$(subst /,-,$(1)).oci.tar) +--tag $(REGISTRY)/$(1):$(IMAGE_TAG)$(if $(filter 1,$(PUBLISH_VERSIONED)),$(if $(filter-out $(IMAGE_TAG),$(strip $(2))), --tag $(REGISTRY)/$(1):$(strip $(2))))$(if $(filter 1,$(PUBLISH_FLOATING)), --tag $(REGISTRY)/$(1):latest)$(call oci-output,$(1)) endef # cache-args [] @@ -101,9 +115,8 @@ endef # keep the cache manifest portable across registries (OCIR/ghcr/ECR). # defaults to `buildcache`; pass an explicit tag for images that build # a distinct artifact per loop iteration (e.g. ubuntu-container-disk per k8s ver). -# $(comma) escapes the literal commas in the --cache-to value so make does not -# mis-parse them as $(if ...) argument separators. -comma := , +# $(comma) (defined above) escapes the literal commas in the --cache-to value so +# make does not mis-parse them as $(if ...) argument separators. cache-args = --cache-from type=registry,ref=$(CACHE_REGISTRY)/$(1):$(if $(2),$(2),buildcache)$(if $(filter 1,$(WRITE_CACHE)), --cache-to type=registry$(comma)ref=$(CACHE_REGISTRY)/$(1):$(if $(2),$(2),buildcache)$(comma)mode=max$(comma)oci-mediatypes=true$(comma)image-manifest=true) ifeq ($(COZYSTACK_VERSION),) diff --git a/packages/system/capi-providers-cpprovider/Makefile b/packages/system/capi-providers-cpprovider/Makefile index 0f8be6c97..12bf5b535 100644 --- a/packages/system/capi-providers-cpprovider/Makefile +++ b/packages/system/capi-providers-cpprovider/Makefile @@ -21,7 +21,8 @@ image: --tag $(IMAGE_BASE):$(IMAGE_TAG) \ --tag $(IMAGE_BASE):$(IMAGE_TAG)-$(TAG) \ --cache-from type=registry,ref=$(IMAGE_BASE):latest \ - --cache-to type=inline \ + $(if $(strip $(OCI_EXPORT_DIR)),,--cache-to type=inline) \ + $(call oci-output,cluster-api-control-plane-provider-kamaji) \ --metadata-file images/cluster-api-control-plane-provider-kamaji.json \ $(BUILDX_ARGS) digest=$$(yq e '."containerimage.digest"' images/cluster-api-control-plane-provider-kamaji.json -o json -r); \