Skip to content

Commit 236640f

Browse files
committed
fix(build): log only the tags a build actually pushes
PUSHED_TAGS_LOG fed every tag to hack/stitch-multiarch.sh whether or not the build pushed it, so a PUSH=0 build, and now a plain LOAD=1 build, handed the stitch tags that were never published. Assisted-by: LLM Signed-off-by: Aleksei Sviridkin <[email protected]>
1 parent cf16b7f commit 236640f

3 files changed

Lines changed: 13 additions & 7 deletions

File tree

‎hack/common-envs.mk‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,11 +119,12 @@ oci-output = $(if $(strip $(OCI_EXPORT_DIR)), --output type=oci$(comma)dest=$(OC
119119
# line. hack/stitch-multiarch.sh moves exactly those tags onto the multi-arch
120120
# index; no ref in the tree names a versioned tag, so this is how it learns
121121
# one was pushed. The append happens when the recipe is expanded, `make -n`
122-
# included, and is skipped under OCI_EXPORT_DIR, which pushes nothing.
122+
# included, and is skipped when the build pushes nothing (PUSH other than 1, or
123+
# OCI_EXPORT_DIR).
123124
image-tag-refs = $(REGISTRY)/$(1):$(IMAGE_TAG)$(if $(strip $(OCI_EXPORT_DIR)),,$(if $(filter 1,$(PUBLISH_VERSIONED)),$(if $(filter-out $(IMAGE_TAG),$(strip $(2))), $(REGISTRY)/$(1):$(strip $(2))))$(if $(filter 1,$(PUBLISH_FLOATING)), $(REGISTRY)/$(1):latest))
124125

125126
define image-tags
126-
$(foreach r,$(call image-tag-refs,$(1),$(2)),--tag $(r))$(call oci-output,$(1))$(if $(and $(strip $(PUSHED_TAGS_LOG)),$(if $(strip $(OCI_EXPORT_DIR)),,1)),$(shell printf '%s\n' $(call image-tag-refs,$(1),$(2)) >>'$(PUSHED_TAGS_LOG)'))
127+
$(foreach r,$(call image-tag-refs,$(1),$(2)),--tag $(r))$(call oci-output,$(1))$(if $(and $(strip $(PUSHED_TAGS_LOG)),$(filter 1,$(PUSH)),$(if $(strip $(OCI_EXPORT_DIR)),,1)),$(shell printf '%s\n' $(call image-tag-refs,$(1),$(2)) >>'$(PUSHED_TAGS_LOG)'))
127128
endef
128129

129130
# cache-args <image-name>

‎hack/common-envs_test.bats‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@
185185
if echo "$tags" | grep -q -- '-$'; then echo "FAIL: a tag ends in '-': $tags"; false; fi
186186
}
187187

188-
@test "image-tags records every tag it pushes in PUSHED_TAGS_LOG, and nothing when unset or exporting" {
188+
@test "image-tags records every tag it pushes in PUSHED_TAGS_LOG, and nothing when unset, exporting or not pushing" {
189189
# The stitch moves exactly these tags onto the multi-arch index. A component
190190
# version pushed under PUBLISH_VERSIONED=1 is named by no ref in the tree, so
191191
# a tag missing here would stay on the amd64-only image.
@@ -200,6 +200,10 @@
200200
make -n -C packages/system/cozystack-controller image IMAGE_TAG=pr-1-abc BUILDER=b \
201201
OCI_EXPORT_DIR=/tmp/ocitest PUSHED_TAGS_LOG="$tmp/export-log" >/dev/null
202202
[ ! -e "$tmp/export-log" ]
203+
# A build that does not push must not hand its tags to the stitch.
204+
LOAD=1 make -n -C packages/system/cozystack-controller image IMAGE_TAG=pr-1-abc BUILDER=b \
205+
PUSHED_TAGS_LOG="$tmp/load-log" >/dev/null
206+
if [ -s "$tmp/load-log" ]; then echo "FAIL: LOAD=1 logs tags it never pushed: $(cat "$tmp/load-log")"; false; fi
203207
rm -rf "$tmp"
204208
}
205209

‎hack/stitch-multiarch.sh‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,11 @@
2121
# if it points at A, so none is left naming the amd64 half alone: <tag>,
2222
# the tag <t> the ref carries, and every <repo>:<tag> line in the file
2323
# PUSHED_TAGS_LOG names. image-tags in hack/common-envs.mk writes that
24-
# log when the variable is set, and it is how the component version
25-
# pushed beside <image-tag> under PUBLISH_VERSIONED=1 is found, since
26-
# most refs name only <image-tag>. These are the only tags read; a tag of
27-
# another build that sits on the same bytes is not this build's to move.
24+
# log when the variable is set and PUSH=1, and it is how the component
25+
# version pushed beside <image-tag> under PUBLISH_VERSIONED=1 is found,
26+
# since most refs name only <image-tag>. These are the only tags read;
27+
# a tag of another build that sits on the same bytes is not this build's
28+
# to move.
2829
# PUSHED_TAGS_LOG set to a file that does not exist fails the run.
2930
# 3. A is replaced with the index digest in the files hack/lib/image-refs.sh
3031
# enumerates, and nowhere else.

0 commit comments

Comments
 (0)