Skip to content

Commit 550be05

Browse files
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 <image-name>` 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 <[email protected]> Co-Authored-By: Claude Opus 4.8 <[email protected]> Signed-off-by: Myasnikov Daniil <[email protected]>
1 parent 5d0f623 commit 550be05

3 files changed

Lines changed: 41 additions & 19 deletions

File tree

‎.github/workflows/pull-requests.yaml‎

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -871,13 +871,21 @@ jobs:
871871
conclusion = 'failure';
872872
summary = `in-tree e2e did not pass (result: ${E2E_RESULT})`;
873873
}
874-
await github.rest.checks.create({
875-
owner: context.repo.owner,
876-
repo: context.repo.repo,
877-
name: 'E2E Tests',
878-
head_sha: HEAD_SHA,
879-
status: 'completed',
880-
conclusion,
881-
output: { title: 'E2E Tests', summary },
882-
});
874+
try {
875+
await github.rest.checks.create({
876+
owner: context.repo.owner,
877+
repo: context.repo.repo,
878+
name: 'E2E Tests',
879+
head_sha: HEAD_SHA,
880+
status: 'completed',
881+
conclusion,
882+
output: { title: 'E2E Tests', summary },
883+
});
884+
} catch (err) {
885+
// The 'E2E Tests' check-run is the required merge gate. If we
886+
// cannot publish it, fail loudly and fail-closed: setFailed keeps
887+
// the job (and thus the gate) red so the PR stays non-mergeable.
888+
core.setFailed(`Failed to report E2E Tests check-run: ${err}`);
889+
return;
890+
}
883891
core.info(`E2E Tests → ${conclusion}: ${summary}`);

‎hack/common-envs.mk‎

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -83,13 +83,27 @@ BUILDX_ARGS := --provenance=false --push=$(PUSH) --load=$(LOAD) \
8383
# for cluster-side pulls; the versioned and floating tags exist for human
8484
# discoverability and downstream tooling on releases.
8585
# When OCI_EXPORT_DIR is set it also appends a per-image `--output type=oci`
86-
# so the build writes <dir>/<name>.oci.tar (the tag becomes the archive's image
87-
# name). Every package's buildx call routes its tags through this macro, so this
88-
# is the single point that turns the whole build into an artifact-export build.
89-
# $(comma) escapes the literal comma so make does not read it as an $(if …)
90-
# argument separator; it is defined below and resolves at $(call) time.
86+
# (via the oci-output macro) so the build writes <dir>/<name>.oci.tar (the tag
87+
# becomes the archive's image name). Every package's buildx call routes its tags
88+
# through this macro, so this is the single point that turns the whole build into
89+
# an artifact-export build — except recipes that bypass image-tags, which must
90+
# call oci-output directly (see #3257).
91+
92+
# comma emits a literal comma inside the lazily-expanded macros below
93+
# (oci-output, cache-args) without make mis-reading it as an $(if …)/$(call …)
94+
# argument separator. Defined here, above its first user, so it is unambiguously
95+
# in scope wherever those macros are $(call)ed from a recipe.
96+
comma := ,
97+
98+
# oci-output <image-name> — when OCI_EXPORT_DIR is set, expands to a per-image
99+
# `--output type=oci,dest=<dir>/<name>.oci.tar`; empty otherwise. EVERY buildx
100+
# call reachable from a fork build must include this — via image-tags, or
101+
# directly for recipes that bypass image-tags (#3257). A missing archive is
102+
# caught loudly by the fork build's `if-no-files-found: error` upload.
103+
oci-output = $(if $(strip $(OCI_EXPORT_DIR)), --output type=oci$(comma)dest=$(OCI_EXPORT_DIR)/$(subst /,-,$(1)).oci.tar)
104+
91105
define image-tags
92-
--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)
106+
--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))
93107
endef
94108

95109
# cache-args <image-name> [<cache-tag>]
@@ -101,9 +115,8 @@ endef
101115
# keep the cache manifest portable across registries (OCIR/ghcr/ECR).
102116
# <cache-tag> defaults to `buildcache`; pass an explicit tag for images that build
103117
# a distinct artifact per loop iteration (e.g. ubuntu-container-disk per k8s ver).
104-
# $(comma) escapes the literal commas in the --cache-to value so make does not
105-
# mis-parse them as $(if ...) argument separators.
106-
comma := ,
118+
# $(comma) (defined above) escapes the literal commas in the --cache-to value so
119+
# make does not mis-parse them as $(if ...) argument separators.
107120
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)
108121

109122
ifeq ($(COZYSTACK_VERSION),)

‎packages/system/capi-providers-cpprovider/Makefile‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ image:
2121
--tag $(IMAGE_BASE):$(IMAGE_TAG) \
2222
--tag $(IMAGE_BASE):$(IMAGE_TAG)-$(TAG) \
2323
--cache-from type=registry,ref=$(IMAGE_BASE):latest \
24-
--cache-to type=inline \
24+
$(if $(strip $(OCI_EXPORT_DIR)),,--cache-to type=inline) \
25+
$(call oci-output,cluster-api-control-plane-provider-kamaji) \
2526
--metadata-file images/cluster-api-control-plane-provider-kamaji.json \
2627
$(BUILDX_ARGS)
2728
digest=$$(yq e '."containerimage.digest"' images/cluster-api-control-plane-provider-kamaji.json -o json -r); \

0 commit comments

Comments
 (0)