Skip to content

Commit

Permalink
clean registry when disk util over 40 percent
Browse files Browse the repository at this point in the history
  • Loading branch information
zniu1011 committed Sep 20, 2024
1 parent 74a6367 commit c5240e8
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
11 changes: 9 additions & 2 deletions images/fcos-bastion-image/root/usr/bin/clean-registries.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,21 @@ wait_for_container_running() {
mapfile -t ports < <(systemctl list-units 'registry@*' --no-pager --quiet | awk -F'[@.]' '{print $2}')
for port in "${ports[@]}"; do
disk_use=$(df /opt/registry-"${port}" --output='pcent' | grep -o '[0-9]*')
if [ "$disk_use" -gt 85 ]; then
rm -rf /opt/registry-"${port}"/data/docker/registry/v2/repositories/*
if [ "$disk_use" -gt 50 ]; then
for dir in `find /opt/registry-"${port}"/data/docker/registry/v2/repositories/ -maxdepth 1 -type d -mtime +1`; do
find ${dir}/release/_manifests/tags/ -name link -type f -exec rm -f {} \;
done
sed -i -e '/delete/{n;s/enabled:.*/enabled: true/;}' /opt/registry-"${port}"/config.yaml
sed -i -e '/readonly/{n;s/enabled:.*/enabled: true/;}' /opt/registry-"${port}"/config.yaml
systemctl restart registry@"${port}".service
wait_for_container_running registry-"${port}"
podman exec registry-"${port}" /bin/registry garbage-collect /etc/docker/registry/config.yml
sed -i -e '/delete/{n;s/enabled:.*/enabled: false/;}' /opt/registry-"${port}"/config.yaml
sed -i -e '/readonly/{n;s/enabled:.*/enabled: false/;}' /opt/registry-"${port}"/config.yaml
systemctl restart registry@"${port}".service
for dir in `find /opt/registry-"${port}"/data/docker/registry/v2/repositories/ -maxdepth 1 -type d -mtime +1`; do
rm -rf ${dir}
done
fi
done

Expand Down
5 changes: 4 additions & 1 deletion images/fcos-bastion-image/root/usr/bin/gen_registry_file.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,14 @@ http:
key: /certs/domain.key
storage:
delete:
enabled: true
enabled: false
cache:
blobdescriptor: inmemory
filesystem:
rootdirectory: /var/lib/registry
maintenance:
readonly:
enabled: false
auth:
htpasswd:
realm: Registry Realm
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
[Unit]
Description=Timer to cleanup mirrored registries caches on boot
Description=Timer to cleanup mirrored registries caches on boot and 6 hours once
[Timer]
OnBootSec=5min
OnCalendar=*-*-* *:00:00
OnCalendar=*-*-* */6:00:00

[Install]
WantedBy=timers.target

0 comments on commit c5240e8

Please sign in to comment.