testcontainers / testcontainers/testcontainers-python

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

未关闭
#1,049 3 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

🚀 enhancement
主要语言
Python
星标
2.3k
派生
386
平均合并
4 小时 40 分钟
30 天内合并 PR
1

描述

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.

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

从 src/testcontainers/compose/compose.py 开始,重点查看所引用的 start() 方法附近的 ComposeContainer 类,并将其与链接的 Java ComposeContainer 和 ComposeDelegate 实现进行比较。在决定应如何注册 Compose 项目标签之前,先跟踪现有的 Python Ryuk 注册 API。完成的标准是:由 ComposeContainer 启动的容器在崩溃或强制停止后能够被安全清理,并且有针对该行为的相关覆盖。

由索引模型根据 Issue 内容生成。

评估

技术栈
docker, docker-compose, python
领域
devops, testing-qa
Issue 类型
功能
难度
4/5
预计耗时
3-5 天
活跃度
活跃
描述清晰度
描述清楚
新手友好度
68/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。