1
0
mirror of synced 2025-12-30 12:04:43 -05:00
Files
airbyte/tools/bin/pull_image.sh
perangel 9d03921908 Retry docker pulls in CI (#19384)
* Retry docker pulls in CI

* Notify caller of retry

* Invoke pulls with `-i`

* Cleanup retrie default value
2022-11-16 13:44:21 -05:00

43 lines
1.0 KiB
Bash
Executable File

#!/usr/bin/env bash
retries=3
function pull_dockerhub_image_with_retries() {
local image=$1
local retries=$2
for (( i=1; i<=$retries; i++ )); do
docker pull $image
# NOTE: this does not discriminate on the failure, any failure will retry
test "$?" -eq 0 && return || echo "Docker pull failed, sleeping for 5 seconds before retrying ($i/$retries)" && sleep 5
done
}
function main() {
while getopts ':i:r:' OPTION; do
case "$OPTION" in
i)
image="$OPTARG"
;;
r)
if [[ "$OPTARG" =~ ^(-)?[0-9]+$ ]]; then
retries="$OPTARG"
else
echo "retries (-r) must be a number" && exit 1
fi
;;
?)
echo "script usage: $(basename "$0") [-i image] [-r retries]" >&2
exit 1
;;
esac
done
shift "$(($OPTIND -1))"
pull_dockerhub_image_with_retries $image $retries
}
main "$@"