Skip to content

Commit 30eff87

Browse files
authored
publish images to ecr public repo (#325)
* publish images to ecr public repo * add ecr-public-login script
1 parent 7f33a27 commit 30eff87

File tree

4 files changed

+73
-1
lines changed

4 files changed

+73
-1
lines changed

Makefile

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ VERSION = $(shell git describe --tags --always --dirty)
22
LATEST_RELEASE_TAG=$(shell git describe --tags --abbrev=0)
33
PREVIOUS_RELEASE_TAG=$(shell git describe --abbrev=0 --tags `git rev-list --tags --skip=1 --max-count=1`)
44
REPO_FULL_NAME=aws/aws-node-termination-handler
5+
ECR_REGISTRY ?= public.ecr.aws/r6b0f9a1
6+
ECR_REPO ?= ${ECR_REGISTRY}/aws-node-termination-handler
57
IMG ?= amazon/aws-node-termination-handler
68
IMG_TAG ?= ${VERSION}
79
IMG_W_TAG = ${IMG}:${IMG_TAG}
@@ -47,10 +49,16 @@ build-docker-images-windows:
4749
push-docker-images:
4850
@docker login -u ${DOCKER_USERNAME} -p="${DOCKERHUB_TOKEN}"
4951
${MAKEFILE_PATH}/scripts/push-docker-images -p ${SUPPORTED_PLATFORMS_LINUX} -r ${IMG} -v ${VERSION} -m
52+
${MAKEFILE_PATH}/scripts/retag-docker-images -p ${SUPPORTED_PLATFORMS_LINUX} -v ${VERSION} -o ${IMG} -n ${ECR_REPO}
53+
@ECR_REGISTRY=${ECR_REGISTRY} ${MAKEFILE_PATH}/scripts/ecr-public-login
54+
${MAKEFILE_PATH}/scripts/push-docker-images -p ${SUPPORTED_PLATFORMS_LINUX} -r ${ECR_REPO} -v ${VERSION} -m
5055

5156
push-docker-images-windows:
5257
@docker login -u ${DOCKER_USERNAME} -p="${DOCKERHUB_TOKEN}"
5358
${MAKEFILE_PATH}/scripts/push-docker-images -p ${SUPPORTED_PLATFORMS_WINDOWS} -r ${IMG} -v ${VERSION} -m
59+
${MAKEFILE_PATH}/scripts/retag-docker-images -p ${SUPPORTED_PLATFORMS_LINUX} -v ${VERSION} -o ${IMG} -n ${ECR_REPO}
60+
@ECR_REGISTRY=${ECR_REGISTRY} ${MAKEFILE_PATH}/scripts/ecr-public-login
61+
${MAKEFILE_PATH}/scripts/push-docker-images -p ${SUPPORTED_PLATFORMS_WINDOWS} -r ${ECR_REPO} -v ${VERSION} -m
5462

5563
version:
5664
@echo ${VERSION}

config/helm/aws-node-termination-handler/values.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# Declare variables to be passed into your templates.
44

55
image:
6-
repository: amazon/aws-node-termination-handler
6+
repository: public.ecr.aws/r6b0f9a1/aws-node-termination-handler
77
tag: v1.11.1
88
pullPolicy: IfNotPresent
99
pullSecrets: []

scripts/ecr-public-login

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/bin/bash
2+
set -euo pipefail
3+
4+
if [[ -z "${ECR_REGISTRY}" ]]; then
5+
echo "The env var ECR_REGISTRY must be set"
6+
exit 1
7+
fi
8+
9+
docker login --username AWS -p="$(docker run --rm --env-file <(env | grep AWS) -i amazon/aws-cli ecr-public get-login-password --region us-east-1)" ${ECR_REGISTRY}

scripts/retag-docker-images

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
#!/bin/bash
2+
set -euo pipefail
3+
4+
SCRIPTPATH="$( cd "$(dirname "$0")" ; pwd -P )"
5+
6+
REPO_ROOT_PATH=$SCRIPTPATH/../
7+
MAKE_FILE_PATH=$REPO_ROOT_PATH/Makefile
8+
9+
VERSION=$(make -s -f $MAKE_FILE_PATH version)
10+
PLATFORMS=("linux/amd64")
11+
12+
13+
USAGE=$(cat << 'EOM'
14+
Usage: retag-docker-images [-p <platform pairs>]
15+
Tags created docker images with a new prefix
16+
17+
Example: retag-docker-images -p "linux/amd64,linux/arm" -o <OLD_REPO_PREFIX> -n <NEW_REPO_PREFIX>
18+
Optional:
19+
-p Platform pair list (os/architecture) [DEFAULT: linux/amd64]
20+
-o OLD IMAGE REPO to retag
21+
-n NEW IMAGE REPO to tag with
22+
-v VERSION: The application version of the docker image [DEFAULT: output of `make version`]
23+
EOM
24+
)
25+
26+
# Process our input arguments
27+
while getopts "p:o:n:v:" opt; do
28+
case ${opt} in
29+
p ) # Platform Pairs
30+
IFS=',' read -ra PLATFORMS <<< "$OPTARG"
31+
;;
32+
o ) # Old Image Repo
33+
OLD_IMAGE_REPO="$OPTARG"
34+
;;
35+
n ) # New Image Repo
36+
NEW_IMAGE_REPO="$OPTARG"
37+
;;
38+
v ) # Image Version
39+
VERSION="$OPTARG"
40+
;;
41+
\? )
42+
echo "$USAGE" 1>&2
43+
exit
44+
;;
45+
esac
46+
done
47+
48+
for os_arch in "${PLATFORMS[@]}"; do
49+
os=$(echo $os_arch | cut -d'/' -f1)
50+
arch=$(echo $os_arch | cut -d'/' -f2)
51+
52+
old_img_tag="$OLD_IMAGE_REPO:$VERSION-$os-$arch"
53+
new_img_tag="$NEW_IMAGE_REPO:$VERSION-$os-$arch"
54+
docker tag ${old_img_tag} ${new_img_tag}
55+
done

0 commit comments

Comments
 (0)