Skip to content

Commit

Permalink
tasks: Regularly clean up leftover containers and outdated images
Browse files Browse the repository at this point in the history
Our bots accumulate outdated task containers which eat a lot of space
over time. This will become worse now with automated tasks updates from
commit 4824188.

Our machinery also sometimes leaks exited/failed containers, clean them
up as well.
  • Loading branch information
martinpitt committed Dec 6, 2024
1 parent 4824188 commit 00afb88
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 0 deletions.
9 changes: 9 additions & 0 deletions ansible/roles/tasks-systemd/cockpituous-janitor.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[Unit]
Description=Clean up cockpituous cruft

[Service]
Type=oneshot
# remove leftover containers
ExecStart=/bin/sh -ec 'podman ps -q --filter status=exited | xargs -r podman rm'
# remote old task images; this is opportunistic -- it won't remove used images, but will fail on them
ExecStart=-/usr/bin/podman rmi --all
7 changes: 7 additions & 0 deletions ansible/roles/tasks-systemd/cockpituous-janitor.timer
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[Unit]
Description=Regularly clean up cockpituous cruft

[Timer]
OnBootSec=1h
OnUnitActiveSec=24h
AccuracySec=15min
12 changes: 12 additions & 0 deletions ansible/roles/tasks-systemd/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,18 @@
'--env=COCKPIT_GITHUB_TOKEN_FILE=/run/secrets/github-token',
]
- name: Create janitor service
copy:
src: "{{ role_path }}/cockpituous-janitor.service"
dest: /etc/systemd/system/cockpituous-janitor.service
mode: preserve

- name: Create janitor timer
copy:
src: "{{ role_path }}/cockpituous-janitor.timer"
dest: /etc/systemd/system/cockpituous-janitor.timer
mode: preserve

- name: Set up systemd service for cockpit/tasks
shell: |
export INSTANCES={{ instances | default(1) }}
Expand Down
1 change: 1 addition & 0 deletions tasks/install-service
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ cat <<EOF > /etc/systemd/system/[email protected]
Description=Cockpit Tasks %i
Requires=podman.socket
After=podman.socket
Wants=cockpituous-janitor.timer
[Service]
Restart=always
Expand Down

0 comments on commit 00afb88

Please sign in to comment.