From 90dad9ebc0be15c643df8f5f6f2d5ebe6949ccaf Mon Sep 17 00:00:00 2001 From: MENTAL <35723598+thisis-mental@users.noreply.github.com> Date: Wed, 29 Jul 2020 21:36:43 +0200 Subject: [PATCH 1/2] Update config.py --- pyouroboros/config.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/pyouroboros/config.py b/pyouroboros/config.py index 5f198f3b..e004edb9 100644 --- a/pyouroboros/config.py +++ b/pyouroboros/config.py @@ -8,7 +8,8 @@ class Config(object): 'PROMETHEUS_PORT', 'NOTIFIERS', 'REPO_USER', 'REPO_PASS', 'CLEANUP', 'RUN_ONCE', 'CRON', 'INFLUX_URL', 'INFLUX_PORT', 'INFLUX_USERNAME', 'INFLUX_PASSWORD', 'INFLUX_DATABASE', 'INFLUX_SSL', 'INFLUX_VERIFY_SSL', 'DATA_EXPORT', 'SELF_UPDATE', 'LABEL_ENABLE', 'DOCKER_TLS', 'LABELS_ONLY', - 'DRY_RUN', 'MONITOR_ONLY', 'HOSTNAME', 'DOCKER_TLS_VERIFY', 'SWARM', 'SKIP_STARTUP_NOTIFICATIONS'] + 'DRY_RUN', 'MONITOR_ONLY', 'HOSTNAME', 'DOCKER_TLS_VERIFY', 'SWARM', 'SKIP_STARTUP_NOTIFICATIONS', + 'CLEANUP_UNUSED_VOLUMES'] hostname = environ.get('HOSTNAME') interval = 300 @@ -22,6 +23,7 @@ class Config(object): data_export = None log_level = 'info' cleanup = False + cleanup_unused_volumes = False run_once = False dry_run = False monitor_only = False @@ -94,7 +96,7 @@ def parse(self): print(e) elif option in ['CLEANUP', 'RUN_ONCE', 'INFLUX_SSL', 'INFLUX_VERIFY_SSL', 'DRY_RUN', 'MONITOR_ONLY', 'SWARM', 'SELF_UPDATE', 'LABEL_ENABLE', 'DOCKER_TLS', 'LABELS_ONLY', 'DOCKER_TLS_VERIFY', - 'SKIP_STARTUP_NOTIFICATIONS']: + 'SKIP_STARTUP_NOTIFICATIONS', 'CLEANUP_UNUSED_VOLUMES']: if env_opt.lower() in ['true', 'yes']: setattr(self, option.lower(), True) elif env_opt.lower() in ['false', 'no']: From 4dfbaf25cdc47d097f6e9ae22c233ce6470e6705 Mon Sep 17 00:00:00 2001 From: MENTAL <35723598+thisis-mental@users.noreply.github.com> Date: Wed, 29 Jul 2020 21:38:26 +0200 Subject: [PATCH 2/2] Prune volumes --- pyouroboros/dockerclient.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/pyouroboros/dockerclient.py b/pyouroboros/dockerclient.py index 7e56fc56..ed9588a7 100644 --- a/pyouroboros/dockerclient.py +++ b/pyouroboros/dockerclient.py @@ -372,6 +372,13 @@ def update(self): self.client.images.remove(current_image.id) except APIError as e: self.logger.error("Could not delete old image for %s, Error: %s", container.name, e) + + if self.config.cleanup_unused_volumes: + try: + self.docker.client.volumes.prune() + except APIError as e: + self.logger.error("Could not delete unused volume for %s, Error: %s", container.name, e) + updated_count += 1 self.logger.debug("Incrementing total container updated count")