Skip to content

Commit 9d03921

Browse files
authored
Retry docker pulls in CI (#19384)
* Retry docker pulls in CI * Notify caller of retry * Invoke pulls with `-i` * Cleanup retrie default value
1 parent 7bec0d9 commit 9d03921

File tree

2 files changed

+44
-2
lines changed

2 files changed

+44
-2
lines changed

.github/workflows/commands-for-testing-tool.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ jobs:
5555
- name: Set up Docker Buildx
5656
uses: docker/setup-buildx-action@v1
5757
- name: Pull Testing Tool docker image
58-
run: docker pull airbyte/airbyte-e2e-testing-tool:latest
58+
run: ./tools/bin/pull_image.sh -i airbyte/airbyte-e2e-testing-tool:latest
5959
- name: Create input and output folders
6060
run: |
6161
mkdir secrets
@@ -104,7 +104,7 @@ jobs:
104104
- name: Set up Docker Buildx
105105
uses: docker/setup-buildx-action@v1
106106
- name: Pull Testing Tool docker image
107-
run: docker pull airbyte/airbyte-e2e-testing-tool:latest
107+
run: ./tools/bin/pull_image.sh -i airbyte/airbyte-e2e-testing-tool:latest
108108
- name: Change wrapper permissions
109109
run: |
110110
mkdir secrets

tools/bin/pull_image.sh

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#!/usr/bin/env bash
2+
3+
retries=3
4+
5+
function pull_dockerhub_image_with_retries() {
6+
local image=$1
7+
local retries=$2
8+
9+
for (( i=1; i<=$retries; i++ )); do
10+
docker pull $image
11+
# NOTE: this does not discriminate on the failure, any failure will retry
12+
test "$?" -eq 0 && return || echo "Docker pull failed, sleeping for 5 seconds before retrying ($i/$retries)" && sleep 5
13+
done
14+
}
15+
16+
function main() {
17+
while getopts ':i:r:' OPTION; do
18+
case "$OPTION" in
19+
i)
20+
image="$OPTARG"
21+
;;
22+
r)
23+
if [[ "$OPTARG" =~ ^(-)?[0-9]+$ ]]; then
24+
retries="$OPTARG"
25+
else
26+
echo "retries (-r) must be a number" && exit 1
27+
fi
28+
;;
29+
?)
30+
echo "script usage: $(basename "$0") [-i image] [-r retries]" >&2
31+
exit 1
32+
;;
33+
esac
34+
done
35+
shift "$(($OPTIND -1))"
36+
37+
pull_dockerhub_image_with_retries $image $retries
38+
}
39+
40+
main "$@"
41+
42+

0 commit comments

Comments
 (0)