blob: 45b6cdd76e8a3e80220279f66936f87113270bf4 [file] [log] [blame]
David K. Bainbridgec4e0fc52016-11-14 12:03:35 -08001#!/bin/bash
2#D Displays information about Docker images in the CORD POD registry
3
4PROG=$(echo $(basename $0) | sed -e 's/^cord-/cord /g')
5
6usage() {
7 echo "usage: $PROG [-r|--registry <registry] <sub-command> [options]"
8 echo " list display the Docker images in the registry"
9 echo " help this message"
10}
11
12usage_list() {
13 echo "usage $PROG list [--json|-j]"
14 echo " json display output as JSON object"
15 echo " help this message"
16}
17
18REG=docker-registry:5000
19while [ $# -gt 0 ]; do
20 case $1 in
21 -r|--registry)
22 shift
23 REG=$1
24 ;;
25 -*)
26 echo "Unknown option '$1'"
27 usage
28 exit 1
29 ;;
30 *)
31 break
32 ;;
33 esac
34 shift
35done
36
37COMMAND=$1; shift
38
39case $COMMAND in
40 list)
41 DO_JSON=0
42 while [ $# -gt 0 ]; do
43 case $1 in
44 json|--json|-j)
45 DO_JSON=1
46 ;;
47 help|--help|-h)
48 usage_list
49 exit 0
50 ;;
51 *)
52 >&2 echo "Unknown option '$1'"
53 usage_list
54 exit 1
55 ;;
56 esac
57 shift
58 done
59
60 if [ $DO_JSON -eq 1 ]; then
61 /bin/echo -n '{"registries":['
62 COMMA=
63 for i in $(curl -sSL http://$REG/v2/_catalog | jq '.repositories | .[]' | sed -e 's/"//g'); do
64 /bin/echo -n "$COMMA{\"registry\":\"${REG}/$i\",\"tags\":["
65 C2=
David K. Bainbridge012f3302016-12-07 15:35:04 -080066 for t in $(curl -sSL http://$REG/v2/$i/tags/list | jq '.tags | .[]' | sed -e 's/"//g'); do
David K. Bainbridgec4e0fc52016-11-14 12:03:35 -080067 echo -n "${C2}\"$t\""
68 C2=","
69 done
70 /bin/echo -n "]}"
71 COMMA=","
72 done
73 echo -n "]}"
74 else
75 OUT=$(mktemp)
76 echo "REPOSITORY,TAG" > $OUT
77 for i in $(curl -sSL http://$REG/v2/_catalog | jq '.repositories | .[]' | sed -e 's/"//g'); do
David K. Bainbridge012f3302016-12-07 15:35:04 -080078 for t in $(curl -sSL http://$REG/v2/$i/tags/list | jq '.tags + [] | .[]' | sed -e 's/"//g'); do
David K. Bainbridgec4e0fc52016-11-14 12:03:35 -080079 /bin/echo -e "${REG}/$i,$t" >> $OUT
80 done
81 done
82 cat $OUT | column -s , -t
83 rm -f $OUT
84 fi
85 ;;
86 help)
87 usage
88 exit 0
89 ;;
90 *)
91 usage
92 exit 1
93 ;;
94esac