0
0
#!/usr/bin/env bash
# scripts/oci-pull.sh <host/name@sha256:manifest-digest> <dir>: the artifact scripts/oci-push.sh printed, pulled BY DIGEST with oras (which checks every
# blob against the manifest), a file pushed in parts concatenated back. Each pull is time-boxed (OCI_PULL_TIMEOUT, 600 s), tried twice.
set -euo pipefail
ref=$1 dir=$2
oras=$(bash "$(dirname "${BASH_SOURCE[0]}")/ci-oras.sh")
mkdir -p "$dir"
for attempt in 1 2; do
if timeout "${OCI_PULL_TIMEOUT:-600}" "$oras" pull --no-tty "$ref" -o "$dir"; then
# a file pushed in parts (scripts/oci-push.sh) is put back together: <name>.part-0000, .part-0001, ... in order
for first in "$dir"/*.part-0000; do
[ -e "$first" ] || continue
whole="${first%.part-0000}"
cat "${whole}".part-[0-9][0-9][0-9][0-9] > "$whole" && rm -f "${whole}".part-[0-9][0-9][0-9][0-9]
done
exit 0
fi
echo "oci-pull: attempt $attempt failed" >&2
done
exit 1