docker: add housekeeping #105

Merged
mg merged 12 commits from dhc into master 2024-06-05 18:58:29 +02:00
6 changed files with 75 additions and 0 deletions

View file

@ -19,3 +19,6 @@
- role: mgrote_docker_compose_inline - role: mgrote_docker_compose_inline
tags: "compose" tags: "compose"
become: true 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