Skip to content

Commit 81a6df9

Browse files
committed
ci: introducing-jitter
1 parent 26601c8 commit 81a6df9

2 files changed

Lines changed: 50 additions & 1 deletion

File tree

‎.github/workflows/test-on-push-and-pr.yml‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,15 @@ jobs:
189189
name: "${{ matrix.distro }} ${{ matrix.distro_version }} / python ${{ matrix.runtime_version }}"
190190

191191
steps:
192+
- name: Jitter start (stagger matrix shards to spare public.ecr.aws rate limit)
193+
# Every shard is scheduled within milliseconds of the others and pulls
194+
# its base images from public.ecr.aws inside the same rate-limit window,
195+
# so together they trip the throttle (429 Too Many Requests).
196+
run: |
197+
jitter=$((RANDOM % 61))
198+
echo "Sleeping ${jitter}s to stagger this shard"
199+
sleep "${jitter}"
200+
192201
- uses: actions/checkout@v4
193202

194203
- name: Extract RIE
@@ -215,7 +224,7 @@ jobs:
215224
echo "RUN apk add curl" >> "$TMPFILE"
216225
fi
217226
echo "COPY .scratch/${RIE} /usr/bin/${RIE}" >> "$TMPFILE"
218-
docker build . \
227+
tests/integration/docker-retry.sh docker build . \
219228
-f "$TMPFILE" \
220229
-t ric-test \
221230
--build-arg RUNTIME_VERSION=${{ matrix.runtime_version }} \

‎tests/integration/docker-retry.sh‎

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#!/bin/bash
2+
# Copyright 2026 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
#
4+
# Run a docker command, retrying when it fails (e.g. public.ecr.aws throttling
5+
# the base image pulls with "429 Too Many Requests").
6+
# Usage: docker-retry.sh <command> [args...]
7+
8+
set -uo pipefail
9+
10+
# Ladder of base wait times (in seconds) between successive attempts.
11+
# Default: 1 min, 2 min, 5 min — 4 attempts total (initial + 3 retries).
12+
# public.ecr.aws rate-limit windows recover on a minute-scale timer, so short
13+
# exponential backoff tends to exhaust its budget before the slot reopens.
14+
IFS=' ' read -r -a DELAYS <<< "${RETRY_DELAYS:-60 120 300}"
15+
JITTER_MAX="${RETRY_JITTER_MAX:-30}"
16+
MAX_ATTEMPTS=$(( ${#DELAYS[@]} + 1 ))
17+
18+
if (( $# == 0 )); then
19+
>&2 echo "usage: docker-retry.sh <command> [args...]"
20+
exit 2
21+
fi
22+
23+
attempt=1
24+
while true; do
25+
"$@"
26+
status=$?
27+
if (( status == 0 || attempt >= MAX_ATTEMPTS )); then
28+
exit "$status"
29+
fi
30+
31+
# Base delay from the ladder + additive jitter in [0, JITTER_MAX] so
32+
# concurrent shards don't retry in the exact same second.
33+
base=${DELAYS[$((attempt - 1))]}
34+
jitter=$(( RANDOM % (JITTER_MAX + 1) ))
35+
delay=$(( base + jitter ))
36+
37+
>&2 echo "docker-retry: '$*' failed (exit ${status}); attempt ${attempt}/${MAX_ATTEMPTS}, retrying in ${delay}s (${base}s + ${jitter}s jitter)."
38+
sleep "$delay"
39+
attempt=$(( attempt + 1 ))
40+
done

0 commit comments

Comments
 (0)