testcontainers / testcontainers/testcontainers-python
Provide generic DockerContainer with init attributes
まだ誰も着手していません。
- 主要言語
- Python
- スター
- 2.3k
- フォーク
- 386
- 平均マージ
- 4時間 40分
- マージ済み PR(30日)
- 1
説明
First I want to thank you for this very nice and convenient library.
Background
I am using the library for smoke tests for microservices. In these tests I spin up a container and make sure I can e.g., fetch an endpoint and see that the container is built and starts correctly.
The library provides all convenient methods, except for a way to set e.g., ports and env variables in the context manager. To solve this I have subclassed testcontainers.core.container.DockerContainer into a class as below:
from typing import Any
import testcontainers.core.container
class ContainerContext(testcontainers.core.container.DockerContainer):
def __init__(
self, image: str, ports: list[int], env_vars: dict[str, str], **kwargs: Any
) -> None:
super().__init__(image, **kwargs)
self.with_exposed_ports(*ports)
for env, value in env_vars.items():
self.with_env(env, value)
and use it as
import requests
def test_smoke():
with container_context(
"my_service_image",
ports=[8000],
env_vars={"SOME_ENV_SETTINGS": "some_value", "SOME_ENV_SETTINGS2": "other_value"},
) as con:
r = requests.get(
f"http://{con.get_container_host_ip()}:{con.get_exposed_port(8000)}"
)
assert r
Proposal
- Include a generic container class where all
name,ports,env,volumes, … can be set as init variables.
I saw #114 that removed the previous GenericContainer but I don't see a motivation why it was done and why it could not be extended.
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
testcontainers.core.container.DockerContainer と、#114 で議論された以前の GenericContainer の削除を確認してください。要求されている初期化属性 —name、ports、env、volumes— を既存のコンテナ API と比較し、汎用コンテナがサブクラス化せずに初期化時にこれらの値を設定できれば、提案は完了とみなしてください。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- docker, python
- 領域
- devops, testing
- issue の種類
- 機能追加
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 35/100