-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwait-for-image.sh
executable file
·55 lines (46 loc) · 1.21 KB
/
wait-for-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
45
46
47
48
49
50
51
52
53
54
55
#!/usr/bin/env bash
#
# Wait for an image to appear on Quay.io
#
set -euo pipefail
NAME_TAG="${1-}"
QUAY_TOKEN="${2-}"
# Seconds:
INTERVAL="${3-30}"
TIME_LIMIT="${4-2400}"
check_not_empty \
NAME_TAG
IFS=: read -r NAME TAG <<<"$NAME_TAG"
check_not_empty \
NAME \
TAG \
INTERVAL \
TIME_LIMIT
find_tag() {
URL="https://quay.io/api/v1/repository/$1/tag?specificTag=$2"
CURL_PARAMS+=( "--silent" "--show-error" "--fail" "--location" "$URL" )
if [ -n "$QUAY_TOKEN" ]; then
>&2 gh_log notice "Connecting to Quay with token"
CURL_PARAMS+=( "-H" "Authorization: Bearer $QUAY_TOKEN" )
else
>&2 gh_log notice "Connecting to Quay without token"
fi
curl "${CURL_PARAMS[@]}" | jq -r ".tags[0].name"
}
# bash built-in variable
SECONDS=0
FOUND_TAG=""
while [ "$SECONDS" -le "$TIME_LIMIT" ]; do
FOUND_TAG=$(find_tag "$NAME" "$TAG")
if [ "$FOUND_TAG" = "$TAG" ]; then
gh_log notice "Image '$NAME:$TAG' has been found on Quay.io."
exit 0
fi
if [ "$INTERVAL" -eq 0 ]; then
break
fi
echo "Waiting $INTERVAL more seconds for $NAME:$TAG..."
sleep "$INTERVAL"
done
gh_log error "Image '$NAME:$TAG' has not been found on Quay.io."
exit 1