-
Notifications
You must be signed in to change notification settings - Fork 45
[code-simplifier] Simplify docker pull retry loop in download_docker_images.sh #13781
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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 | ||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for attempt in $(seq 1 $max_attempts)adds an externalseqdependency and relies on command-substitution word splitting. Since this is a bash script, prefer a built-in arithmetic loop (e.g., a C-stylefor ((...))) to avoid the extra process and make the iteration semantics clearer. If you keepseq, at least quote$max_attemptsto avoid globbing/word-splitting issues and SC2086 warnings.