-
-
Notifications
You must be signed in to change notification settings - Fork 277
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
[Enhancement]: clean up old reuse containers #1166
Comments
@david-szabo97 Since you implemented the |
We cannot detect that, as we generate the hash from the actual builder configuration. This is somewhat akin to a chicken-and-egg problem, and showing how effectively and almost invisibly Testcontainers handles the cleanup of test resources 🔥. It is crucial to understand the concept of Ryuk and why it is necessary (as simply running cleanup from the test process does not work reliable). During my time at AJ, I proposed the idea of integrating external events into Ryuk. If Ryuk detects an event and exits, it would then remove all related resources. Testcontainers for .NET theoretically supports individual Ryuk instances (running independently from each other). Resources can be grouped, and the assigned Ryuk instance will manage them accordingly. AJ introduced Testcontainers Desktop (maybe that supports your use case), which also supports reuse. However, I have not had the chance to try it yet; AFAIK it is only available for macOS. |
Pity... Theoretically, it should be possible to implement it somehow (not sure if Ryuk supports this or not, so far I never had any reason to look into it). |
I suspect that you'd need to keep track of the hashes of the containers being requested in a constantly running container akin to or as an extension of ryuk, and if you don't see a request for, say, a day, you can probably expire the old resources. |
Problem
I'm not entirely sure, if this is an indented use-case or not.
In one of my projects, we have a huge number of database migrations and also a lot of seeding data.
So my goal was, to use the new reuse-feature ( #1051 ), so that I once start the database in a testcontainer, apply all migrations and seed some data, and then reuse that container.
Whenever a new migration is added, or some seeding data changes, the hash changes, and a new container is created and used.
When it stays the same, the existing container is reused.
That actually works, however the old containers are never cleaned up.
New containers are created, but the old containers (with different
reuse-id
labels) either keep running (is.Dispose()
call is disabled), or keep existing in a stopped state (if.Dispose()
is used).In both variants, more and more resources of the system are used, until you manually clean it up.
Solution
I would prefer it, that if the
reuse-id
changes, all old containers with the same image and differentreuse-id
are deleted automatically.Benefit
Less resources used on your system.
Alternatives
We keep it as is.
Would you like to help contributing this enhancement?
Yes
The text was updated successfully, but these errors were encountered: