testcontainers / testcontainers/testcontainers-dotnet
[Enhancement]: clean up old reuse containers
Nobody has claimed this yet.
- Dominant language
- C#
- Stars
- 4.4k
- Forks
- 357
- Avg merge
- 14h 42m
- Merged PRs (30d)
- 16
Description
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.
_container = new MsSqlBuilder()
...
.WithCleanUp(true)
.WithReuse(true)
.WithLabel("reuse-id", hash_of_migrations_and_seeding)
.Build();
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 different reuse-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
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reading the reuse feature from issue #1051 and tracing how WithCleanUp(true), WithReuse(true), and the reuse-id label affect container creation, disposal, and stopped containers. Define done as automatically removing older containers using the same image but a different reuse-id, with coverage for both running and stopped cases.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp, docker
- Domain
- devops, testing-qa
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100