Merge "Improve image and network cleanup procedure"

This commit is contained in:
Zuul 2021-03-01 10:45:08 +00:00 committed by Gerrit Code Review
commit 9c93bfa12a
4 changed files with 29 additions and 10 deletions

View File

@ -101,14 +101,13 @@ zun_docker_api_version: false
zun_docker_bind_host: "{{ openstack_service_bind_address | default('0.0.0.0') }}"
zun_docker_bind_port: 2375
# Should Docker image cache data be periodically cleaned up?
zun_docker_prune_images: False
# Time period for which to clean up old Docker data. The options are hour, day,
# month, or year. (string value)
zun_docker_prune_frequency: hour
# Which Docker data to clean up when running the above periodic task
zun_docker_prune_images: True
zun_docker_prune_networks: True
## Manually specified zun UID/GID
# Deployers can specify a UID for the zun user as well as the GID for the
# zun group if needed. This is commonly used in environments where shared

View File

@ -0,0 +1,7 @@
---
features:
- |
Adds a 'zun-docker-cleanup' script to the Zun compute virtualenv which can
be used to clean up cached Docker images held on compute hosts. This can be
run on a timer by setting the 'zun_docker_prune_images' variable or
executed manually by adding '--force' to the script.

View File

@ -295,6 +295,11 @@
group: "root"
mode: "0755"
- name: Set state for timed data cleanup
file:
path: "/var/tmp/zun-docker-cleanup.disabled"
state: "{{ zun_docker_prune_images | ternary('absent', 'touch') }}"
- name: Remove legacy systemd docker override
file:
path: "/etc/systemd/system/docker.service.d/zun-docker.conf"

View File

@ -1,7 +1,15 @@
#!/bin/bash
{% if zun_docker_prune_images %}
docker image prune -a -f --filter "until=1h"
{% endif %}
{% if zun_docker_prune_networks %}
docker network prune -f --filter "until=1h"
{% endif %}
# If the disabled file is present, don't allow the script
# to run unless it is forced.
if [ -e "/var/tmp/zun-docker-cleanup.disabled" ] && [ "$1" != "--force" ]; then
echo "Timed cleanup of Docker data is disabled"
echo "To force a cleanup, re-run this script with '--force'"
exit 0
fi
# Clear dangling images from Docker
docker image prune -f
# Clear old images from Zun cache directory
find /var/cache/zun -amin +1440 -type f -exec rm -fv {} \;