adjusted showTags.sh and deleteTags.sh to docker.sapsailing.com

This commit is contained in:
Axel Uhl
2022-01-18 23:45:03 +01:00
parent b4d822dcb7
commit 674de4e7a2
2 changed files with 25 additions and 6 deletions
+14 -3
View File
@@ -9,7 +9,16 @@
# TOKEN_FILE can be generated using obtainToken.sh
TOKEN_FILE=~/.docker/.token
TOKEN=$(cat "${TOKEN_FILE}")
if [ -f "${TOKEN_FILE}" ]; then
TOKEN=$(cat "${TOKEN_FILE}")
AUTH_HEADER="Authorization: JWT ${TOKEN}"
else
# set username, password, and organization
read -p "Username: " UNAME
read -s -p "Password: " UPASS
echo
AUTH_HEADER="Authorization: Basic $( echo -n "${UNAME}:${UPASS}" | base64 )"
fi
REPO=$1
if [ "$REPO" = "" ]; then
echo "Usage: $0 account/repository [ <regexp1> \[ <regexp2> ... ] ]"
@@ -27,7 +36,7 @@ shift
echo "Deleting tags $* in repository ${REPO}..."
# delete images and/or tags
IMAGE_TAGS=$(curl -s -H "Authorization: JWT ${TOKEN}" https://hub.docker.com/v2/repositories/${REPO}/tags/?page_size=1000 | jq -r '.results|.[]|.name')
IMAGE_TAGS=$(curl -s -H "${AUTH_HEADER}" https://docker.sapsailing.com/v2/${REPO}/tags/list | jq -r '.tags|.[]')
for j in ${IMAGE_TAGS}
do
# echo "Checking tag $j"
@@ -39,7 +48,9 @@ do
if [[ $j =~ $k ]]; then
found=1
echo -n " - ${j} ... "
curl -X DELETE -s -H "Authorization: JWT ${TOKEN}" https://hub.docker.com/v2/repositories/${REPO}/tags/${j}/
digest=$( curl -s -X HEAD -I -i -H "Accept: application/vnd.docker.distribution.manifest.v2+json" -H "${AUTH_HEADER}" https://docker.sapsailing.com/v2/${REPO}/manifests/${j} | grep "^Docker-Content-Digest: " | sed -e 's/^Docker-Content-Digest: \([^␍]*\)␍\?$/\1/' )
URL="https://docker.sapsailing.com/v2/${REPO}/manifests/${digest}"
curl -s -X DELETE -H "${AUTH_HEADER}" "${URL}"
echo "DELETED ($?)"
fi
fi
+11 -3
View File
@@ -9,7 +9,16 @@
# TOKEN_FILE can be generated using obtainToken.sh
TOKEN_FILE=~/.docker/.token
TOKEN=$(cat "${TOKEN_FILE}")
if [ -f "${TOKEN_FILE}" ]; then
TOKEN=$(cat "${TOKEN_FILE}")
AUTH_HEADER="Authorization: JWT ${TOKEN}"
else
# set username, password, and organization
read -p "Username: " UNAME
read -s -p "Password: " UPASS
echo
AUTH_HEADER="Authorization: Basic $( echo -n "${UNAME}:${UPASS}" | base64 )"
fi
REPO=$1
if [ "$REPO" = "" ]; then
echo "Usage: $0 account/repository [ <regexp1> \[ <regexp2> ... ] ]"
@@ -22,8 +31,7 @@ fi
shift
# -------
IMAGE_TAGS=$(curl -s -H "Authorization: JWT ${TOKEN}" https://hub.docker.com/v2/repositories/${REPO}/tags/?page_size=1000 | jq -r '.results|.[]|.name')
IMAGE_TAGS=$(curl -s -H "${AUTH_HEADER}" https://docker.sapsailing.com/v2/${REPO}/tags/list | jq -r '.tags|.[]')
for j in ${IMAGE_TAGS}
do
if [ "$#" = "0" ]; then