Totally revamp cluster chart configs
This commit is contained in:
49
scripts/gitlab-prune-registry.sh
Executable file
49
scripts/gitlab-prune-registry.sh
Executable file
@@ -0,0 +1,49 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
token=UTjgSspYQcX-BVUd1UsC
|
||||
api=https://gitlab.com/api/v4
|
||||
|
||||
prune () {
|
||||
id=$1
|
||||
reg=$(curl -s --header "PRIVATE-TOKEN: $token" \
|
||||
"$api/projects/$id/registry/repositories" \
|
||||
| json_pp | sed -n 's/^ *"id" *: *\([0-9]\+\).*/\1/p')
|
||||
for i in $reg; do
|
||||
curl -s --request DELETE --data 'keep_n=10' \
|
||||
--data 'name_regex=.*[0-9].*' \
|
||||
--header "PRIVATE-TOKEN: $token" \
|
||||
"$api/projects/$id/registry/repositories/$i/tags"
|
||||
done
|
||||
}
|
||||
|
||||
gc () {
|
||||
pod=$(kubectl get pod -n gitlab -lapp=registry | tail -1 | cut -d' ' -f1)
|
||||
kubectl exec -n gitlab $pod -- \
|
||||
registry garbage-collect /etc/docker/registry/config.yml -m
|
||||
}
|
||||
|
||||
all () {
|
||||
groups=$(curl -s --header "PRIVATE-TOKEN: $token" "$api/groups" \
|
||||
| json_pp | sed -n 's/^ *"id" *: *\([0-9]\+\).*/\1/p')
|
||||
for g in $groups; do
|
||||
proj=$(curl -s --header "PRIVATE-TOKEN: $token" \
|
||||
"$api/groups/$g/projects?simple=true&include_subgroups=true" \
|
||||
| json_pp | sed -n 's/^ \{6\}"id" *: *\([0-9]\+\).*/\1/p')
|
||||
for p in $proj; do
|
||||
prune $p
|
||||
done
|
||||
done
|
||||
}
|
||||
|
||||
projects () {
|
||||
for i in $@; do
|
||||
prune $(echo $i | sed 's,/,%2F,g')
|
||||
done
|
||||
}
|
||||
|
||||
case $1 in
|
||||
--all) all ;;
|
||||
*) projects $@
|
||||
esac
|
||||
|
||||
gc
|
||||
Reference in New Issue
Block a user