Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tasks: Regularly clean up leftover containers and outdated images #630

Merged
merged 2 commits into from
Dec 6, 2024

Conversation

martinpitt
Copy link
Member

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.


Our bot instances tend to look like this:

$ sudo podman ps -a
CONTAINER ID  IMAGE                                     COMMAND               CREATED       STATUS                   PORTS       NAMES
94a5d1418d0e  ghcr.io/cockpit-project/tasks:2024-10-07  python3 -c #!/usr...  11 days ago   Exited (1) 11 days ago               serene_lewin
c4aa8e31eaeb  ghcr.io/cockpit-project/tasks:2024-10-07  python3 -c #!/usr...  31 hours ago  Exited (2) 31 hours ago              funny_solomon
fb7bad7a6718  ghcr.io/cockpit-project/tasks:2024-10-07  python3 -c #!/usr...  19 hours ago  Exited (2) 19 hours ago              pensive_sanderson
81b917609411  ghcr.io/cockpit-project/tasks:latest      cockpit-tasks --v...  2 hours ago   Up 2 hours                           cockpit-tasks-1

$ sudo podman images
REPOSITORY                     TAG         IMAGE ID      CREATED       SIZE
ghcr.io/cockpit-project/tasks  latest      838edb5f6014  8 weeks ago   2.13 GB
ghcr.io/cockpit-project/tasks  2024-10-07  838edb5f6014  8 weeks ago   2.13 GB
ghcr.io/cockpit-project/tasks  2024-08-19  8effe37221cc  3 months ago  2.05 GB
ghcr.io/cockpit-project/tasks  2024-07-24  806c4c43e01b  4 months ago  2.02 GB
ghcr.io/cockpit-project/tasks  2024-07-04  8e16bff291ef  5 months ago  1.99 GB
quay.io/cockpit/tasks          2024-03-15  d63ae344d9ef  8 months ago  1.89 GB

I rolled this out, the timer started, and cleaned up all that cruft.

@martinpitt martinpitt requested a review from jelly December 6, 2024 10:46
# 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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Never seen ExecStart=-, is that allowed to fail syntax?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not use podman image prune? Should be safer and only remove unused images.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, - prefix means "allowed to fail", see manpage.

podman image prune

TIL! This is nicer indeed, done.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(--force is terribly named -- should be -y or so..)

jelly
jelly previously approved these changes Dec 6, 2024
Copy link
Member

@jelly jelly left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small typo can fixed or we just merge

Type=oneshot
# remove leftover containers
ExecStart=/bin/sh -ec 'podman ps -q --filter status=exited | xargs -r podman rm'
# remote old task images
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typoe remote -> remove

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Fixed.

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.
Our webhook has ran in CentOS CI for a long time. tasks/README.md also
says so, but the AWS documentation contradicted that. Update it
accordingly.
@martinpitt martinpitt merged commit 72c8130 into main Dec 6, 2024
3 checks passed
@martinpitt martinpitt deleted the janitor branch December 6, 2024 13:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants