Skip to content

Commit

Permalink
Merge pull request #6 from thisis-mental/remove-unused-volumes
Browse files Browse the repository at this point in the history
Remove unused volumes
  • Loading branch information
gmt2001 authored Aug 8, 2020
2 parents 771f4bb + 4dfbaf2 commit 931235a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
6 changes: 4 additions & 2 deletions pyouroboros/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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']:
Expand Down
7 changes: 7 additions & 0 deletions pyouroboros/dockerclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit 931235a

Please sign in to comment.