forked from xiyangxixi/docker
-
Notifications
You must be signed in to change notification settings - Fork 23
/
clean_harbor_image.sh
47 lines (37 loc) · 1.3 KB
/
clean_harbor_image.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
#!/bin/bash
URL="http://192.168.0.241"
USER="admin"
PASS="Harbor12345"
PRO="library"
HARBOR_PAHT="/iba/harbor"
# 软删除 harbor tags
del_tags()
{
echo "软删除 ${rp}/${t}"
curl -X DELETE -H 'Accept: text/plain' -u ${USER}:${PASS} "${URL}/api/repositories/${rp}/tags/${t}"
}
# 硬删除 harbor tags
har_del_tags()
{
cd ${HARBOR_PAHT}
docker-compose -f docker-compose.yml -f docker-compose.clair.yml stop
docker run -it --name gc --rm --volumes-from registry vmware/registry:2.6.2-photon garbage-collect /etc/registry/config.yml
docker-compose -f docker-compose.yml -f docker-compose.clair.yml start
}
# 获取 project id
PID=$(curl -s -X GET --header 'Accept: application/json' "${URL}/api/projects"|grep -w -B 2 "${PRO}" |grep "project_id"|awk -F '[:, ]' '{print $7}')
#echo ${PID}
# 拿获取到的 projects_id 获取 repositories
REPOS=$(curl -s -X GET --header 'Accept: application/json' "${URL}/api/repositories?project_id=${PID}"|grep "name"|awk -F '"' '{print $4}')
for rp in ${REPOS}
do
echo ${rp}
TAGS=$(curl -s -X GET --header 'Accept: application/json' "${URL}/api/repositories/${rp}/tags"|grep \"name\"|awk -F '"' '{print $4}'|sort -r |awk 'NR > 9 {print $1}')
for t in ${TAGS}
do
echo ${t}
del_tags
done
echo "===================="
done
har_del_tags