Created
April 28, 2020 19:03
-
-
Save mcindea/6db1d926206f40bdb7251126a040b521 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# ./find-ecr-image.sh 1234567890.dkr.ecr.eu-west-1.amazonaws.com/supersecret:tag | |
REGISTRY_ID="${1%%.*}" | |
IMAGE_TAG=${1##*:} | |
REPOSITORY="$(echo ${1%%:*} | cut -d / -f 2,3)" | |
if [[ -z "$REGISTRY_ID" ]] || [[ -z "$IMAGE_TAG" ]] || [[ -z "$REPOSITORY" ]] ; then | |
echo "Usage: $( basename $0 ) url:tag" | |
echo "Example: $( basename $0 NNNNNNNNN.dkr.ecr.eu-west-1.amazonaws.com/something:master) " | |
exit 1 | |
fi | |
IMAGE_META="$( aws ecr describe-images --registry-id $REGISTRY_ID --repository-name=$REPOSITORY --image-ids=imageTag=$IMAGE_TAG 2> /dev/null )" | |
if [[ $? == 0 ]]; then | |
IMAGE_TAGS="$( echo ${IMAGE_META} | jq '.imageDetails[0].imageTags[0]' -r )" | |
if [[ "$(echo $IMAGE_TAGS)" == "$(echo $IMAGE_TAG)" ]];then | |
echo "$1 found" | |
else | |
echo "$IMAGE_TAG not found or the JSON response changed" | |
exit 2 | |
fi | |
else | |
echo "$1 not found" | |
exit 1 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment