Skip to content
Closed
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
33 changes: 32 additions & 1 deletion hack/bin/upload-image.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,37 @@ if [[ "${DOCKER_USER+x}" != "" ]]; then
credsArgs="--dest-creds=$DOCKER_USER:$DOCKER_PASSWORD"
fi

# Retry a command with exponential backoff
# quay.io sometimes rate-limits us, so try again...
function retry {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

local maxAttempts=$1
local secondsDelay=1
local attemptCount=1
local output=
shift 1

while [ $attemptCount -le "$maxAttempts" ]; do
output=$("$@")
local status=$?

if [ $status -eq 0 ]; then
break
fi

if [ $attemptCount -lt "$maxAttempts" ]; then
echo "Command [$*] failed after attempt $attemptCount of $maxAttempts. Retrying in $secondsDelay second(s)." >&2
sleep $secondsDelay
elif [ $attemptCount -eq "$maxAttempts" ]; then
echo "Command [$*] failed after $attemptCount attempt(s)" >&2
return $status
fi
attemptCount=$((attemptCount + 1))
secondsDelay=$((secondsDelay * 2))
done

echo "$output"
}

tmp_link_store=$(mktemp -d)
# Using dockerTools.streamLayeredImage outputs an executable which prints the
# image tar on stdout when executed. This is done so we don't store large images
Expand All @@ -42,4 +73,4 @@ image_file="$tmp_link_store/image"
repo=$(skopeo list-tags "docker-archive://$image_file" | jq -r '.Tags[0] | split(":") | .[0]')
printf "*** Uploading $image_file to %s:%s" "$repo" "$DOCKER_TAG"
# shellcheck disable=SC2086
skopeo --insecure-policy copy $credsArgs "docker-archive://$image_file" "docker://$repo:$DOCKER_TAG"
retry 5 skopeo --insecure-policy copy $credsArgs "docker-archive://$image_file" "docker://$repo:$DOCKER_TAG"