mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 13:40:44 +00:00
ci: avoid unnecessary docker image pulls
This commit is contained in:
42
scripts/ci-docker-pull-retry.sh
Normal file
42
scripts/ci-docker-pull-retry.sh
Normal file
@@ -0,0 +1,42 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
if [[ "$#" -ne 1 || -z "${1// }" ]]; then
|
||||
echo "usage: $0 <image>" >&2
|
||||
exit 2
|
||||
fi
|
||||
|
||||
image="$1"
|
||||
attempts="${OPENCLAW_DOCKER_PULL_ATTEMPTS:-3}"
|
||||
timeout_seconds="${OPENCLAW_DOCKER_PULL_TIMEOUT_SECONDS:-480}"
|
||||
retry_delay_seconds="${OPENCLAW_DOCKER_PULL_RETRY_DELAY_SECONDS:-20}"
|
||||
|
||||
if ! [[ "$attempts" =~ ^[1-9][0-9]*$ ]]; then
|
||||
echo "OPENCLAW_DOCKER_PULL_ATTEMPTS must be a positive integer, got: $attempts" >&2
|
||||
exit 2
|
||||
fi
|
||||
|
||||
if ! [[ "$timeout_seconds" =~ ^[1-9][0-9]*$ ]]; then
|
||||
echo "OPENCLAW_DOCKER_PULL_TIMEOUT_SECONDS must be a positive integer, got: $timeout_seconds" >&2
|
||||
exit 2
|
||||
fi
|
||||
|
||||
if ! [[ "$retry_delay_seconds" =~ ^[0-9]+$ ]]; then
|
||||
echo "OPENCLAW_DOCKER_PULL_RETRY_DELAY_SECONDS must be a non-negative integer, got: $retry_delay_seconds" >&2
|
||||
exit 2
|
||||
fi
|
||||
|
||||
last_status=1
|
||||
for attempt in $(seq 1 "$attempts"); do
|
||||
echo "==> Pull Docker image attempt ${attempt}/${attempts}: ${image}"
|
||||
if timeout --foreground --kill-after=30s "${timeout_seconds}s" docker pull "$image"; then
|
||||
exit 0
|
||||
fi
|
||||
last_status="$?"
|
||||
echo "Docker pull failed or timed out after ${timeout_seconds}s: status=${last_status}" >&2
|
||||
if [[ "$attempt" -lt "$attempts" && "$retry_delay_seconds" -gt 0 ]]; then
|
||||
sleep "$retry_delay_seconds"
|
||||
fi
|
||||
done
|
||||
|
||||
exit "$last_status"
|
||||
Reference in New Issue
Block a user