Repository navigation
Conversation
stiwa-petm
left a comment
There was a problem hiding this comment.
I don't have merge rights. But noticed a few small things. Code and tests look solid to me. Didn't run it locally yet though. Thank you for the PR, hopefully a maintainer reviews this soon as well.
| name: testcontainers-ryuk-fixture | ||
| services: | ||
| service: | ||
| image: alpine:3.20 |
There was a problem hiding this comment.
Most other images for tests in this repo use alpine:latest
| ): | ||
| monkeypatch.setattr(testcontainers_config, "ryuk_disabled", False) | ||
| assert Reaper._instance is None | ||
| with DockerContainer("alpine:3.20", command="sleep 300") as ordinary: |
There was a problem hiding this comment.
Most other images for tests in this repo use alpine:latest
|
|
||
| def __post_init__(self) -> None: | ||
| if self.ryuk: | ||
| self._project_name = f"testcontainers-{uuid4().hex}" |
There was a problem hiding this comment.
Maybe log generated project name on debug?
619d814 to
140d762
Compare
stiwa-petm
left a comment
There was a problem hiding this comment.
Thank you for the changes. I don't have rights to merge or start the other workflows required for approval. For me the code changes seem clean. If anybody else can start the workflows or review please do so, thanks.
What does this PR do?
Adds opt-in Ryuk cleanup to
DockerCompose:Each opted-in object receives a unique Compose project name and registers its
com.docker.compose.projectlabel with the process’s shared Reaper before starting services. If the Python process is abruptly terminated, Ryuk can remove the project’s containers, networks, and volumes.Existing behavior remains unchanged when
ryukis omitted.Why is it needed?
DockerComposestarts services through the Compose CLI, bypassing the Reaper registration used byDockerContainer. Context-manager cleanup handles normal exit, but an abruptly terminated test process can leave Compose resources behind.This connects Compose environments to the existing cleanup mechanism. Registering the project before
compose upalso covers resources left behind when startup fails partway through. A unique project name separates cleanup ownership between independent Compose objects using the same files.Addresses #1049.
Shape
Extends the existing
DockerComposedataclass and shared command builder. The generated project name is reused across all commands and restarts of the same object. Compose reuses an existing Reaper when available.Adds acknowledged label-filter registration to Reaper, including serialized socket exchanges, fragmented-response handling, and a bounded timeout. Initial session registration uses the same mechanism so its acknowledgement cannot be mistaken for a subsequent Compose registration. Registration failures prevent startup; a failed additional registration does not deliberately close the shared connection and trigger cleanup of other environments.
Added documentation and 22 test cases covering registration failures, project isolation, Reaper reuse, retained volumes, cleanup diagnostics, and actual subprocess termination. The Linux verification run passed all 22 new cases plus three existing Ryuk tests. The five live integration cases skip native macOS because of Docker Desktop Ryuk instability.
A few lifecycle details for reviewers:
COMPOSE_PROJECT_NAMEand top-level Composename; explicit resource names and host ports still require care.keep_volumes=Truepreserves resources during normal context exit, but they remain eligible for Ryuk cleanup after disconnection.