This repository has been archived by the owner on Feb 24, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathregistry.sh
executable file
·116 lines (80 loc) · 2.07 KB
/
registry.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#!/bin/bash
ip=localhost
registry=$ip:5000
usage()
{
echo -e "\033[34m Usage: \033[0m"
echo "$0 [ -h | --help ]"
echo "$0 [ -l | --list ]"
echo "$0 [ -l | --delete ]"
echo "$0 [ -c | --license ]"
exit 0;
}
license()
{
cd licenses
./validate-licenses.sh
}
delete()
{
registry="$ip:5000"
echo $registry
name=$1
echo $name
if [ -z $name ]; then
usage
fi
curl -v -sSL -X DELETE "http://${registry}/v2/${name}/manifests/$(
curl -sSL -I \
-H "Accept: application/vnd.docker.distribution.manifest.v2+json" \
"http://${registry}/v2/${name}/manifests/$(
curl -sSL "http://${registry}/v2/${name}/tags/list" | jq -r '.tags[0]'
)" \
| awk '$1 == "Docker-Content-Digest:" { print $2 }' \
| tr -d $'\r' \
)"
# REG_POD=`kubectl get pods -n kube-system -lactual-registry=true --no-headers | awk '{print $1}'`
# kubectl exec $REG_POD -n kube-system -- rm -rf /var/lib/registry/docker/registry/v2/repositories/$name
# kubectl exec $REG_POD -n kube-system -- bin/registry garbage-collect /etc/docker/registry/config.yml
}
list() {
curl --silent -X GET $ip:5000/v2/_catalog
images=`curl --silent -X GET localhost:5000/v2/_catalog | awk -F'[][]' '{print $2}'`
IFS=','
for i in $images
do
image=`curl --silent -X GET localhost:5000/v2/${i//[$'"']}/tags/list`
image=${image//null/ '\033[31m' -- deleted -- '\033[0m' }
echo $image
done
exit 0
}
while true; do
case "$1" in
### BEGIN ###
-l | --list )
case "$2" in
version ) list $2
break;;
*) list $2
break;;
esac
break;;
### END ###
-d | --delete )
delete $2
break;;
-c | --license )
license
break;;
-h | --help )
usage;
break;;
--)
break;;
*)
usage
break;;
esac
done
exit 0