docker: add housekeeping (#105)
ci/woodpecker/push/gitleaks Pipeline was successful Details
ci/woodpecker/push/ansible-lint Pipeline was successful Details

Reviewed-on: #105
Co-authored-by: Michael Grote <michael.grote@posteo.de>
Co-committed-by: Michael Grote <michael.grote@posteo.de>
This commit is contained in:
Michael Grote 2024-06-05 18:58:28 +02:00 committed by Michael Grote
parent f33ba3c932
commit d1c18d270a
6 changed files with 75 additions and 0 deletions

View File

@ -19,3 +19,6 @@
- role: mgrote_docker_compose_inline
tags: "compose"
become: true
- role: mgrote_docker_housekeeping
tags: "housekeeping"
become: true

View File

@ -0,0 +1,3 @@
---
docker_housekeeping_schedule: "weekly"
...

View File

@ -0,0 +1,14 @@
---
- name: systemctl daemon-reload
become: true
ansible.builtin.systemd:
daemon_reload: true
notify: Start timer
- name: Start timer
become: true
ansible.builtin.systemd:
name: docker_housekeeping.timer
state: restarted
enabled: true
notify: systemctl daemon-reload

View File

@ -0,0 +1,36 @@
---
- name: Setup docker housekeeping tasks
become: true
ansible.builtin.template:
src: docker_housekeeping.service.j2
dest: /etc/systemd/system/docker_housekeeping.service
owner: root
group: root
mode: "0644"
notify:
- systemctl daemon-reload
- name: Setup timer
become: true
ansible.builtin.template:
src: docker_housekeeping.timer.j2
dest: /etc/systemd/system/docker_housekeeping.timer
owner: root
group: root
mode: "0644"
notify:
- systemctl daemon-reload
- Start timer
- name: Enable Units
become: true
ansible.builtin.systemd:
name: "{{ item }}"
enabled: true
masked: false
with_items:
- docker_housekeeping.service
- docker_housekeeping.timer
notify:
- Start timer
...

View File

@ -0,0 +1,8 @@
{{ file_header | default () }}
[Unit]
Description=Docker housekeeping tasks
[Service]
Type=simple
ExecStart=/usr/bin/docker system prune --force --filter "until=24h"
# https://docs.docker.com/config/pruning

View File

@ -0,0 +1,11 @@
{{ file_header | default () }}
[Unit]
Description=Timer for docker_housekeeping backups.
[Timer]
# https://wiki.archlinux.org/title/systemd/Timers
OnCalendar={{ docker_housekeeping_schedule }}
RandomizedDelaySec=30 min
[Install]
WantedBy=timers.target multi-user.target