-
Notifications
You must be signed in to change notification settings - Fork 1
/
entrypoint.sh
executable file
·57 lines (46 loc) · 1.28 KB
/
entrypoint.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
56
57
#!/usr/bin/env bash
set -o errexit
set -o nounset
REST_OF_OUTPUT_PAGE=5
opts=':p:ah'
usage() {
echo "docker-tags [-p PAGE] [-a] [-h]"
echo " -p : Output the specified number of pages.( DEFAULT : 5 )"
echo " -a : Output all pages."
echo " -h : Output Help."
exit 1
}
while getopts ":${opts}" opt ; do
case "${opt}" in
a)
REST_OF_OUTPUT_PAGE=
;;
p)
REST_OF_OUTPUT_PAGE="${OPTARG}"
;;
h|\?)
usage
;;
esac
done
shift $((OPTIND -1))
DOCKER_IMAGE="${1}"
# Prepend "library" string if a parameter is not contains "/" char.
echo "${DOCKER_IMAGE}" \
| grep '/' >/dev/null \
|| DOCKER_IMAGE="library/${DOCKER_IMAGE}"
URL="https://registry.hub.docker.com/v2/repositories/${DOCKER_IMAGE}/tags/"
(
echo "TAG SIZE UPDATED"
echo "----- ----- -----"
while [ "${URL}" != null ]; do
[[ -n "${REST_OF_OUTPUT_PAGE}" ]] && [[ ! "$((REST_OF_OUTPUT_PAGE--))" > 0 ]] && break
RESPONSE="$(
curl --keepalive-time 300 -4 --silent "${URL}" 2>/dev/null
)"
URL="$(echo "${RESPONSE}" | jq -r '."next"')"
echo "${RESPONSE}" | jq -r '."results"[] | .name+" "+(.full_size|tostring)+" "+.last_updated'
done
) | while read -r TAG SIZE LAST_UPDATED; do
printf "%-20s\t%10s\t%s\n" "${TAG}" "${SIZE}" "${LAST_UPDATED}"
done