Skip to content

Commit

Permalink
Add retries to docker-compose pull
Browse files Browse the repository at this point in the history
  • Loading branch information
PawelLipski committed Jan 15, 2022
1 parent 1882d66 commit 05671cf
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 6 deletions.
4 changes: 2 additions & 2 deletions blogs/docker-ci-tricks-2/blog.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,11 @@ Let's peek into [ci/tox/ci-run.sh](https://github.com/VirtusLab/git-machete/blob
```shell script
# ... skipped ...

source ci/docker-build-and-push.sh tox
source ci/docker-pull-or-build-and-push.sh tox

# ... skipped ...
```
There is no definition of a `DIRECTORY_HASH` in here, but there is an execution of a [ci/docker-build-and-push.sh](https://github.com/VirtusLab/git-machete/blob/develop/ci/docker-build-and-push.sh) with `tox` argument in which we can see the definition:
There is no definition of a `DIRECTORY_HASH` in here, but there is an execution of a [ci/docker-pull-or-build-and-push.sh](https://github.com/VirtusLab/git-machete/blob/develop/ci/docker-pull-or-build-and-push.sh) with `tox` argument in which we can see the definition:

```shell script
# ... skipped ...
Expand Down
2 changes: 1 addition & 1 deletion ci/deb-ppa-upload/ci-deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ else
do_dput=true
fi

source ci/docker-build-and-push.sh deb-ppa-upload
source ci/docker-pull-or-build-and-push.sh deb-ppa-upload

docker-compose --ansi never run -e TARGET_DISTRO_NAME=bionic -e TARGET_DISTRO_NUMBER=18.04 -e DO_DPUT=$do_dput deb-ppa-upload
docker-compose --ansi never run -e TARGET_DISTRO_NAME=focal -e TARGET_DISTRO_NUMBER=20.04 -e DO_DPUT=$do_dput deb-ppa-upload
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,26 @@ DIRECTORY_HASH=$(git rev-parse HEAD:ci/$image_name)
export DIRECTORY_HASH
cd ci/$image_name/

function retry() {
attempts=$1
interval=10
for i in $(seq 1 $attempts); do
if "${@:2}"; then break; fi

echo "Attempt #$i out of $attempts at command '$*' failed"
if [[ $i -lt $attempts ]]; then
echo "Sleeping $interval seconds..."
sleep $interval
fi
done
}

# If image is not found by pull, build the image and push it to the Docker Hub.
docker-compose --ansi never pull $image_name

# Let's retry pulling the image in case of a spurious failure
# (`error pulling image configuration: Get "https://docker-images-prod.s3.dualstack.us-east-1.amazonaws.com/...": dial tcp ...:443: i/o timeout`)
retry 3 docker-compose --ansi never pull $image_name

# A very unpleasant workaround for https://github.com/docker/compose/issues/7258
# (since v1.25.1, `docker-compose pull` is NOT failing when it can't fetch the image).
image_tag=$(docker-compose --ansi never config | yq eval ".services.$image_name.image" -)
Expand Down
2 changes: 1 addition & 1 deletion ci/rpm/ci-run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

set -e -o pipefail -u -x

source ci/docker-build-and-push.sh rpm
source ci/docker-pull-or-build-and-push.sh rpm

docker-compose --ansi never run rpm
2 changes: 1 addition & 1 deletion ci/tox/ci-run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

set -e -o pipefail -u -x

source ci/docker-build-and-push.sh tox
source ci/docker-pull-or-build-and-push.sh tox

docker-compose --ansi never run tox

0 comments on commit 05671cf

Please sign in to comment.