From 0c50f8417a36ff731b35a5405fb25f70c5ad8c93 Mon Sep 17 00:00:00 2001 From: Philip Hyunsu Cho Date: Wed, 19 Jun 2019 15:08:42 -0700 Subject: [PATCH] [CI] Specify account ID when logging into ECR Docker registry (#4584) * [CI] Specify account ID when logging into ECR Docker registry * Do not display awscli login command --- Jenkinsfile | 3 ++- tests/ci_build/ci_build.sh | 11 +++++++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 2b665c083..6a5eadc9c 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -11,7 +11,8 @@ pipeline { agent none environment { - DOCKER_CACHE_REPO = '492475357299.dkr.ecr.us-west-2.amazonaws.com' + DOCKER_CACHE_ECR_ID = '492475357299' + DOCKER_CACHE_ECR_REGION = 'us-west-2' } // Setup common job properties diff --git a/tests/ci_build/ci_build.sh b/tests/ci_build/ci_build.sh index f6abe2bea..5f0ed1120 100755 --- a/tests/ci_build/ci_build.sh +++ b/tests/ci_build/ci_build.sh @@ -137,12 +137,15 @@ EOF # Build the docker container. echo "Building container (${DOCKER_IMG_NAME})..." -# If enviornment variable DOCKER_CACHE_REPO is set, use an external Docker repo for build caching -if [[ -n "${DOCKER_CACHE_REPO}" ]] +# If enviornment variables DOCKER_CACHE_ECR_ID and DOCKER_CACHE_ECR_REGION are set, use AWS ECR for build caching +if [[ -n "${DOCKER_CACHE_ECR_ID}" && -n "${DOCKER_CACHE_ECR_REGION}" ]] then + # Format Docker repo URL + DOCKER_CACHE_REPO="${DOCKER_CACHE_ECR_ID}.dkr.ecr.${DOCKER_CACHE_ECR_REGION}.amazonaws.com" + echo "Using AWS ECR; repo URL = ${DOCKER_CACHE_REPO}" # Login for Docker registry - echo '$(python3 -m awscli ecr get-login --no-include-email --region us-west-2)' - $(python3 -m awscli ecr get-login --no-include-email --region us-west-2) + echo "\$(python3 -m awscli ecr get-login --no-include-email --region ${DOCKER_CACHE_ECR_REGION} --registry-ids ${DOCKER_CACHE_ECR_ID})" + $(python3 -m awscli ecr get-login --no-include-email --region ${DOCKER_CACHE_ECR_REGION} --registry-ids ${DOCKER_CACHE_ECR_ID}) # Pull pre-build container from Docker build cache, # if one exists for the particular branch or pull request echo "docker pull ${DOCKER_CACHE_REPO}/${DOCKER_IMG_NAME}:${BRANCH_NAME}"