Skip to content

Commit

Permalink
Optionally log in to DockerHub during healthchecks
Browse files Browse the repository at this point in the history
This will help avoid rate limiting by DockerHub.

Change-type: patch
Signed-off-by: Kyle Harding <kyle@balena.io>
  • Loading branch information
klutchell committed Nov 16, 2023
1 parent 002ecd5 commit e49608b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
9 changes: 9 additions & 0 deletions docker-compose.test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ services:
cache_from:
- sut:latest
hostname: alpine-test
environment:
- DOCKERHUB_USERNAME=${DOCKERHUB_USERNAME:-}
- DOCKERHUB_PASSWORD=${DOCKERHUB_PASSWORD:-}

debian-test:
extends:
Expand All @@ -72,6 +75,9 @@ services:
cache_from:
- sut:latest
hostname: debian-test
environment:
- DOCKERHUB_USERNAME=${DOCKERHUB_USERNAME:-}
- DOCKERHUB_PASSWORD=${DOCKERHUB_PASSWORD:-}

ubuntu-test:
extends:
Expand All @@ -84,3 +90,6 @@ services:
cache_from:
- sut:latest
hostname: ubuntu-test
environment:
- DOCKERHUB_USERNAME=${DOCKERHUB_USERNAME:-}
- DOCKERHUB_PASSWORD=${DOCKERHUB_PASSWORD:-}
7 changes: 6 additions & 1 deletion test/healthcheck.sh
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,11 @@ if command -v dockerd >/dev/null 2>&1; then
# run the client tests when running as nonroot
docker version
docker info

if [ -n "${DOCKERHUB_USERNAME}" ] && [ -n "${DOCKERHUB_PASSWORD}" ]; then
echo "${DOCKERHUB_PASSWORD}" | docker login --username "${DOCKERHUB_USERNAME}" --password-stdin
fi

docker run --rm hello-world
docker pull --platform linux/arm/v7 arm32v7/hello-world

Expand Down Expand Up @@ -103,7 +108,7 @@ fi
case $(id -u) in
"0")
# re-run healthchecks as nonroot user
exec su - nonroot -c /test/healthcheck.sh
exec su - nonroot -c "DOCKERHUB_USERNAME=${DOCKERHUB_USERNAME} DOCKERHUB_PASSWORD=${DOCKERHUB_PASSWORD} /test/healthcheck.sh"
;;
*)
# print the nonroot user id and continue to finish the healthchecks
Expand Down

0 comments on commit e49608b

Please sign in to comment.