[ubuntu] feat(docker): authenticate using DockerHub credentials (#2548)

Ubuntu builds, by default, pull images anonymously from the
official DockerHub. DockerHub rate limits requests from
anonymous and unpaid accounts:
- https://docs.docker.com/docker-hub/download-rate-limit/

When those rate limits are reached the Packer build will
fail with an error indicated the rate limit has been
reached.

Add support for providing credentials for a paid
account that can be used by the Docker setup steps to
authenticate when pulling images from DockerHub, thereby
avoiding the rate limit.

Related to #2094
This commit is contained in:
Hutson Betts
2021-01-28 04:31:45 -06:00
committed by GitHub
parent e2d6b1632b
commit 46e0c05e7e
4 changed files with 66 additions and 13 deletions

View File

@@ -28,10 +28,21 @@ systemctl is-enabled --quiet docker.service || systemctl enable docker.service
sleep 10
docker info
# If credentials are provided, attempt to log into Docker Hub
# with a paid account to avoid Docker Hub's rate limit.
if [ "${DOCKERHUB_LOGIN}" ] && [ "${DOCKERHUB_PASSWORD}" ]; then
docker login --username "${DOCKERHUB_LOGIN}" --password "${DOCKERHUB_PASSWORD}"
fi
# Pull images
images=$(get_toolset_value '.docker.images[]')
for image in $images; do
docker pull "$image"
done
invoke_tests "Tools" "Docker"
# Always attempt to logout so we do not leave our credentials on the built
# image. Logout _should_ return a zero exit code even if no credentials were
# stored from earlier.
docker logout
invoke_tests "Tools" "Docker"