From dde53fba7968536d5468cc01b9f0f1392c4a5e46 Mon Sep 17 00:00:00 2001 From: Nathan Leiby Date: Thu, 10 Aug 2017 14:46:04 -0700 Subject: [PATCH 1/9] ecr login: allow login without email This is required for later versions of Docker. Also refactor: put ECR Login alongside Docker login. This way we ensure we can push before spending time building the image. --- circleci/docker-publish | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/circleci/docker-publish b/circleci/docker-publish index fc720b1..53b5970 100755 --- a/circleci/docker-publish +++ b/circleci/docker-publish @@ -1,7 +1,7 @@ #!/bin/bash # Logs into Docker registry (DockerHub and optionally ECR), -# then builds and pushes docker image. Docker image is tagged +# then builds and pushes docker image. Docker image is tagged # with 7 character git commit SHA. # # Usage: @@ -30,8 +30,12 @@ check_ecr_vars() { if [[ -z $ECR_PUSH_SECRET ]]; then echo "Missing var for ECR: ECR_PUSH_SECRET" && exit 1; fi } +ecr_login(){ + eval $(AWS_ACCESS_KEY_ID=$ECR_PUSH_ID AWS_SECRET_ACCESS_KEY=$ECR_PUSH_SECRET aws ecr --region $ECR_REGION get-login --include-email) \ + || eval $(AWS_ACCESS_KEY_ID=$ECR_PUSH_ID AWS_SECRET_ACCESS_KEY=$ECR_PUSH_SECRET aws ecr --region $ECR_REGION get-login --no-include-email) +} + push_ecr_image(){ - eval $(AWS_ACCESS_KEY_ID=$ECR_PUSH_ID AWS_SECRET_ACCESS_KEY=$ECR_PUSH_SECRET aws ecr --region $ECR_REGION get-login) docker tag $ORG/$REPO:$SHORT_SHA $ECR_ACCOUNT_ID.dkr.ecr.$ECR_REGION.amazonaws.com/$REPO:$SHORT_SHA docker push $ECR_ACCOUNT_ID.dkr.ecr.$ECR_REGION.amazonaws.com/$REPO:$SHORT_SHA } @@ -56,6 +60,10 @@ fi # dockerhub login. # `FROM image` in Dockerfile is going to pull from DockerHub docker login -u $DOCKER_USER -p $DOCKER_PASS --email="$DOCKER_EMAIL" || docker login -u $DOCKER_USER -p $DOCKER_PASS +if [ "$ECR_PUSH_ID" != "" ]; then + echo "ECR access_id available. Logging into ECR..." + ecr_login +fi echo "Building docker image..." docker build -t $ORG/$REPO:$SHORT_SHA . @@ -66,6 +74,5 @@ push_hub_image $1 $2 $3 $4 # all repos eventually should dual publish (or explicitly opt-out) if [ "$ECR_PUSH_ID" != "" ]; then echo "ECR access_id available. Pushing to ECR..." - # push_ecr_image - echo "skipping" + push_ecr_image fi From cf89001967ea1b3b69d40c77bb5d508f498a1b0b Mon Sep 17 00:00:00 2001 From: Nathan Leiby Date: Fri, 11 Aug 2017 14:57:26 -0700 Subject: [PATCH 2/9] remove email from docker login cmds --- circleci/docker-publish | 7 ++----- circleci/report-card | 2 +- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/circleci/docker-publish b/circleci/docker-publish index 53b5970..97b58f6 100755 --- a/circleci/docker-publish +++ b/circleci/docker-publish @@ -15,7 +15,6 @@ check_hub_vars() { # User supplied args if [[ -z $DOCKER_USER ]]; then echo "Missing arg1 DOCKER_USER" && exit 1; fi if [[ -z $DOCKER_PASS ]]; then echo "Missing arg2 DOCKER_PASS" && exit 1; fi - if [[ -z $DOCKER_EMAIL ]]; then echo "Missing arg3 DOCKER_EMAIL" && exit 1; fi if [[ -z $ORG ]]; then echo "Missing arg4 ORG" && exit 1; fi } @@ -31,8 +30,7 @@ check_ecr_vars() { } ecr_login(){ - eval $(AWS_ACCESS_KEY_ID=$ECR_PUSH_ID AWS_SECRET_ACCESS_KEY=$ECR_PUSH_SECRET aws ecr --region $ECR_REGION get-login --include-email) \ - || eval $(AWS_ACCESS_KEY_ID=$ECR_PUSH_ID AWS_SECRET_ACCESS_KEY=$ECR_PUSH_SECRET aws ecr --region $ECR_REGION get-login --no-include-email) + eval $(AWS_ACCESS_KEY_ID=$ECR_PUSH_ID AWS_SECRET_ACCESS_KEY=$ECR_PUSH_SECRET aws ecr --region $ECR_REGION get-login --no-include-email) } push_ecr_image(){ @@ -48,7 +46,6 @@ SHORT_SHA=${CIRCLE_SHA1:0:7} DOCKER_USER=$1 DOCKER_PASS=$2 -DOCKER_EMAIL=$3 ORG=$4 # Check CLI + env vars for DockerHub and (conditonally) ECR @@ -59,7 +56,7 @@ fi # dockerhub login. # `FROM image` in Dockerfile is going to pull from DockerHub -docker login -u $DOCKER_USER -p $DOCKER_PASS --email="$DOCKER_EMAIL" || docker login -u $DOCKER_USER -p $DOCKER_PASS +docker login -u $DOCKER_USER -p $DOCKER_PASS if [ "$ECR_PUSH_ID" != "" ]; then echo "ECR access_id available. Logging into ECR..." ecr_login diff --git a/circleci/report-card b/circleci/report-card index be5e7a8..f51531f 100755 --- a/circleci/report-card +++ b/circleci/report-card @@ -23,7 +23,7 @@ GITHUB_TOKEN=$4 REPORT_CARD_IMAGE="0babaab" echo "Logging into DockerHub..." -docker login -u $DOCKER_USER -p $DOCKER_PASS --email="$DOCKER_EMAIL" +docker login -u $DOCKER_USER -p $DOCKER_PASS if [ $? -ne 0 ]; then echo "ERROR: Failed to login to dockerhub" exit 1 From 447f47d48a731764fded76f6cae075c14185901a Mon Sep 17 00:00:00 2001 From: Nathan Leiby Date: Wed, 30 Aug 2017 15:04:38 -0700 Subject: [PATCH 3/9] docker-publish: try email, fallback to no email --- circleci/docker-publish | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/circleci/docker-publish b/circleci/docker-publish index 97b58f6..4eb5848 100755 --- a/circleci/docker-publish +++ b/circleci/docker-publish @@ -30,7 +30,7 @@ check_ecr_vars() { } ecr_login(){ - eval $(AWS_ACCESS_KEY_ID=$ECR_PUSH_ID AWS_SECRET_ACCESS_KEY=$ECR_PUSH_SECRET aws ecr --region $ECR_REGION get-login --no-include-email) + eval $(AWS_ACCESS_KEY_ID=$ECR_PUSH_ID AWS_SECRET_ACCESS_KEY=$ECR_PUSH_SECRET aws ecr --region $ECR_REGION get-login --include-email) || eval $(AWS_ACCESS_KEY_ID=$ECR_PUSH_ID AWS_SECRET_ACCESS_KEY=$ECR_PUSH_SECRET aws ecr --region $ECR_REGION get-login --no-include-email) } push_ecr_image(){ @@ -56,7 +56,7 @@ fi # dockerhub login. # `FROM image` in Dockerfile is going to pull from DockerHub -docker login -u $DOCKER_USER -p $DOCKER_PASS +docker login -u $DOCKER_USER -p $DOCKER_PASS --email="$DOCKER_EMAIL" || docker login -u $DOCKER_USER -p $DOCKER_PASS if [ "$ECR_PUSH_ID" != "" ]; then echo "ECR access_id available. Logging into ECR..." ecr_login From 130cbed32a720d692123134590b17ec5d197c862 Mon Sep 17 00:00:00 2001 From: Nathan Leiby Date: Wed, 30 Aug 2017 15:39:08 -0700 Subject: [PATCH 4/9] print docker version --- circleci/docker-publish | 3 +++ 1 file changed, 3 insertions(+) diff --git a/circleci/docker-publish b/circleci/docker-publish index 4eb5848..a0ecf58 100755 --- a/circleci/docker-publish +++ b/circleci/docker-publish @@ -48,6 +48,9 @@ DOCKER_USER=$1 DOCKER_PASS=$2 ORG=$4 +echo "Docker version..." +docker version + # Check CLI + env vars for DockerHub and (conditonally) ECR check_hub_vars if [ "$ECR_PUSH_ID" != "" ]; then From 001f575f4b95b7aa4f4a95ed149e7866b1d41512 Mon Sep 17 00:00:00 2001 From: Nathan Leiby Date: Wed, 30 Aug 2017 16:01:06 -0700 Subject: [PATCH 5/9] docker-publish: add newlines to logs, for clarity --- circleci/docker-publish | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/circleci/docker-publish b/circleci/docker-publish index a0ecf58..09bc337 100755 --- a/circleci/docker-publish +++ b/circleci/docker-publish @@ -59,20 +59,21 @@ fi # dockerhub login. # `FROM image` in Dockerfile is going to pull from DockerHub +echo "\nLogging into DockerHub..." docker login -u $DOCKER_USER -p $DOCKER_PASS --email="$DOCKER_EMAIL" || docker login -u $DOCKER_USER -p $DOCKER_PASS if [ "$ECR_PUSH_ID" != "" ]; then - echo "ECR access_id available. Logging into ECR..." + echo "\nECR access_id available. Logging into ECR..." ecr_login fi -echo "Building docker image..." +echo "\nBuilding docker image..." docker build -t $ORG/$REPO:$SHORT_SHA . -echo "Pushing to DockerHub..." +echo "\nPushing to DockerHub..." push_hub_image $1 $2 $3 $4 # all repos eventually should dual publish (or explicitly opt-out) if [ "$ECR_PUSH_ID" != "" ]; then - echo "ECR access_id available. Pushing to ECR..." + echo "\nECR access_id available. Pushing to ECR..." push_ecr_image fi From 61c6dd166be03609f0caa44a9742fb15b15aba80 Mon Sep 17 00:00:00 2001 From: Nathan Leiby Date: Wed, 30 Aug 2017 16:06:00 -0700 Subject: [PATCH 6/9] Revert "docker-publish: add newlines to logs, for clarity" This reverts commit 001f575f4b95b7aa4f4a95ed149e7866b1d41512. --- circleci/docker-publish | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/circleci/docker-publish b/circleci/docker-publish index 09bc337..a0ecf58 100755 --- a/circleci/docker-publish +++ b/circleci/docker-publish @@ -59,21 +59,20 @@ fi # dockerhub login. # `FROM image` in Dockerfile is going to pull from DockerHub -echo "\nLogging into DockerHub..." docker login -u $DOCKER_USER -p $DOCKER_PASS --email="$DOCKER_EMAIL" || docker login -u $DOCKER_USER -p $DOCKER_PASS if [ "$ECR_PUSH_ID" != "" ]; then - echo "\nECR access_id available. Logging into ECR..." + echo "ECR access_id available. Logging into ECR..." ecr_login fi -echo "\nBuilding docker image..." +echo "Building docker image..." docker build -t $ORG/$REPO:$SHORT_SHA . -echo "\nPushing to DockerHub..." +echo "Pushing to DockerHub..." push_hub_image $1 $2 $3 $4 # all repos eventually should dual publish (or explicitly opt-out) if [ "$ECR_PUSH_ID" != "" ]; then - echo "\nECR access_id available. Pushing to ECR..." + echo "ECR access_id available. Pushing to ECR..." push_ecr_image fi From bfbd467e5013f46df23d6c1150160f6547d71e38 Mon Sep 17 00:00:00 2001 From: Nathan Leiby Date: Wed, 30 Aug 2017 16:08:17 -0700 Subject: [PATCH 7/9] docker login cleanup --- circleci/docker-publish | 4 ++-- circleci/report-card | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/circleci/docker-publish b/circleci/docker-publish index a0ecf58..23d3aeb 100755 --- a/circleci/docker-publish +++ b/circleci/docker-publish @@ -59,7 +59,7 @@ fi # dockerhub login. # `FROM image` in Dockerfile is going to pull from DockerHub -docker login -u $DOCKER_USER -p $DOCKER_PASS --email="$DOCKER_EMAIL" || docker login -u $DOCKER_USER -p $DOCKER_PASS +docker login -u $DOCKER_USER -p $DOCKER_PASS --email="" || docker login -u $DOCKER_USER -p $DOCKER_PASS if [ "$ECR_PUSH_ID" != "" ]; then echo "ECR access_id available. Logging into ECR..." ecr_login @@ -69,7 +69,7 @@ echo "Building docker image..." docker build -t $ORG/$REPO:$SHORT_SHA . echo "Pushing to DockerHub..." -push_hub_image $1 $2 $3 $4 +push_hub_image # all repos eventually should dual publish (or explicitly opt-out) if [ "$ECR_PUSH_ID" != "" ]; then diff --git a/circleci/report-card b/circleci/report-card index f51531f..e1e2f1e 100755 --- a/circleci/report-card +++ b/circleci/report-card @@ -23,7 +23,7 @@ GITHUB_TOKEN=$4 REPORT_CARD_IMAGE="0babaab" echo "Logging into DockerHub..." -docker login -u $DOCKER_USER -p $DOCKER_PASS +docker login -u $DOCKER_USER -p $DOCKER_PASS --email="" || docker login -u $DOCKER_USER -p $DOCKER_PASS if [ $? -ne 0 ]; then echo "ERROR: Failed to login to dockerhub" exit 1 From c6b4c4510b39ecdcb3aab4131e45821cce699f81 Mon Sep 17 00:00:00 2001 From: Nathan Leiby Date: Wed, 30 Aug 2017 16:16:17 -0700 Subject: [PATCH 8/9] docker login cleanup2 --- circleci/docker-publish | 2 +- circleci/report-card | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/circleci/docker-publish b/circleci/docker-publish index 23d3aeb..7fb3d4c 100755 --- a/circleci/docker-publish +++ b/circleci/docker-publish @@ -59,7 +59,7 @@ fi # dockerhub login. # `FROM image` in Dockerfile is going to pull from DockerHub -docker login -u $DOCKER_USER -p $DOCKER_PASS --email="" || docker login -u $DOCKER_USER -p $DOCKER_PASS +docker login -u $DOCKER_USER -p $DOCKER_PASS --email="none" || docker login -u $DOCKER_USER -p $DOCKER_PASS if [ "$ECR_PUSH_ID" != "" ]; then echo "ECR access_id available. Logging into ECR..." ecr_login diff --git a/circleci/report-card b/circleci/report-card index e1e2f1e..3d3f850 100755 --- a/circleci/report-card +++ b/circleci/report-card @@ -23,7 +23,7 @@ GITHUB_TOKEN=$4 REPORT_CARD_IMAGE="0babaab" echo "Logging into DockerHub..." -docker login -u $DOCKER_USER -p $DOCKER_PASS --email="" || docker login -u $DOCKER_USER -p $DOCKER_PASS +docker login -u $DOCKER_USER -p $DOCKER_PASS --email="none" || docker login -u $DOCKER_USER -p $DOCKER_PASS if [ $? -ne 0 ]; then echo "ERROR: Failed to login to dockerhub" exit 1 From a1f99c5d262e4888f7a5737ea812615610ce250b Mon Sep 17 00:00:00 2001 From: Nathan Leiby Date: Wed, 20 Sep 2017 11:50:39 -0700 Subject: [PATCH 9/9] docker-publish: add back DOCKER_EMAIL --- circleci/docker-publish | 2 ++ 1 file changed, 2 insertions(+) diff --git a/circleci/docker-publish b/circleci/docker-publish index 7fb3d4c..9aceb90 100755 --- a/circleci/docker-publish +++ b/circleci/docker-publish @@ -15,6 +15,7 @@ check_hub_vars() { # User supplied args if [[ -z $DOCKER_USER ]]; then echo "Missing arg1 DOCKER_USER" && exit 1; fi if [[ -z $DOCKER_PASS ]]; then echo "Missing arg2 DOCKER_PASS" && exit 1; fi + if [[ -z $DOCKER_EMAIL ]]; then echo "Missing arg3 DOCKER_EMAIL" && exit 1; fi if [[ -z $ORG ]]; then echo "Missing arg4 ORG" && exit 1; fi } @@ -46,6 +47,7 @@ SHORT_SHA=${CIRCLE_SHA1:0:7} DOCKER_USER=$1 DOCKER_PASS=$2 +DOCKER_EMAIL=$3 # this arg is unused; TODO: Migration to remove it from other repos which call ci-scripts ORG=$4 echo "Docker version..."