From 95730a6a9693cf21e8f678dc9aa5ec058576e409 Mon Sep 17 00:00:00 2001 From: saibotk Date: Sat, 15 Aug 2020 21:30:33 +0200 Subject: [PATCH] docker-cleanup: Add role to prune old images --- camo.yml | 1 + codimd.yml | 1 + docker-ipv6-nat.yml | 1 + gitlab-runner.yml | 1 + gitlab.yml | 1 + keycloak.yml | 1 + mastodon.yml | 1 + minecraft-blockmap.yml | 1 + minecraft.yml | 1 + minio.yml | 1 + monitoring.yml | 2 ++ roles/docker-cleanup/README.md | 24 ++++++++++++++++++++++++ roles/docker-cleanup/meta/main.yml | 15 +++++++++++++++ roles/docker-cleanup/tasks/main.yml | 25 +++++++++++++++++++++++++ static_websites.yml | 1 + teamspeak.yml | 1 + unicorns_website.yml | 1 + 17 files changed, 79 insertions(+) create mode 100644 roles/docker-cleanup/README.md create mode 100644 roles/docker-cleanup/meta/main.yml create mode 100644 roles/docker-cleanup/tasks/main.yml diff --git a/camo.yml b/camo.yml index 0f21aff..649d853 100644 --- a/camo.yml +++ b/camo.yml @@ -21,6 +21,7 @@ roles: - docker - docker-compose + - docker-cleanup - traefik - camo environment: diff --git a/codimd.yml b/codimd.yml index bcbf007..c018b1d 100644 --- a/codimd.yml +++ b/codimd.yml @@ -20,6 +20,7 @@ roles: - docker - docker-compose + - docker-cleanup - traefik - codimd environment: diff --git a/docker-ipv6-nat.yml b/docker-ipv6-nat.yml index f047473..0ccd2cb 100644 --- a/docker-ipv6-nat.yml +++ b/docker-ipv6-nat.yml @@ -20,6 +20,7 @@ roles: - docker - docker-compose + - docker-cleanup - docker-ipv6-nat environment: PYTHONPATH: /opt/python2/ansible-dependencies/lib/python2.7/site-packages diff --git a/gitlab-runner.yml b/gitlab-runner.yml index 9a74aa1..1402bd7 100644 --- a/gitlab-runner.yml +++ b/gitlab-runner.yml @@ -21,6 +21,7 @@ roles: - docker - docker-compose + - docker-cleanup - gitlab-runner environment: PYTHONPATH: /opt/python2/ansible-dependencies/lib/python2.7/site-packages diff --git a/gitlab.yml b/gitlab.yml index 2b80a09..551c6e1 100644 --- a/gitlab.yml +++ b/gitlab.yml @@ -21,6 +21,7 @@ roles: - docker - docker-compose + - docker-cleanup - traefik - gitlab environment: diff --git a/keycloak.yml b/keycloak.yml index fe4cb08..fd63e34 100644 --- a/keycloak.yml +++ b/keycloak.yml @@ -21,6 +21,7 @@ roles: - docker - docker-compose + - docker-cleanup - traefik - keycloak environment: diff --git a/mastodon.yml b/mastodon.yml index 45d293d..75c89ae 100644 --- a/mastodon.yml +++ b/mastodon.yml @@ -21,6 +21,7 @@ roles: - docker - docker-compose + - docker-cleanup - traefik - mastodon environment: diff --git a/minecraft-blockmap.yml b/minecraft-blockmap.yml index 6350165..1f2e20c 100644 --- a/minecraft-blockmap.yml +++ b/minecraft-blockmap.yml @@ -20,6 +20,7 @@ roles: - docker - docker-compose + - docker-cleanup - traefik - minecraft-blockmap environment: diff --git a/minecraft.yml b/minecraft.yml index e9ca192..772eac9 100644 --- a/minecraft.yml +++ b/minecraft.yml @@ -21,6 +21,7 @@ roles: - docker - docker-compose + - docker-cleanup - minecraft environment: PYTHONPATH: /opt/python2/ansible-dependencies/lib/python2.7/site-packages diff --git a/minio.yml b/minio.yml index 41d0c7d..742a4d8 100644 --- a/minio.yml +++ b/minio.yml @@ -21,6 +21,7 @@ roles: - docker - docker-compose + - docker-cleanup - traefik - minio environment: diff --git a/monitoring.yml b/monitoring.yml index cfc366e..7fa1f76 100644 --- a/monitoring.yml +++ b/monitoring.yml @@ -21,6 +21,7 @@ roles: - docker - docker-compose + - docker-cleanup - traefik - monitoring environment: @@ -30,6 +31,7 @@ roles: - docker - docker-compose + - docker-cleanup - telegraf environment: PYTHONPATH: /opt/python2/ansible-dependencies/lib/python2.7/site-packages diff --git a/roles/docker-cleanup/README.md b/roles/docker-cleanup/README.md new file mode 100644 index 0000000..b0338d2 --- /dev/null +++ b/roles/docker-cleanup/README.md @@ -0,0 +1,24 @@ +docker-cleanup +========= + +This will prune unused docker images older than 3 days, to keep the system clean. + +Requirements +------------ + +You will need to have docker installed with its python package to use this role. + +Role Variables +-------------- + +None + +Dependencies +------------ + +- docker + +License +------- + +GPL-3.0-only diff --git a/roles/docker-cleanup/meta/main.yml b/roles/docker-cleanup/meta/main.yml new file mode 100644 index 0000000..8f5b40a --- /dev/null +++ b/roles/docker-cleanup/meta/main.yml @@ -0,0 +1,15 @@ +galaxy_info: + author: Christoph Kern + description: Cleans up the exsting docker install + license: GPL-3.0-only + + min_ansible_version: 2.4 + + platforms: + - name: CentOS + versions: + - 7 + + galaxy_tags: [] + +dependencies: [] diff --git a/roles/docker-cleanup/tasks/main.yml b/roles/docker-cleanup/tasks/main.yml new file mode 100644 index 0000000..8488a02 --- /dev/null +++ b/roles/docker-cleanup/tasks/main.yml @@ -0,0 +1,25 @@ +--- + +# Infrastructure +# Ansible instructions to deploy the infrastructure +# Copyright (C) 2019-2020 Christoph (Sheogorath) Kern +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, version 3 of the License. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +- name: Prune docker images older than 3 days + docker_prune: + images: yes + images_filters: + dangling: false + until: 72h + become: true diff --git a/static_websites.yml b/static_websites.yml index 5130af2..90bc16b 100644 --- a/static_websites.yml +++ b/static_websites.yml @@ -22,6 +22,7 @@ roles: - docker - docker-compose + - docker-cleanup - traefik - static_websites environment: diff --git a/teamspeak.yml b/teamspeak.yml index f6aeb00..c77a7b1 100644 --- a/teamspeak.yml +++ b/teamspeak.yml @@ -20,6 +20,7 @@ roles: - docker - docker-compose + - docker-cleanup - teamspeak environment: PYTHONPATH: /opt/python2/ansible-dependencies/lib/python2.7/site-packages diff --git a/unicorns_website.yml b/unicorns_website.yml index 52fda4d..b73fc05 100644 --- a/unicorns_website.yml +++ b/unicorns_website.yml @@ -20,6 +20,7 @@ roles: - docker - docker-compose + - docker-cleanup - traefik environment: PYTHONPATH: /opt/python2/ansible-dependencies/lib/python2.7/site-packages