diff --git a/actions/setup/sh/download_docker_images.sh b/actions/setup/sh/download_docker_images.sh index de51f0119e..704b1f9ead 100755 --- a/actions/setup/sh/download_docker_images.sh +++ b/actions/setup/sh/download_docker_images.sh @@ -16,34 +16,33 @@ set -euo pipefail docker_pull_with_retry() { local image="$1" local max_attempts=3 - local attempt=1 local wait_time=5 - while [ $attempt -le $max_attempts ]; do + for attempt in $(seq 1 $max_attempts); do echo "Attempt $attempt of $max_attempts: Pulling $image..." - timeout 5m docker pull --quiet "$image" 2>&1 - local exit_code=$? - if [ $exit_code -eq 0 ]; then + if timeout 5m docker pull --quiet "$image" 2>&1; then echo "Successfully pulled $image" return 0 fi - # Check if the command timed out (exit code 124 from timeout command) + local exit_code=$? + + # Timeout produces exit code 124 if [ $exit_code -eq 124 ]; then - echo "docker pull timed out for $image" + echo "docker pull timed out for $image after 5 minutes" return 1 fi - if [ $attempt -lt $max_attempts ]; then + # Retry with exponential backoff unless this was the last attempt + if [ "$attempt" -lt "$max_attempts" ]; then echo "Failed to pull $image. Retrying in ${wait_time}s..." sleep $wait_time - wait_time=$((wait_time * 2)) # Exponential backoff + wait_time=$((wait_time * 2)) else echo "Failed to pull $image after $max_attempts attempts" return 1 fi - attempt=$((attempt + 1)) done }