-
Notifications
You must be signed in to change notification settings - Fork 1
/
docker-hub-list-tags.sh
executable file
·72 lines (55 loc) · 1.42 KB
/
docker-hub-list-tags.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/bin/bash
set -eo pipefail
jqExpression='.results[].name'
self="$(basename "$0")"
usage() {
cat <<-EOUSAGE
usage: $self [options] repo [repo ...]
ie: $self library/docker
$self library/docker tianon/docker-master | sort -uV
$self --jq '.results[]' tianon/syncthing
$self --jq '.results[] | [ .name, (.full_size | tostring), .last_updated ] | join("\\t")' tianon/syncthing | sort -V | column -ts \$'\\t'
options:
--jq='$jqExpression'
modify the "jq" expression used to extract results
EOUSAGE
}
opts="$(getopt -o 'h?' --long 'help,jq:' -- "$@" || { usage >&2 && false; })"
eval set -- "$opts"
while true; do
flag="$1"
shift
case "$flag" in
--jq) jqExpression="$1"; shift ;;
--help|-h|'-?') usage; exit 0 ;;
--) break ;;
*)
{
echo "error: unknown flag: $flag"
usage
} >&2
exit 1
;;
esac
done
if [ "$#" -eq 0 ]; then
echo >&2 'error: expected at lease one "repo" argument'
usage >&2
exit 1
fi
_all() {
local repo="$1"; shift
local nextPage="https://hub.docker.com/v2/repositories/${repo}/tags/?page_size=100"
while true; do
local page="$(curl -fsSL "$nextPage")"
[ "$(echo "$page" | jq --raw-output '.results | length')" -gt 0 ] || break
echo "$page" | jq --raw-output "$jqExpression"
nextPage="$(echo "$page" | jq --raw-output '.next')"
[ "$nextPage" != 'null' ] || break
done
}
while [ "$#" -gt 0 ]; do
repo="$1"
shift
_all "$repo"
done