From b0bedb01c8b4eb457fd0416f2d17bfc64ea2e987 Mon Sep 17 00:00:00 2001 From: Scott Moser Date: Wed, 15 Nov 2023 10:38:37 -0500 Subject: [PATCH] test: Fix the docker-clone make target to exit failure. My expectation was that when make invoked the shell (sh) for a line in a rule was that it did so with '-e'. That was an incorrect assumption. The make docker-clone target was basically doing: for i in url1 url2 url3; do something $i; done The failure of the *last* item in the list should cause the command to exit failure, but failure of an earlier command would not. The change here is just to move that shell code into a script in tools/oci-copy and call it from there. Signed-off-by: Scott Moser --- Makefile | 10 ++-------- tools/oci-copy | 42 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+), 8 deletions(-) create mode 100755 tools/oci-copy diff --git a/Makefile b/Makefile index 5dd54a16..5f7ddea9 100644 --- a/Makefile +++ b/Makefile @@ -142,16 +142,10 @@ test: stacker $(REGCLIENT) $(SKOPEO) $(ZOT) $(patsubst %,test/%.bats,$(TEST)) -CLONE_D = $(BUILD_D)/oci-clone -CLONE_RETRIES = 3 .PHONY: docker-clone docker-clone: - mkdir -p $(CLONE_D) - vr() { echo "$$" "$$@" 1>&2; "$$@"; }; \ - for u in $(STACKER_BUILD_IMAGES); do \ - name=$${u$(HASH)$(HASH)*/}; \ - vr skopeo copy --retry-times $(CLONE_RETRIES) "$$u" "oci:$(CLONE_D):$${name}"; \ - done + ./tools/oci-copy "$(BUILD_D)/oci-clone" $(STACKER_BUILD_IMAGES) + .PHONY: show-info show-info: diff --git a/tools/oci-copy b/tools/oci-copy new file mode 100755 index 00000000..56019045 --- /dev/null +++ b/tools/oci-copy @@ -0,0 +1,42 @@ +#!/bin/sh +# vi: ts=4 expandtab +Usage() { + cat <&2; } + +fail() { [ $# -eq 0 ] || stderr "$@"; exit 1; } + +vr() { + stderr "$" "$@" + "$@" && return 0 + fail "FAIL[$?]: $*" +} + +[ "$1" = "-h" ] || [ "$1" = "--help" ] && { Usage; exit 0; } +[ $# -ge 2 ] || { + Usage 1>&2; + fail "Got $# args, expected 2 or more"; +} + +oci_d="$1" +shift + +command -v skopeo >/dev/null 2>&1 || + fail "no 'skopeo' in PATH" + +mkdir -p "$oci_d" || fail "failed to create dir '$oci_d'" +for url in "$@"; do + name=${url##*/}; + vr skopeo copy --retry-times=3 "$url" "oci:${oci_d}:$name" || + fail "Failed to copy '$url' to 'oci:${oci_d}:$name'" +done +exit 0