forked from cypress-io/cypress-docker-images
-
Notifications
You must be signed in to change notification settings - Fork 2
/
find-ecr-image.sh
executable file
·44 lines (38 loc) · 1.17 KB
/
find-ecr-image.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/usr/bin/env bash
# Example:
# ./find-ecr-image.sh foo/bar mytag
# via https://gist.github.com/outofcoffee/8f40732aefacfded14cce8a45f6e5eb1
USAGE="find-ecr-image — Check ECR for existing docker image
Usage:
./find-ecr-image <repository-name> <image-tag>
Example:
./find-ecr-image.sh foo/bar mytag
./find-ecr-image.sh -p public/repo mytag
Options:
<repository-name> ECR repository name
<image-tag> ECR image tag
-h Show this message
-p / --pubic Public Repository (optional)
"
help() {
echo "$USAGE"
}
if [[ $# -lt 2 ]] || [[ "$1" == "-h" ]]; then
help
exit 1
fi
if [[ "$3" == "-p" ]] || [[ "$3" == "--public" ]]; then
echo "Public"
# public repository
IMAGE_META="$( aws ecr-public describe-images --repository-name=$1 --image-ids=imageTag=$2 2> /dev/null )"
else
# private repository
IMAGE_META="$( aws ecr describe-images --repository-name=$1 --image-ids=imageTag=$2 2> /dev/null )"
fi
if [[ $? == 0 ]]; then
IMAGE_TAGS="$( echo ${IMAGE_META} | jq '.imageDetails[0].imageTags[0]' -r )"
echo "$1:$2 found"
exit 1
else
echo "$1:$2 not found"
fi