Skip to content

feat: reusable containers #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 41 commits into
base: main
Choose a base branch
from
Open

Conversation

matthiasschaub
Copy link
Member

No description provided.

@matthiasschaub matthiasschaub changed the title feat: reuse containers feat: reusable containers Jul 3, 2024
@matthiasschaub matthiasschaub force-pushed the reusable_containers branch 2 times, most recently from 44660f1 to 74c8df1 Compare July 3, 2024 12:04
matthiasschaub and others added 18 commits July 8, 2024 09:40
do not create Ryuk cleanup instance if reuse enabled and container has
been start with `with_reuse`
🤖 I have created a release *beep* *boop*
---


##
[4.9.1](testcontainers/testcontainers-python@testcontainers-v4.9.0...testcontainers-v4.9.1)
(2025-01-21)


### Bug Fixes

* milvus healthcheck: use correct requests errors
([testcontainers#759](testcontainers#759))
([78b137c](testcontainers@78b137c))
* **mysql:** add dialect parameter instead of hardcoded mysql dialect
([testcontainers#739](testcontainers#739))
([8d77bd3](testcontainers@8d77bd3))
* **tests:** replace dind-test direct docker usage with sdk
([testcontainers#750](testcontainers#750))
([ace2a7d](testcontainers@ace2a7d))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
…estcontainers#769)

When invoking `.start()` multiple times on the same `DockerContainer`
instance, the call fails with `ValueError: The org.testcontainers
namespace is reserved for internal use` error.

Example code:

```
from testcontainers.core.container import DockerContainer
container = DockerContainer("alpine:latest").with_kwargs(labels={})
container.start()
container.stop()
container.start()
```

The fix is to update labels for the container in a copy of the
user-provided dictionary, so that:
* the code doesn't mutate user structures
* avoid side effects, allowing for multiple .start() invocations
Fixed a typo which I ran into while working a bugfix.
testcontainers#766)

@alexanderankin We already discussed last year that we only want to
support the latest Keycloak version.

I added the `latest` tag to test parameterization so we get a better
feedback for future Keycloak updates.

Fixes testcontainers#764

---------

Co-authored-by: David Ankin <daveankin@gmail.com>
…ers#773)

This closes testcontainers#772

---------

Co-authored-by: David Ankin <daveankin@gmail.com>
Make sure the test covers the intended behaviour. Previously it was
executing the create_labels function without actually verifying there
are no side effects.
use convention for getting ip and port instead of hardcoding DIND mode
🤖 I have created a release *beep* *boop*
---


##
[4.9.2](testcontainers/testcontainers-python@testcontainers-v4.9.1...testcontainers-v4.9.2)
(2025-02-26)


### Bug Fixes

* Change env var disabling OpenSearch security plugin
([testcontainers#773](testcontainers#773))
([2620d7f](testcontainers@2620d7f))
* **core:** create_label test
([testcontainers#771](testcontainers#771))
([7517297](testcontainers@7517297))
* **core:** multiple container start invocations with custom labels
([testcontainers#769](testcontainers#769))
([3e783a8](testcontainers@3e783a8))
* **keycloak:** Fixed Keycloak testcontainer for latest version v26.1.0
([testcontainers#766](testcontainers#766))
([b1642e9](testcontainers@b1642e9))
* **scylla:** scylla get cluster method
([testcontainers#778](testcontainers#778))
([46913c1](testcontainers@46913c1))


### Documentation

* Fixed typo in CONTRIBUTING.md
([testcontainers#767](testcontainers#767))
([f0bb0f5](testcontainers@f0bb0f5))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
This will address the Security issue reported on testcontainers#786
As recommended, `tj-actions/changed-files` was replace replaced with
[path-filter](https://github.com/dorny/paths-filter)

---------

Co-authored-by: David Ankin <daveankin@gmail.com>
Add new SocatContainer at testcontainers module that
can be used along with other modules as a helper.

---------

Co-authored-by: David Ankin <daveankin@gmail.com>
alexanderankin and others added 16 commits April 2, 2025 12:02
🤖 I have created a release *beep* *boop*
---


##
[4.10.0](testcontainers/testcontainers-python@testcontainers-v4.9.2...testcontainers-v4.10.0)
(2025-04-02)


### Features

* Add SocatContainer
([testcontainers#795](testcontainers#795))
([2f9139c](testcontainers@2f9139c))


### Bug Fixes

* **ollama:** make device request a list
([testcontainers#799](testcontainers#799))
([9497a45](testcontainers@9497a45))
* **security:** Update track-modules job
([testcontainers#787](testcontainers#787))
([f979525](testcontainers@f979525))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
…ontainers#789)

the `with_command` function can actually take an argument with type
`list[str]`.

Co-authored-by: amirhosein <amirhosein@cyberdesign.se>
Fix: testcontainers#706,
testcontainers#614

Now when using kwargs in the Image API, the params are passed correctly
into the build

```python
with DockerImage(path=dir, tag="test", buildargs={"MY_ARG": "some_arg"}) as image:
```

Added relevant test + updated docstring to better reflect the usage
…tainers#785)

closes testcontainers#745 

if the docker compose command is provided, use that instead of default
one.

Co-authored-by: amirhosein <amirhosein@cyberdesign.se>
…ners#803)

Trying to improve docs reliability for "latest" version
…containers#690)

Fix: testcontainers#674

Changes:
1. Proper type hinting for ports bindings, support strings like
`8080/tcp` or `8125/udp`
2. Backward compatible with `int`
3. More test coverage
4. Improve documentations regarding the usage of `with_bind_ports` and
`with_exposed_ports`

Any comments will be appreciated

---------

Co-authored-by: David Ankin <daveankin@gmail.com>
Supports:
testcontainers#305
Related : testcontainers#691  testcontainers#692 

### Overview
1. Updated Mypy 
2. Add a new dev script to allow easy reporting on Mypy errors (Using it
in the makefile)
4. fix various type errors (all over core)

#### Old
```
                    Error Summary                     
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━┓
┃ File Path                                 ┃ Errors ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━┩
│ core/testcontainers/core/version.py       │ 12     │
│ core/testcontainers/core/docker_client.py │ 14     │
│ core/testcontainers/core/network.py       │ 4      │
│ core/testcontainers/core/image.py         │ 17     │
│ core/testcontainers/core/waiting_utils.py │ 8      │
│ core/testcontainers/core/container.py     │ 20     │
│ core/tests/test_new_docker_api.py         │ 4      │
│ core/tests/test_docker_in_docker.py       │ 2      │
│ core/testcontainers/compose/compose.py    │ 22     │
│ core/testcontainers/compose/__init__.py   │ 2      │
│ core/testcontainers/core/generic.py       │ 1      │
│ core/tests/test_version.py                │ 2      │
│ core/tests/test_ryuk.py                   │ 2      │
│ core/tests/test_registry.py               │ 1      │
│ core/tests/test_network.py                │ 1      │
│ core/tests/test_labels.py                 │ 1      │
│ core/tests/test_image.py                  │ 3      │
│ core/tests/test_docker_client.py          │ 1      │
│ core/tests/conftest.py                    │ 1      │
│ core/tests/test_compose.py                │ 7      │
└───────────────────────────────────────────┴────────┘
Found 125 errors in 20 files.
```
#### New
```
                    Error Summary                     
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━┓
┃ File Path                                 ┃ Errors ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━┩
│ core/testcontainers/core/version.py       │ 12     │
│ core/testcontainers/core/docker_client.py │ 14     │
│ core/testcontainers/core/image.py         │ 17     │
│ core/testcontainers/core/waiting_utils.py │ 8      │
│ core/testcontainers/core/container.py     │ 20     │
│ core/tests/test_new_docker_api.py         │ 4      │
│ core/tests/test_docker_in_docker.py       │ 2      │
│ core/testcontainers/compose/compose.py    │ 22     │
│ core/testcontainers/compose/__init__.py   │ 2      │
│ core/tests/test_version.py                │ 2      │
│ core/tests/test_ryuk.py                   │ 2      │
│ core/tests/test_registry.py               │ 1      │
│ core/tests/test_image.py                  │ 3      │
│ core/tests/test_compose.py                │ 7      │
└───────────────────────────────────────────┴────────┘
Found 116 errors in 14 files.
```

---------

Co-authored-by: David Ankin <daveankin@gmail.com>
Supports:
testcontainers#305
Related :
testcontainers#691
testcontainers#692 testcontainers#700

```
poetry run mypy --config-file pyproject.toml core/testcontainers/core/version.py 
Success: no issues found in 1 source file
```

Old
```
                    Error Summary                     
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━┓
┃ File Path                                 ┃ Errors ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━┩
│ core/testcontainers/core/version.py       │ 12     │
│ core/testcontainers/core/docker_client.py │ 14     │
│ core/testcontainers/core/image.py         │ 17     │
│ core/testcontainers/core/waiting_utils.py │ 8      │
│ core/testcontainers/core/container.py     │ 20     │
│ core/tests/test_new_docker_api.py         │ 4      │
│ core/tests/test_docker_in_docker.py       │ 2      │
│ core/testcontainers/compose/compose.py    │ 22     │
│ core/testcontainers/compose/__init__.py   │ 2      │
│ core/tests/test_version.py                │ 2      │
│ core/tests/test_ryuk.py                   │ 2      │
│ core/tests/test_registry.py               │ 1      │
│ core/tests/test_image.py                  │ 3      │
│ core/tests/test_compose.py                │ 7      │
└───────────────────────────────────────────┴────────┘
Found 116 errors in 14 files.
```
New
```
                    Error Summary                     
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━┓
┃ File Path                                 ┃ Errors ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━┩
│ core/testcontainers/core/docker_client.py │ 14     │
│ core/testcontainers/core/image.py         │ 17     │
│ core/testcontainers/core/waiting_utils.py │ 8      │
│ core/testcontainers/core/container.py     │ 20     │
│ core/tests/test_new_docker_api.py         │ 4      │
│ core/tests/test_docker_in_docker.py       │ 2      │
│ core/testcontainers/compose/compose.py    │ 22     │
│ core/testcontainers/compose/__init__.py   │ 2      │
│ core/tests/test_ryuk.py                   │ 2      │
│ core/tests/test_registry.py               │ 1      │
│ core/tests/test_image.py                  │ 3      │
│ core/tests/test_compose.py                │ 7      │
└───────────────────────────────────────────┴────────┘
Found 102 errors in 12 files.
```
Supports:
testcontainers#305
Related :
testcontainers#691
testcontainers#692 testcontainers#700

Based on testcontainers#504, kudos @alexanderankin 

```
poetry run mypy --config-file pyproject.toml core/testcontainers/core/docker_client.py 
Success: no issues found in 1 source file
```

Old
```
                    Error Summary                     
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━┓
┃ File Path                                 ┃ Errors ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━┩
│ core/testcontainers/core/version.py       │ 12     │
│ core/testcontainers/core/docker_client.py │ 14     │
│ core/testcontainers/core/image.py         │ 17     │
│ core/testcontainers/core/waiting_utils.py │ 8      │
│ core/testcontainers/core/container.py     │ 20     │
│ core/tests/test_new_docker_api.py         │ 4      │
│ core/tests/test_docker_in_docker.py       │ 2      │
│ core/testcontainers/compose/compose.py    │ 22     │
│ core/testcontainers/compose/__init__.py   │ 2      │
│ core/tests/test_version.py                │ 2      │
│ core/tests/test_ryuk.py                   │ 2      │
│ core/tests/test_registry.py               │ 1      │
│ core/tests/test_image.py                  │ 3      │
│ core/tests/test_compose.py                │ 7      │
└───────────────────────────────────────────┴────────┘
Found 116 errors in 14 files.
```
New
```
                    Error Summary                     
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━┓
┃ File Path                                 ┃ Errors ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━┩
│ core/testcontainers/core/version.py       │ 12     │
│ core/testcontainers/core/network.py       │ 3      │
│ core/testcontainers/core/image.py         │ 17     │
│ core/testcontainers/core/waiting_utils.py │ 8      │
│ core/testcontainers/core/container.py     │ 19     │
│ core/tests/test_new_docker_api.py         │ 4      │
│ core/tests/test_docker_in_docker.py       │ 2      │
│ core/testcontainers/compose/compose.py    │ 22     │
│ core/testcontainers/compose/__init__.py   │ 2      │
│ core/tests/test_version.py                │ 2      │
│ core/tests/test_ryuk.py                   │ 2      │
│ core/tests/test_registry.py               │ 1      │
│ core/tests/test_image.py                  │ 3      │
│ core/tests/test_compose.py                │ 7      │
└───────────────────────────────────────────┴────────┘
Found 104 errors in 14 files.
```
TL;DR this is a cleanups and alignments

- Update pre-commit ruff version to latest + adaptations needed

- Fix some issues with the pyproject.toml file schemas.
1. `tool.poetry.source` requires URL
[see](python-poetry/poetry#3855)
2. `tool.ruff.lint` changed flake8-type-checking code
[checkout](https://astral.sh/blog/ruff-v0.8.0)
3. `tool.mypy` doest not support `fast_module_lookup` in the TOML (Need
to investigate more if we want to add it back)

---------

Co-authored-by: David Ankin <daveankin@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants