testcontainers / testcontainers/testcontainers-python

Feature: Ryuk support in ComposeContainer class (like in Java)

Open
#1,049 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

🚀 enhancement
Dominant language
Python
Stars
2.3k
Forks
386
Avg merge
4h 40m
Merged PRs (30d)
1

Description

What are you trying to do?

When using testcontainers for Python in a CI/CD environment containers started using the ComposeContainer class are not stopped in crash or force-stop scenarios. The same class in Java cleaned up the started Containers via Ryuk.

It would be nice if the Python class ComposeContainer provides the same functionality of cleaning up the containers it started in a safe manner. (for example with Ryuk)

Safe cleanup of containers seems to be a core feature of the other *Container classes and is missing for compose files using the ComposeContainer class.

Here is a brief summary of how it is implemented in Java and potential changes:
ComposeContainer class in Java:

https://github.com/testcontainers/testcontainers-java/blob/905a445ad8b701e4c531aa652e42179072a88d01/core/src/main/java/org/testcontainers/containers/ComposeContainer.java#L33

In the "start()" method "registerContainersForShutdown" is called. See:

https://github.com/testcontainers/testcontainers-java/blob/905a445ad8b701e4c531aa652e42179072a88d01/core/src/main/java/org/testcontainers/containers/ComposeContainer.java#L160

In "registerContainersForShutdown"

https://github.com/testcontainers/testcontainers-java/blob/905a445ad8b701e4c531aa652e42179072a88d01/core/src/main/java/org/testcontainers/containers/ComposeDelegate.java#L244-L248

the line ".registerLabelsFilterForCleanup(Collections.singletonMap("com.docker.compose.project", project));" effectivly adds a label filter to Ryuk using the official Docker property com.docker.compose.project with a random project ID. (see constructor of ComposeDelegate for "project" property)

Python doesn't have this functionality, see https://github.com/testcontainers/testcontainers-python/blob/a3476488ac1f7526a9c22d65251c8639d7089326/src/testcontainers/compose/compose.py#L84 for the analog of the ComposeContainer class in Python and https://github.com/testcontainers/testcontainers-python/blob/a3476488ac1f7526a9c22d65251c8639d7089326/src/testcontainers/compose/compose.py#L318 for the "start()" method that has no code to interact with Ryuk.

Why should it be done this way?

Please provide the same or similar functionality to allow safe usage of ComposeContainer class like in Java.
Thank you.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in src/testcontainers/compose/compose.py, especially the ComposeContainer class around the referenced start() method, and compare it with the linked Java ComposeContainer and ComposeDelegate implementations. Trace the existing Python Ryuk registration APIs before deciding how Compose project labels should be registered. Done means containers started by ComposeContainer are safely cleaned up after crashes or force stops, with relevant coverage for this behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
docker, docker-compose, python
Domain
devops, testing-qa
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Active
Clarity
Clearly specified
Newbie friendliness
68/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.