[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
This commit is contained in:
Philip Hyunsu Cho 2019-06-19 15:08:42 -07:00 committed by GitHub
parent ae05948e32
commit 0c50f8417a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 5 deletions

3
Jenkinsfile vendored
View File

@ -11,7 +11,8 @@ pipeline {
agent none agent none
environment { 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 // Setup common job properties

View File

@ -137,12 +137,15 @@ EOF
# Build the docker container. # Build the docker container.
echo "Building container (${DOCKER_IMG_NAME})..." echo "Building container (${DOCKER_IMG_NAME})..."
# If enviornment variable DOCKER_CACHE_REPO is set, use an external Docker repo for build caching # If enviornment variables DOCKER_CACHE_ECR_ID and DOCKER_CACHE_ECR_REGION are set, use AWS ECR for build caching
if [[ -n "${DOCKER_CACHE_REPO}" ]] if [[ -n "${DOCKER_CACHE_ECR_ID}" && -n "${DOCKER_CACHE_ECR_REGION}" ]]
then 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 # Login for Docker registry
echo '$(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 us-west-2) $(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, # Pull pre-build container from Docker build cache,
# if one exists for the particular branch or pull request # if one exists for the particular branch or pull request
echo "docker pull ${DOCKER_CACHE_REPO}/${DOCKER_IMG_NAME}:${BRANCH_NAME}" echo "docker pull ${DOCKER_CACHE_REPO}/${DOCKER_IMG_NAME}:${BRANCH_NAME}"