From 963860f1dd29f79b32060c9de6ac098964f4e7b4 Mon Sep 17 00:00:00 2001 From: Likitha Vemulapalli <40854257+LikithaVemulapalli@users.noreply.github.com> Date: Mon, 9 Sep 2024 15:53:24 -0700 Subject: [PATCH] Added new script that fixes windows ecr login issues (#222) --- Makefile | 3 +- scripts/install-amazon-ecr-credential-helper | 45 ++++++++++++++++++++ 2 files changed, 47 insertions(+), 1 deletion(-) create mode 100644 scripts/install-amazon-ecr-credential-helper diff --git a/Makefile b/Makefile index 05ddc6c..a1b58f0 100644 --- a/Makefile +++ b/Makefile @@ -21,6 +21,7 @@ BIN_DIR = ${MAKEFILE_PATH}/bin BINARY_NAME ?= ec2-metadata-mock THIRD_PARTY_LICENSES = ${MAKEFILE_PATH}/THIRD_PARTY_LICENSES.md GOLICENSES = ${BIN_DIR}/go-licenses +AMAZON_ECR_CREDENTIAL_HELPER_VERSION = 0.7.1 $(shell mkdir -p ${BUILD_DIR_PATH} && touch ${BUILD_DIR_PATH}/_go.mod) @@ -128,7 +129,7 @@ push-docker-images-linux: push-docker-images-windows: ${MAKEFILE_PATH}/scripts/retag-docker-images -p ${SUPPORTED_PLATFORMS_WINDOWS} -v ${VERSION} -o ${IMG} -n ${ECR_REPO} - @ECR_REGISTRY=${ECR_REGISTRY} ${MAKEFILE_PATH}/scripts/ecr-public-login + bash ${MAKEFILE_PATH}/scripts/install-amazon-ecr-credential-helper $(AMAZON_ECR_CREDENTIAL_HELPER_VERSION) ${MAKEFILE_PATH}/scripts/push-docker-images -p ${SUPPORTED_PLATFORMS_WINDOWS} -r ${ECR_REPO} -v ${VERSION} -m push-helm-chart: diff --git a/scripts/install-amazon-ecr-credential-helper b/scripts/install-amazon-ecr-credential-helper new file mode 100644 index 0000000..2ff3f45 --- /dev/null +++ b/scripts/install-amazon-ecr-credential-helper @@ -0,0 +1,45 @@ +#!/bin/bash + +set -euo pipefail + +usage=$(cat << EOM + Download and install amazon-ecr-credential-helper for Docker client. + usage: $(basename $0) [-h] VERSION + Options: + -h Print help message then exit + Arguments: + VERSION Version number of amazon-ecr-login-helper to download and install (e.g. 0.7.1) +EOM +) + +function display_help { + echo "${usage}" 1<&2 +} + +while getopts "h" arg; do + case "${arg}" in + h ) display_help + exit 0 + ;; + + * ) display_help + exit 1 + ;; + esac +done +shift $((OPTIND-1)) + +version="${1:-}" +if [[ -z "${version}" ]]; then + echo "❌ no version given" + display_help + exit 1 +fi + +install_path="$(dirname "$(which docker-credential-wincred.exe)")" +curl -Lo "${install_path}/docker-credential-ecr-login.exe" "https://amazon-ecr-credential-helper-releases.s3.us-east-2.amazonaws.com/${version}/windows-amd64/docker-credential-ecr-login.exe" + +# Update Docker to use ecr-login instead of wincred. +modified_config="$(mktemp)" +jq '.credsStore="ecr-login"' ~/.docker/config.json > "${modified_config}" +mv -f "${modified_config}" ~/.docker/config.json \ No newline at end of file