Skip to content

Commit

Permalink
chore: allow aws credential generation for ecr-public
Browse files Browse the repository at this point in the history
Set `ECR_PUBLIC` in onder to login with public.ecr.aws

Signed-off-by: Andrew Bayer <andrew.bayer@gmail.com>
  • Loading branch information
Steve Arch authored and David Conde committed Jul 13, 2021
1 parent 3198ace commit 670f56d
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion dockercfg-generator/aws_docker_creds.sh
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,20 @@ else
AWS_ACCOUNT=$(aws sts get-caller-identity | jq -r ".Account")
fi

# For public images stored in public.ecr.aws, we need to use a different CLI call
if [[ -v ECR_PUBLIC ]]; then
COMMAND=ecr-public
SERVER=public.ecr.aws
else
COMMAND=ecr
SERVER=${AWS_ACCOUNT}.dkr.ecr.${AWS_REGION}.amazonaws.com
fi

# fetching aws docker login
# aws deprecated the get-login function in favor of get-login-password
# https://docs.aws.amazon.com/cli/latest/reference/ecr/get-login.html
echo "Logging into AWS ECR with account ${AWS_ACCOUNT}"
aws ecr get-login-password --region ${AWS_REGION} | docker login --username AWS --password-stdin ${AWS_ACCOUNT}.dkr.ecr.${AWS_REGION}.amazonaws.com
aws ${COMMAND} get-login-password --region ${AWS_REGION} | docker login --username AWS --password-stdin ${SERVER}

# writing aws docker creds to desired path
echo "Writing Docker creds to $1"
Expand Down

0 comments on commit 670f56d

Please sign in to comment.