David K. Bainbridge | c4e0fc5 | 2016-11-14 12:03:35 -0800 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | #D Displays information about Docker images in the CORD POD registry |
| 3 | |
| 4 | PROG=$(echo $(basename $0) | sed -e 's/^cord-/cord /g') |
| 5 | |
| 6 | usage() { |
| 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 | |
| 12 | usage_list() { |
| 13 | echo "usage $PROG list [--json|-j]" |
| 14 | echo " json display output as JSON object" |
| 15 | echo " help this message" |
| 16 | } |
| 17 | |
| 18 | REG=docker-registry:5000 |
| 19 | while [ $# -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 |
| 35 | done |
| 36 | |
| 37 | COMMAND=$1; shift |
| 38 | |
| 39 | case $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. Bainbridge | 012f330 | 2016-12-07 15:35:04 -0800 | [diff] [blame^] | 66 | for t in $(curl -sSL http://$REG/v2/$i/tags/list | jq '.tags | .[]' | sed -e 's/"//g'); do |
David K. Bainbridge | c4e0fc5 | 2016-11-14 12:03:35 -0800 | [diff] [blame] | 67 | 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. Bainbridge | 012f330 | 2016-12-07 15:35:04 -0800 | [diff] [blame^] | 78 | for t in $(curl -sSL http://$REG/v2/$i/tags/list | jq '.tags + [] | .[]' | sed -e 's/"//g'); do |
David K. Bainbridge | c4e0fc5 | 2016-11-14 12:03:35 -0800 | [diff] [blame] | 79 | /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 | ;; |
| 94 | esac |