modified dockertag: wget -> curl, add harbor-image-tag for query private harbor registry project, tags

pull/828/head
lushenle 2020-03-31 18:03:59 +08:00 committed by jmgao
parent 4dab4aed24
commit 0e988944bc
2 changed files with 54 additions and 5 deletions

View File

@ -1,11 +1,10 @@
#!/bin/bash
#
function usage() {
cat << HELP
docker-tag -- list all tags for a Docker image on a remote registry
EXAMPLE:
EXAMPLE:
- list all tags for ubuntu:
docker-tag ubuntu
@ -17,13 +16,13 @@ HELP
if [ $# -lt 1 ]; then
usage
exit 2
exit
fi
image="$1"
tags=`wget -q https://registry.hub.docker.com/v1/repositories/${image}/tags -O - | sed -e 's/[][]//g' -e 's/"//g' -e 's/ //g' | tr '}' '\n' | awk -F: '{print $3}'`
tags=$(curl -ksL https://registry.hub.docker.com/v1/repositories/${image}/tags | sed -e 's/[][]//g' -e 's/"//g' -e 's/ //g' | tr '}' '\n' | awk -F: '{print $3}')
if [ -n "$2" ]; then
tags=`echo "${tags}" | grep "$2"`
tags=$(echo "${tags}" | grep "$2")
fi
echo "${tags}"

View File

@ -0,0 +1,50 @@
#!/bin/bash
#
function usage() {
cat << HELP
harbor-image-tag -- list all tags for a Docker image on a remote Harbor Registry
EXAMPLE:
- list all images:
harbor-image-tag get_images
- list all tags for redis:
harbor-image-tag get_tags redis/redis
HELP
}
if [ $# -lt 1 ]; then
usage
exit 2
fi
USER="admin"
PASS="XXXXXXXXXXXXXXXXXX"
HURL="https://{{ HARBOR_DOMAIN }}"
MTAG=$2
function get_images() {
RTOKEN=$(curl -k -s -u ${USER}:${PASS} ${HURL}/service/token?account=${USER}\&service=harbor-registry\&scope=registry:catalog:* | grep "token" | awk -F '"' '{print $4}')
RLIST=$(curl -k -s -H "authorization: bearer ${RTOKEN} " ${HURL}/v2/_catalog | awk -F '[' '{print $2}'|awk -F ']' '{print $1}' | sed 's/"//g')
echo ${RLIST} | tr ',' '\n'
}
function get_tags() {
TTOKEN=$(curl -iksL -X GET -u ${USER}:${PASS} ${HURL}/service/token?account=${USER}\&service=harbor-registry\&scope=repository:${MTAG}:pull | grep "token" | awk -F '"' '{print $4}')
TLIST=$(curl -ksL -X GET -H "Content-Type: application/json" -H "Authorization: Bearer ${TTOKEN}" ${HURL}/v2/${MTAG}/tags/list| awk -F '[' '{print $2}' | awk -F ']' '{print $1}' | sed 's/"//g')
echo ${TLIST} | tr ',' '\n'
}
case $1 in
get_images)
get_images
;;
get_tags)
get_tags
;;
*)
usage
;;
esac