Skip to content

Commit 1319288

Browse files
authored
Fix ECR login and add install-awscli script (#332)
1 parent a85c4fd commit 1319288

File tree

4 files changed

+81
-2
lines changed

4 files changed

+81
-2
lines changed

scripts/ecr-public-login

+13-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,21 @@
11
#!/bin/bash
22
set -euo pipefail
33

4+
SCRIPTPATH="$( cd "$(dirname "$0")" ; pwd -P )"
5+
BUILD_DIR=$SCRIPTPATH/../build/
6+
export PATH="${BUILD_DIR}:${PATH}"
7+
48
if [[ -z "${ECR_REGISTRY}" ]]; then
59
echo "The env var ECR_REGISTRY must be set"
610
exit 1
711
fi
812

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}
13+
function exit_and_fail() {
14+
echo "❌ Failed to login to ECR Public Repo!"
15+
}
16+
17+
trap exit_and_fail INT TERM ERR
18+
19+
"${SCRIPTPATH}/install-awscli"
20+
21+
docker login --username AWS --password="$(aws ecr-public get-login-password --region us-east-1)" "${ECR_REGISTRY}"

scripts/install-awscli

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#!/bin/bash
2+
set -euo pipefail
3+
4+
SCRIPTPATH="$( cd "$(dirname "$0")" ; pwd -P )"
5+
BUILD_DIR=$SCRIPTPATH/../build/
6+
7+
VERSION="2.1.13"
8+
os=$(uname)
9+
arch=$(uname -m)
10+
11+
function exit_and_fail() {
12+
echo "❌ Unable to install awscli v${VERSION} for OS ${os} and arch ${arch}"
13+
}
14+
trap exit_and_fail INT TERM ERR
15+
16+
if [[ "${os}" = "Linux" ]]; then
17+
curl "https://awscli.amazonaws.com/awscli-exe-linux-${arch}-${VERSION}.zip" -o "${BUILD_DIR}/awscliv2.zip"
18+
unzip "${BUILD_DIR}/awscliv2.zip" -d "${BUILD_DIR}/awscliv2"
19+
${BUILD_DIR}/awscliv2/aws/install -i ${BUILD_DIR}/awscliv2 -b "${BUILD_DIR}"
20+
elif [[ "${os}" = "Darwin" ]]; then
21+
curl "https://awscli.amazonaws.com/AWSCLIV2-${VERSION}.pkg" -o "${BUILD_DIR}/awscliv2.pkg"
22+
CHOICES_XML="${BUILD_DIR}/aws-cli-mac.plist"
23+
cat << EOF > "${CHOICES_XML}"
24+
<?xml version="1.0" encoding="UTF-8"?>
25+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
26+
<plist version="1.0">
27+
<array>
28+
<dict>
29+
<key>choiceAttribute</key>
30+
<string>customLocation</string>
31+
<key>attributeSetting</key>
32+
<string>${BUILD_DIR}</string>
33+
<key>choiceIdentifier</key>
34+
<string>default</string>
35+
</dict>
36+
</array>
37+
</plist>
38+
EOF
39+
installer -pkg ${BUILD_DIR}/awscliv2.pkg \
40+
-target CurrentUserHomeDirectory \
41+
-applyChoiceChangesXML "${CHOICES_XML}"
42+
ln -s "${BUILD_DIR}/aws-cli/aws" "${BUILD_DIR}/aws"
43+
else # windows
44+
choco install awscli --version ${VERSION} --force -y || :
45+
fi
46+
47+
echo "✅ Install AWS CLI v${VERSION} for OS ${os} and arch ${arch}"

scripts/retag-docker-images

+20
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,31 @@ while getopts "p:o:n:v:" opt; do
4545
esac
4646
done
4747

48+
function exit_and_fail() {
49+
echo "❌ Failed retagging docker images"
50+
}
51+
52+
trap "exit_and_fail" INT TERM ERR
53+
4854
for os_arch in "${PLATFORMS[@]}"; do
4955
os=$(echo $os_arch | cut -d'/' -f1)
5056
arch=$(echo $os_arch | cut -d'/' -f2)
5157

5258
old_img_tag="$OLD_IMAGE_REPO:$VERSION-$os-$arch"
5359
new_img_tag="$NEW_IMAGE_REPO:$VERSION-$os-$arch"
60+
61+
current_os=$(uname)
62+
# Windows will append '\r' to the end of $img which
63+
# results in docker failing to create the manifest due to invalid reference format.
64+
# However, MacOS does not recognize '\r' as carriage return
65+
# and attempts to remove literal 'r' chars; therefore, made this so portable
66+
if [[ $current_os != "Darwin" ]]; then
67+
old_img_tag=$(echo $old_img_tag | sed -e 's/\r//')
68+
new_img_tag=$(echo $new_img_tag | sed -e 's/\r//')
69+
fi
70+
5471
docker tag ${old_img_tag} ${new_img_tag}
72+
echo "✅ Successfully retagged docker image $old_img_tag to $new_img_tag"
5573
done
74+
75+
echo "✅ Done Retagging!"

test/shellcheck/run-shellcheck

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export PATH="${BUILD_DIR}/shellcheck-v${SHELLCHECK_VERSION}:$PATH"
2121
shell_files=()
2222
while IFS='' read -r line; do
2323
shell_files+=("$line");
24-
done < <(grep -Rnl -e '#!.*/bin/bash' -e '#!.*/usr/bin/env bash' ${SCRIPTPATH}/../../)
24+
done < <(grep -Rnl --exclude-dir=build -e '#!.*/bin/bash' -e '#!.*/usr/bin/env bash' ${SCRIPTPATH}/../../)
2525
shellcheck -S warning "${shell_files[@]}"
2626

2727
echo "✅ All shell scripts look good! 😎"

0 commit comments

Comments
 (0)