From d46e369811f898a56b0f2a873157a5e082caa36a Mon Sep 17 00:00:00 2001 From: Brian Pitts Date: Tue, 6 Oct 2020 13:32:28 -0400 Subject: [PATCH] Log in to docker hub before pulling images Docker Hub is implementing rate limiting for anonymous pulls. We need to log in before we pull. That happens in two places 1) In all job to fetch the image that the CircleCI jobs run in. This is what the new `auth` block handles. 2) In the build job to pull the base image defined in the application's dockerfile. This is that the new "login to dockerhub" step handles, We also still have to log in in the deploy job in order to push to docker hub. There is no shared state between jobs, h/t to jwhitlock who figured most of this out in https://github.com/mozilla/ichnaea/compare/6655b9b...f8da96dc28 --- .circleci/config.yml | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/.circleci/config.yml b/.circleci/config.yml index a5da9c9..f8bb0dd 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -9,6 +9,9 @@ jobs: build: docker: - image: docker:stable-git + auth: + username: $DOCKER_USER + password: $DOCKER_PASS working_directory: /dockerflow steps: - checkout @@ -25,6 +28,15 @@ jobs: "$CIRCLE_PROJECT_REPONAME" \ "$CIRCLE_BUILD_URL" > version.json + - run: + name: Login to Dockerhub + command: | + if [ "${DOCKER_USER}" == "" ] || [ "${DOCKER_PASS}" == "" ]; then + echo "Skipping Login to Dockerhub, credentials not available." + else + echo "${DOCKER_PASS}" | docker login -u="${DOCKER_USER}" --password-stdin + fi + - run: name: Build Docker image command: docker build -t app:build .