Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: Fix the docker-clone make target to exit failure. #551

Merged
merged 1 commit into from
Nov 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 2 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
42 changes: 42 additions & 0 deletions tools/oci-copy
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#!/bin/sh
# vi: ts=4 expandtab
Usage() {
cat <<EOF
Usage: ${0##*/} oci-dir image [image [...]]

Copy each 'image' into oci repo in 'oci-dir'.

Example:
${0##*/} ./my-oci.d docker://busybox:latest
EOF
}

stderr() { echo "$@" 1>&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