registry-docker/testRegistry.sh
2024-12-12 19:55:29 +01:00

53 lines
1.9 KiB
Bash
Executable File

#!/bin/bash
registry=https://registry-docker.gmotech.net
reg_without_proto=$(echo $registry |sed -e "s|https://||")
name=ubuntu
auth="gilles:pa55w0rd"
#curl -u $auth -X GET ${registry}/v2/${name}/manifests/latest
#curl -u $auth -X GET ${registry}/v2/_catalog
#curl -u $auth -v -sSL -X DELETE "${registry}/v2/${name}/_manifests/sha256:8c0cd79cc31c13c52d7c149b67705cf908c7640578f769e34dcbf3d822180442"
#exit
echo -e "\n\n****** First step - pull origin image, tag it and push it on myregistry"
echo "press Enter to continue or ctrl-c to quit"
read
#echo "Pull sample image"
docker pull ubuntu
#echo "Login on registry"
docker login $reg_without_proto
#echo "Tag image"
docker tag $name:latest $reg_without_proto/$name:latest
#echo "Push image in registry"
docker push $reg_without_proto/$name
echo -e "\n\n****** Step2 - display registry (ToComplete)"
echo "press Enter to continue or ctrl-c to quit"
read
curl -u $auth -X GET ${registry}/v2/_catalog
#exit
echo -e "\n\n****** Step 3 - delete imgage from repository (toDo and logout)"
echo "press Enter to continue or ctrl-c to quit"
read
manifest=$(curl -u $auth -sSL -I -H \
"Accept: application/vnd.docker.distribution.manifest.v2+json" \
$registry/v2/$name/manifests/latest \
| awk '$1 == "docker-content-digest:" { print $2 }'| tr -d $'\r')
curl -u $auth -v -s -X DELETE "${registry}/v2/${name}/manifests/${manifest}"
#curl -u $auth -v -s -X DELETE "${registry}/v2/${name}/blobs/${manifest}"
#curl -u $auth -v -s -X DELETE "${registry}/v2/${name}/_manifests/${manifest}"
docker exec -it registry bin/registry garbage-collect /etc/docker/registry/config.yml
docker logout registry-docker.gmotech.net
echo -e "\n\n****** Step 4 - delete image from local"
echo "press Enter to continue or ctrl-c to quit"
read
docker image rm registry-docker.gmotech.net/ubuntu
docker image rm ubuntu
sudo rm -rf /home/docker/registry/data/docker/registry/v2/repositories/${name}
docker compose down
docker compose up -d