diff --git a/Makefile b/Makefile index 8e79cd13..cef4912c 100644 --- a/Makefile +++ b/Makefile @@ -2,6 +2,8 @@ VERSION = $(shell git describe --tags --always --dirty) LATEST_RELEASE_TAG=$(shell git describe --tags --abbrev=0) PREVIOUS_RELEASE_TAG=$(shell git describe --abbrev=0 --tags `git rev-list --tags --skip=1 --max-count=1`) REPO_FULL_NAME=aws/aws-node-termination-handler +ECR_REGISTRY ?= public.ecr.aws/r6b0f9a1 +ECR_REPO ?= ${ECR_REGISTRY}/aws-node-termination-handler IMG ?= amazon/aws-node-termination-handler IMG_TAG ?= ${VERSION} IMG_W_TAG = ${IMG}:${IMG_TAG} @@ -47,10 +49,16 @@ build-docker-images-windows: push-docker-images: @docker login -u ${DOCKER_USERNAME} -p="${DOCKERHUB_TOKEN}" ${MAKEFILE_PATH}/scripts/push-docker-images -p ${SUPPORTED_PLATFORMS_LINUX} -r ${IMG} -v ${VERSION} -m + ${MAKEFILE_PATH}/scripts/retag-docker-images -p ${SUPPORTED_PLATFORMS_LINUX} -v ${VERSION} -o ${IMG} -n ${ECR_REPO} + @ECR_REGISTRY=${ECR_REGISTRY} ${MAKEFILE_PATH}/scripts/ecr-public-login + ${MAKEFILE_PATH}/scripts/push-docker-images -p ${SUPPORTED_PLATFORMS_LINUX} -r ${ECR_REPO} -v ${VERSION} -m push-docker-images-windows: @docker login -u ${DOCKER_USERNAME} -p="${DOCKERHUB_TOKEN}" ${MAKEFILE_PATH}/scripts/push-docker-images -p ${SUPPORTED_PLATFORMS_WINDOWS} -r ${IMG} -v ${VERSION} -m + ${MAKEFILE_PATH}/scripts/retag-docker-images -p ${SUPPORTED_PLATFORMS_LINUX} -v ${VERSION} -o ${IMG} -n ${ECR_REPO} + @ECR_REGISTRY=${ECR_REGISTRY} ${MAKEFILE_PATH}/scripts/ecr-public-login + ${MAKEFILE_PATH}/scripts/push-docker-images -p ${SUPPORTED_PLATFORMS_WINDOWS} -r ${ECR_REPO} -v ${VERSION} -m version: @echo ${VERSION} diff --git a/config/helm/aws-node-termination-handler/values.yaml b/config/helm/aws-node-termination-handler/values.yaml index a91e5ccd..85b438df 100644 --- a/config/helm/aws-node-termination-handler/values.yaml +++ b/config/helm/aws-node-termination-handler/values.yaml @@ -3,7 +3,7 @@ # Declare variables to be passed into your templates. image: - repository: amazon/aws-node-termination-handler + repository: public.ecr.aws/r6b0f9a1/aws-node-termination-handler tag: v1.11.1 pullPolicy: IfNotPresent pullSecrets: [] diff --git a/scripts/ecr-public-login b/scripts/ecr-public-login new file mode 100755 index 00000000..386cf28c --- /dev/null +++ b/scripts/ecr-public-login @@ -0,0 +1,9 @@ +#!/bin/bash +set -euo pipefail + +if [[ -z "${ECR_REGISTRY}" ]]; then + echo "The env var ECR_REGISTRY must be set" + exit 1 +fi + +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} diff --git a/scripts/retag-docker-images b/scripts/retag-docker-images new file mode 100755 index 00000000..347b1605 --- /dev/null +++ b/scripts/retag-docker-images @@ -0,0 +1,55 @@ +#!/bin/bash +set -euo pipefail + +SCRIPTPATH="$( cd "$(dirname "$0")" ; pwd -P )" + +REPO_ROOT_PATH=$SCRIPTPATH/../ +MAKE_FILE_PATH=$REPO_ROOT_PATH/Makefile + +VERSION=$(make -s -f $MAKE_FILE_PATH version) +PLATFORMS=("linux/amd64") + + +USAGE=$(cat << 'EOM' + Usage: retag-docker-images [-p ] + Tags created docker images with a new prefix + + Example: retag-docker-images -p "linux/amd64,linux/arm" -o -n + Optional: + -p Platform pair list (os/architecture) [DEFAULT: linux/amd64] + -o OLD IMAGE REPO to retag + -n NEW IMAGE REPO to tag with + -v VERSION: The application version of the docker image [DEFAULT: output of `make version`] +EOM +) + +# Process our input arguments +while getopts "p:o:n:v:" opt; do + case ${opt} in + p ) # Platform Pairs + IFS=',' read -ra PLATFORMS <<< "$OPTARG" + ;; + o ) # Old Image Repo + OLD_IMAGE_REPO="$OPTARG" + ;; + n ) # New Image Repo + NEW_IMAGE_REPO="$OPTARG" + ;; + v ) # Image Version + VERSION="$OPTARG" + ;; + \? ) + echo "$USAGE" 1>&2 + exit + ;; + esac +done + +for os_arch in "${PLATFORMS[@]}"; do + os=$(echo $os_arch | cut -d'/' -f1) + arch=$(echo $os_arch | cut -d'/' -f2) + + old_img_tag="$OLD_IMAGE_REPO:$VERSION-$os-$arch" + new_img_tag="$NEW_IMAGE_REPO:$VERSION-$os-$arch" + docker tag ${old_img_tag} ${new_img_tag} +done