Skip to content

Commit 89a44eb

Browse files
Optionally log into ECR public (#189)
Description of changes: Created a new helper method to determine whether the user is currently logged into the ECR public Docker registry. Only if they are not already logged in do we attempt to log in. This will allow the test infrastructure to log in once at the beginning (with a separate role) and ensure that login is stored even after we assume another role. By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
1 parent 0de0bd0 commit 89a44eb

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

scripts/build-controller-image.sh

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,10 @@ if [[ $QUIET = "false" ]]; then
7474
echo " git commit: $SERVICE_CONTROLLER_GIT_COMMIT"
7575
fi
7676

77-
# Log into ECR public to access base images
78-
aws ecr-public get-login-password --region us-east-1 | docker login --username AWS --password-stdin public.ecr.aws
77+
if ! is_public_ecr_logged_in; then
78+
# Log into ECR public to access base images
79+
aws ecr-public get-login-password --region us-east-1 | docker login --username AWS --password-stdin public.ecr.aws
80+
fi
7981

8082
# if local build
8183
# then use Dockerfile which allows references to local modules from service controller

scripts/lib/common.sh

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,4 +108,19 @@ k8s_controller_gen_version_equals() {
108108
else
109109
return 1
110110
fi;
111+
}
112+
113+
# is_public_ecr_logged_in returns 0 if the Docker client is authenticated
114+
# with ECR public and therefore can pull and push to ECR public, otherwise
115+
# returns 1
116+
#
117+
# Usage:
118+
#
119+
# if ! is_public_ecr_logged_in; then
120+
# aws ecr-public get-login-password --region us-east-1 \
121+
# | docker login --username AWS --password-stdin public.ecr.aws
122+
# fi
123+
is_public_ecr_logged_in() {
124+
local public_ecr_url="public.ecr.aws"
125+
jq -e --arg url $public_ecr_url '.auths | has($url)' ~/.docker/config.json > /dev/null;
111126
}

0 commit comments

Comments
 (0)