Skip to content

bk: add post-checkout hook to cleanup leftover containers#621

Merged
ivotron merged 1 commit intomainfrom
pre-exit-cleanup-hook
Apr 3, 2025
Merged

bk: add post-checkout hook to cleanup leftover containers#621
ivotron merged 1 commit intomainfrom
pre-exit-cleanup-hook

Conversation

@ivotron
Copy link
Member

@ivotron ivotron commented Apr 2, 2025

Add a post-checkout hook to properly cleanup leftover containers from previous jobs.

fixes https://redpandadata.atlassian.net/browse/DEVPROD-2817

@ivotron ivotron requested a review from jan-g April 2, 2025 18:16
@ivotron ivotron enabled auto-merge (squash) April 2, 2025 18:18
@ivotron ivotron disabled auto-merge April 2, 2025 18:19
@ivotron ivotron force-pushed the pre-exit-cleanup-hook branch from ff8225e to ccfdbf0 Compare April 2, 2025 18:20
@ivotron
Copy link
Member Author

ivotron commented Apr 2, 2025

this can be seen in action on this cancelled step https://buildkite.com/redpanda/redpanda-operator/builds/5389#0195f7b7-dbcc-4d1e-9fcf-d0c9417adf50. or on any other cancelled step of that same job https://buildkite.com/redpanda/redpanda-operator/builds/5389

@ivotron ivotron enabled auto-merge (squash) April 2, 2025 18:22
@RafalKorepta
Copy link
Contributor

I see in CI job on your PR that kind cluster already exist. In other terms pre-start hook should prepare environment and delete kind and k3d clusters along with containers.

Pre-exit hook could be good if the queue is shared among other project.

@ivotron ivotron force-pushed the pre-exit-cleanup-hook branch from ccfdbf0 to 8970872 Compare April 3, 2025 15:21
@ivotron ivotron changed the title bk: add pre-exit hook to cleanup containers bk: add post-checkout hook to cleanup leftover containers Apr 3, 2025
@ivotron
Copy link
Member Author

ivotron commented Apr 3, 2025

I see in CI job on your PR that kind cluster already exist. In other terms pre-start hook should prepare environment and delete kind and k3d clusters along with containers.

Pre-exit hook could be good if the queue is shared among other project.

that's because the previous job didn't run this pre-exit hook. But we can have the same effect if we move it as a post-checkout hook. I've done that and updated the PR. can you please re-review?

@ivotron ivotron requested a review from RafalKorepta April 3, 2025 15:22

echo "Cleaning up unused docker containers"
docker ps -a
for id in $(docker ps -qa); do
Copy link
Contributor

Choose a reason for hiding this comment

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

Why -a here? We're only interested in running containers, right?

  -a, --all             Show all containers (default shows just running)

FWIW, I find it useful to use the long version of arguments in scripts.

Copy link
Member Author

Choose a reason for hiding this comment

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

the goal is to also freeup space. if not important then i can just remove it

docker ps -a
for id in $(docker ps -qa); do
echo "Killing $id"
docker stop -t 1 "$id" || true
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe docker kill instead of stop? No need to waste time waiting on a process to listen to SIGTERM in this context.

|| true isn't need because of set +e, right?

docker stop -t 1 "$id" || true
done

docker container prune --force
Copy link
Contributor

Choose a reason for hiding this comment

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

docker system prune --force --volumes --all will cover the first two lines here. I don't know if it'll clear out networks through 🤔

Copy link
Member Author

Choose a reason for hiding this comment

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

based on docs, it seems like it does

@ivotron ivotron force-pushed the pre-exit-cleanup-hook branch 2 times, most recently from b63d620 to 5edf8e8 Compare April 3, 2025 16:24
@ivotron ivotron requested a review from chrisseto April 3, 2025 16:26
Signed-off-by: Ivo Jimenez <ivo.jimenez@gmail.com>
@ivotron ivotron force-pushed the pre-exit-cleanup-hook branch from 5edf8e8 to 6b42095 Compare April 3, 2025 16:27
@ivotron ivotron merged commit a44a8f0 into main Apr 3, 2025
12 checks passed
@chrisseto chrisseto deleted the pre-exit-cleanup-hook branch April 3, 2025 18:07
chrisseto pushed a commit that referenced this pull request Apr 3, 2025
Signed-off-by: Ivo Jimenez <ivo@redpanda.com>
(cherry picked from commit a44a8f0)
chrisseto pushed a commit that referenced this pull request Apr 3, 2025
Signed-off-by: Ivo Jimenez <ivo@redpanda.com>
(cherry picked from commit a44a8f0)
chrisseto pushed a commit that referenced this pull request Apr 3, 2025
Signed-off-by: Ivo Jimenez <ivo@redpanda.com>
(cherry picked from commit a44a8f0)
@chrisseto
Copy link
Contributor

💚 All backports created successfully

Status Branch Result
release/v25.1.x
release/v2.4.x
release/v2.3.x

Note: Successful backport PRs will be merged automatically after passing CI.

Questions ?

Please refer to the Backport tool documentation

@chrisseto
Copy link
Contributor

Thanks for the fix(es) @ivotron, I opened up the backports for you!

@ivotron
Copy link
Member Author

ivotron commented Apr 3, 2025

ty! on a second thought, docker system prune is a bit too aggressive as it removes all images, which affects caching across jobs. do you cache separately with nix? i can open a follow up that skips removing untagged/dangling images

chrisseto pushed a commit that referenced this pull request Apr 3, 2025
Signed-off-by: Ivo Jimenez <ivo@redpanda.com>
(cherry picked from commit a44a8f0)
chrisseto pushed a commit that referenced this pull request Apr 3, 2025
Signed-off-by: Ivo Jimenez <ivo@redpanda.com>
(cherry picked from commit a44a8f0)
chrisseto pushed a commit that referenced this pull request Apr 3, 2025
Signed-off-by: Ivo Jimenez <ivo@redpanda.com>
(cherry picked from commit a44a8f0)
@RafalKorepta
Copy link
Contributor

@ivotron I'm not sure if you are about to follow up with changing docker system prune?

@ivotron
Copy link
Member Author

ivotron commented Apr 8, 2025

sorry, @chrisseto and i chatted and it seems like removing images is not harmful. are you seeing a negative effect? if yes then i can open a PR

@ivotron
Copy link
Member Author

ivotron commented Apr 8, 2025

if it helps: #684

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants