Skip to content

Commit 7c1e8e7

Browse files
Merge remote-tracking branch 'origin/main' into reusable_containers
2 parents ea6fec7 + ace2a7d commit 7c1e8e7

File tree

75 files changed

+2212
-316
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

75 files changed

+2212
-316
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
{
2-
".": "4.7.1"
2+
".": "4.9.0"
33
}

.github/CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ You need to have the following tools available to you:
3939

4040
## Adding new containers
4141

42-
We have an [issue template](.github/ISSUE_TEMPLATE/new-container.md) for adding new containers, please refer to that for more information.
42+
We have an [issue template](./ISSUE_TEMPLATE/new-container.md) for adding new containers, please refer to that for more information.
4343
Once you've talked to the maintainers (we do our best to reply!) then you can proceed with contributing the new container.
4444

4545
> [!WARNING]

.github/workflows/ci-core.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ jobs:
3333
uses: actions/upload-artifact@v4
3434
with:
3535
name: "coverage-artifact-${{ matrix.python-version}}"
36+
include-hidden-files: true
3637
path: ".coverage.*"
3738
retention-days: 1
3839
- name: Run doctests

CHANGELOG.md

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,86 @@
11
# Changelog
22

3+
## [4.9.0](https://github.com/testcontainers/testcontainers-python/compare/testcontainers-v4.8.2...testcontainers-v4.9.0) (2024-11-26)
4+
5+
6+
### Features
7+
8+
* **compose:** support for setting profiles ([#738](https://github.com/testcontainers/testcontainers-python/issues/738)) ([3e00e71](https://github.com/testcontainers/testcontainers-python/commit/3e00e71da4d2b5e7fd30315468d4e54c86ba6150))
9+
* **core:** Support working with env files ([#737](https://github.com/testcontainers/testcontainers-python/issues/737)) ([932ee30](https://github.com/testcontainers/testcontainers-python/commit/932ee307955e3591a63f194aee8e2f6d8e2f6bf9))
10+
11+
12+
### Bug Fixes
13+
14+
* allow running all tests ([#721](https://github.com/testcontainers/testcontainers-python/issues/721)) ([f958cf9](https://github.com/testcontainers/testcontainers-python/commit/f958cf9fe62a5f3ee2dc255713ec8b16de6a767d))
15+
* **core:** Avoid hanging upon bad docker host connection ([#742](https://github.com/testcontainers/testcontainers-python/issues/742)) ([4ced198](https://github.com/testcontainers/testcontainers-python/commit/4ced1983162914fe511a6e714f136b670e1dbdfb))
16+
* **core:** running testcontainer inside container ([#714](https://github.com/testcontainers/testcontainers-python/issues/714)) ([85a6666](https://github.com/testcontainers/testcontainers-python/commit/85a66667c23d76e87aecc6761bbb01429adb3dee))
17+
* **generic:** Also catch URLError waiting for ServerContainer ([#743](https://github.com/testcontainers/testcontainers-python/issues/743)) ([24e354f](https://github.com/testcontainers/testcontainers-python/commit/24e354f3bfa5912eaf7877da9442a885d7872f1a))
18+
* update wait_for_logs to not throw on 'created', and an optimization ([#719](https://github.com/testcontainers/testcontainers-python/issues/719)) ([271ca9a](https://github.com/testcontainers/testcontainers-python/commit/271ca9a0fef2e5f2b216457bfee44318e93990bf))
19+
* Vault health check ([#734](https://github.com/testcontainers/testcontainers-python/issues/734)) ([79434d6](https://github.com/testcontainers/testcontainers-python/commit/79434d6744b2918493884cf8fbf27aeadf78ecfd))
20+
21+
22+
### Documentation
23+
24+
* Documentation fix for ServerContainer ([#671](https://github.com/testcontainers/testcontainers-python/issues/671)) ([0303d47](https://github.com/testcontainers/testcontainers-python/commit/0303d47d7173e1c4ec1a4f565efee9b2fe694928))
25+
26+
## [4.8.2](https://github.com/testcontainers/testcontainers-python/compare/testcontainers-v4.8.1...testcontainers-v4.8.2) (2024-09-27)
27+
28+
29+
### Bug Fixes
30+
31+
* **core:** Reorganize core tests and improve ([#693](https://github.com/testcontainers/testcontainers-python/issues/693)) ([f1665f3](https://github.com/testcontainers/testcontainers-python/commit/f1665f3aa66eff443923d897ec553e09e47f6a78))
32+
* **core:** Typing in auth ([#691](https://github.com/testcontainers/testcontainers-python/issues/691)) ([66726b6](https://github.com/testcontainers/testcontainers-python/commit/66726b656ab8fd18a69771ff2ee2a3fd8ca959b0))
33+
* **core:** Typing in config + utils ([#692](https://github.com/testcontainers/testcontainers-python/issues/692)) ([794a22e](https://github.com/testcontainers/testcontainers-python/commit/794a22e22362227ccfc0b2acd18130196e25775d))
34+
* **keycloak:** Add support for Keycloak version >=25 ([#694](https://github.com/testcontainers/testcontainers-python/issues/694)) ([62bd0de](https://github.com/testcontainers/testcontainers-python/commit/62bd0debffdb762714de853a069e3b63414fa789))
35+
* mysql typo ([#705](https://github.com/testcontainers/testcontainers-python/issues/705)) ([85d6078](https://github.com/testcontainers/testcontainers-python/commit/85d6078f9bcc99050c0173e459208402aa4f5026)), closes [#689](https://github.com/testcontainers/testcontainers-python/issues/689)
36+
* **opensearch:** add support for admin_password in >= 2.12 ([#697](https://github.com/testcontainers/testcontainers-python/issues/697)) ([935693e](https://github.com/testcontainers/testcontainers-python/commit/935693e01686fea9bf3201cd8c70b3e617bda2ee))
37+
* postgres use psql instead of logs ([#704](https://github.com/testcontainers/testcontainers-python/issues/704)) ([4365754](https://github.com/testcontainers/testcontainers-python/commit/436575410a2906a695b96af66ff55c9ccb8e09a7))
38+
* **tests:** Missing artifacts (include-hidden-files) ([#699](https://github.com/testcontainers/testcontainers-python/issues/699)) ([8f1165d](https://github.com/testcontainers/testcontainers-python/commit/8f1165dd79ee0dcf16f37f2d186cbc3d47bc11bc))
39+
40+
## [4.8.1](https://github.com/testcontainers/testcontainers-python/compare/testcontainers-v4.8.0...testcontainers-v4.8.1) (2024-08-18)
41+
42+
43+
### Bug Fixes
44+
45+
* **generic:** Update the FastAPI install on genric module doctest samples ([#686](https://github.com/testcontainers/testcontainers-python/issues/686)) ([5216b02](https://github.com/testcontainers/testcontainers-python/commit/5216b0241a27afe3419f5c4a6d500dc27154ddd4))
46+
* **mssql:** use glob to find mssql-tools folder since it moves ([#685](https://github.com/testcontainers/testcontainers-python/issues/685)) ([4912725](https://github.com/testcontainers/testcontainers-python/commit/4912725c2a54a9edce046416fbf11e089cc03cb0)), closes [#666](https://github.com/testcontainers/testcontainers-python/issues/666)
47+
* wait_for_logs can now fail early when the container stops ([#682](https://github.com/testcontainers/testcontainers-python/issues/682)) ([925329d](https://github.com/testcontainers/testcontainers-python/commit/925329d8d2df78437a491a29b707d5ac97e7b734))
48+
49+
50+
### Documentation
51+
52+
* Add a more advance usecase documentation for ServerContainer ([#688](https://github.com/testcontainers/testcontainers-python/issues/688)) ([2cf5a9f](https://github.com/testcontainers/testcontainers-python/commit/2cf5a9fbe6db3fa4254a5bb54e67412ec2d08488))
53+
54+
## [4.8.0](https://github.com/testcontainers/testcontainers-python/compare/testcontainers-v4.7.2...testcontainers-v4.8.0) (2024-08-14)
55+
56+
57+
### Features
58+
59+
* Adding support for Cassandra and Scylla ([#167](https://github.com/testcontainers/testcontainers-python/issues/167)) ([2d8bc11](https://github.com/testcontainers/testcontainers-python/commit/2d8bc11c8e151af66456ebad156afc4a87822676))
60+
* **compose:** ability to retain volumes when using context manager ([#659](https://github.com/testcontainers/testcontainers-python/issues/659)) ([e1e3d13](https://github.com/testcontainers/testcontainers-python/commit/e1e3d13b47923dd7124196e6b743799bd87b6885))
61+
* **compose:** add ability to get docker compose config ([#669](https://github.com/testcontainers/testcontainers-python/issues/669)) ([8c28a86](https://github.com/testcontainers/testcontainers-python/commit/8c28a861ce4ade9e8204783e2ef2fd99013c90ea))
62+
* **core:** add ability to do OR & AND for waitforlogs ([#661](https://github.com/testcontainers/testcontainers-python/issues/661)) ([b1453e8](https://github.com/testcontainers/testcontainers-python/commit/b1453e87e1f5443f0f8d04c9b30a278aa835ca9b))
63+
* **new:** Added AWS Lambda module ([#655](https://github.com/testcontainers/testcontainers-python/issues/655)) ([9161cb6](https://github.com/testcontainers/testcontainers-python/commit/9161cb64a0a13b54a981b2b846a4d073db8c30a2))
64+
* refactor network setup ([#678](https://github.com/testcontainers/testcontainers-python/issues/678)) ([d5de0aa](https://github.com/testcontainers/testcontainers-python/commit/d5de0aa01c7d3ba304446dd73347a1a7ec1facc7))
65+
66+
67+
### Bug Fixes
68+
69+
* Add Db2 support ([#673](https://github.com/testcontainers/testcontainers-python/issues/673)) ([1e43923](https://github.com/testcontainers/testcontainers-python/commit/1e439232e35ce0091f20993273e1f01d8c0119c4))
70+
* bring back cassandra driver bc otherwise how does it get installed for cassandra module test run? ([#680](https://github.com/testcontainers/testcontainers-python/issues/680)) ([71c3a1a](https://github.com/testcontainers/testcontainers-python/commit/71c3a1a29e1839de91f05c6bcd4c620122195a94))
71+
* **rabbitmq:** add `vhost` as parameter to RabbitMqContainer ([#656](https://github.com/testcontainers/testcontainers-python/issues/656)) ([fa2081a](https://github.com/testcontainers/testcontainers-python/commit/fa2081a7b325cdd316de28c99b029150022db203))
72+
* **selenium:** add Arg/Options to api of selenium container ([#654](https://github.com/testcontainers/testcontainers-python/issues/654)) ([e02c1b3](https://github.com/testcontainers/testcontainers-python/commit/e02c1b37a651374f47abe72bc17941849c1fd12e)), closes [#652](https://github.com/testcontainers/testcontainers-python/issues/652)
73+
74+
## [4.7.2](https://github.com/testcontainers/testcontainers-python/compare/testcontainers-v4.7.1...testcontainers-v4.7.2) (2024-07-15)
75+
76+
77+
### Bug Fixes
78+
79+
* Add container Trino ([#642](https://github.com/testcontainers/testcontainers-python/issues/642)) ([49ce5a5](https://github.com/testcontainers/testcontainers-python/commit/49ce5a5ff2ac46cf51920e16c5e39684886b699a)), closes [#641](https://github.com/testcontainers/testcontainers-python/issues/641)
80+
* **core:** Improve private registry support (tolerate not implemented fields in DOCKER_AUTH_CONFIG) ([#647](https://github.com/testcontainers/testcontainers-python/issues/647)) ([766c382](https://github.com/testcontainers/testcontainers-python/commit/766c382a3aee4eb512ee0f482d6595d3412097c3))
81+
* **kafka:** add a flag to limit to first hostname for use with networks ([#638](https://github.com/testcontainers/testcontainers-python/issues/638)) ([0ce4fec](https://github.com/testcontainers/testcontainers-python/commit/0ce4fecb2872620fd4cb96313abcba4353442cfd)), closes [#637](https://github.com/testcontainers/testcontainers-python/issues/637)
82+
* **modules:** Mailpit container base API URL helper method ([#643](https://github.com/testcontainers/testcontainers-python/issues/643)) ([df07586](https://github.com/testcontainers/testcontainers-python/commit/df07586d8844c757db62ac0f8b7914c67fd96e05))
83+
384
## [4.7.1](https://github.com/testcontainers/testcontainers-python/compare/testcontainers-v4.7.0...testcontainers-v4.7.1) (2024-07-02)
485

586

Dockerfile

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,29 @@
1-
ARG PYTHON_VERSION
2-
FROM python:${version}-slim-bookworm
1+
ARG PYTHON_VERSION=3.10
2+
FROM python:${PYTHON_VERSION}-slim-bookworm
3+
4+
ENV POETRY_NO_INTERACTION=1 \
5+
POETRY_VIRTUALENVS_IN_PROJECT=1 \
6+
POETRY_VIRTUALENVS_CREATE=1 \
7+
POETRY_CACHE_DIR=/tmp/poetry_cache
38

49
WORKDIR /workspace
510
RUN pip install --upgrade pip \
611
&& apt-get update \
7-
&& apt-get install -y \
8-
freetds-dev \
9-
&& rm -rf /var/lib/apt/lists/*
12+
&& apt-get install -y freetds-dev \
13+
&& apt-get install -y make \
14+
# no real need for keeping this image small at the moment
15+
&& :; # rm -rf /var/lib/apt/lists/*
16+
17+
# install poetry
18+
RUN bash -c 'python -m venv /opt/poetry-venv && source $_/bin/activate && pip install poetry && ln -s $(which poetry) /usr/bin'
1019

11-
# install requirements we exported from poetry
12-
COPY build/requirements.txt requirements.txt
13-
RUN pip install -r requirements.txt
20+
# install dependencies with poetry
21+
COPY pyproject.toml .
22+
COPY poetry.lock .
23+
RUN poetry install --all-extras --with dev --no-root
1424

1525
# copy project source
1626
COPY . .
27+
28+
# install project with poetry
29+
RUN poetry install --all-extras --with dev

Makefile

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,17 +31,6 @@ coverage: ## Target to combine and report coverage.
3131
lint: ## Lint all files in the project, which we also run in pre-commit
3232
poetry run pre-commit run -a
3333

34-
image: ## Make the docker image for dind tests
35-
poetry export -f requirements.txt -o build/requirements.txt
36-
docker build --build-arg PYTHON_VERSION=${PYTHON_VERSION} -t ${IMAGE} .
37-
38-
DOCKER_RUN = docker run --rm -v /var/run/docker.sock:/var/run/docker.sock
39-
40-
tests-dind: ${TESTS_DIND} ## Run the tests in docker containers to test `dind`
41-
${TESTS_DIND}: %/tests-dind: image
42-
${DOCKER_RUN} ${IMAGE} \
43-
bash -c "make $*/tests"
44-
4534
docs: ## Build the docs for the project
4635
poetry run sphinx-build -nW . docs/_build
4736

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,5 +46,5 @@ See [CONTRIBUTING.md](.github/CONTRIBUTING.md) for more details.
4646
| `TESTCONTAINERS_DOCKER_SOCKET_OVERRIDE` | `/var/run/docker.sock` | Path to Docker's socket used by ryuk |
4747
| `TESTCONTAINERS_RYUK_PRIVILEGED` | `false` | Run ryuk as a privileged container |
4848
| `TESTCONTAINERS_RYUK_DISABLED` | `false` | Disable ryuk |
49-
| `RYUK_CONTAINER_IMAGE` | `testcontainers/ryuk:0.7.0` | Custom image for ryuk |
49+
| `RYUK_CONTAINER_IMAGE` | `testcontainers/ryuk:0.8.1` | Custom image for ryuk |
5050
| `RYUK_RECONNECTION_TIMEOUT` | `10s` | Reconnection timeout for Ryuk TCP socket before Ryuk reaps all dangling containers |

conf.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,4 +160,5 @@
160160

161161
intersphinx_mapping = {
162162
"python": ("https://docs.python.org/3", None),
163+
"selenium": ("https://seleniumhq.github.io/selenium/docs/api/py/", None),
163164
}

core/testcontainers/compose/compose.py

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,21 @@
11
from dataclasses import asdict, dataclass, field, fields
22
from functools import cached_property
33
from json import loads
4+
from logging import warning
45
from os import PathLike
56
from platform import system
67
from re import split
78
from subprocess import CompletedProcess
89
from subprocess import run as subprocess_run
9-
from typing import Callable, Literal, Optional, TypeVar, Union
10+
from typing import Any, Callable, Literal, Optional, TypeVar, Union, cast
1011
from urllib.error import HTTPError, URLError
1112
from urllib.request import urlopen
1213

1314
from testcontainers.core.exceptions import ContainerIsNotRunning, NoSuchPortExposed
1415
from testcontainers.core.waiting_utils import wait_container_is_ready
1516

1617
_IPT = TypeVar("_IPT")
18+
_WARNINGS = {"DOCKER_COMPOSE_GET_CONFIG": "get_config is experimental, see testcontainers/testcontainers-python#669"}
1719

1820

1921
def _ignore_properties(cls: type[_IPT], dict_: any) -> _IPT:
@@ -165,9 +167,11 @@ class DockerCompose:
165167
pull: bool = False
166168
build: bool = False
167169
wait: bool = True
170+
keep_volumes: bool = False
168171
env_file: Optional[str] = None
169172
services: Optional[list[str]] = None
170173
docker_command_path: Optional[str] = None
174+
profiles: Optional[list[str]] = None
171175

172176
def __post_init__(self):
173177
if isinstance(self.compose_file_name, str):
@@ -178,7 +182,7 @@ def __enter__(self) -> "DockerCompose":
178182
return self
179183

180184
def __exit__(self, exc_type, exc_val, exc_tb) -> None:
181-
self.stop()
185+
self.stop(not self.keep_volumes)
182186

183187
def docker_compose_command(self) -> list[str]:
184188
"""
@@ -195,6 +199,8 @@ def compose_command_property(self) -> list[str]:
195199
if self.compose_file_name:
196200
for file in self.compose_file_name:
197201
docker_compose_cmd += ["-f", file]
202+
if self.profiles:
203+
docker_compose_cmd += [item for profile in self.profiles for item in ["--profile", profile]]
198204
if self.env_file:
199205
docker_compose_cmd += ["--env-file", self.env_file]
200206
return docker_compose_cmd
@@ -257,6 +263,36 @@ def get_logs(self, *services: str) -> tuple[str, str]:
257263
result = self._run_command(cmd=logs_cmd)
258264
return result.stdout.decode("utf-8"), result.stderr.decode("utf-8")
259265

266+
def get_config(
267+
self, *, path_resolution: bool = True, normalize: bool = True, interpolate: bool = True
268+
) -> dict[str, Any]:
269+
"""
270+
Parse, resolve and returns compose file via `docker config --format json`.
271+
In case of multiple compose files, the returned value will be a merge of all files.
272+
273+
See: https://docs.docker.com/reference/cli/docker/compose/config/ for more details
274+
275+
:param path_resolution: whether to resolve file paths
276+
:param normalize: whether to normalize compose model
277+
:param interpolate: whether to interpolate environment variables
278+
279+
Returns:
280+
Compose file
281+
282+
"""
283+
if "DOCKER_COMPOSE_GET_CONFIG" in _WARNINGS:
284+
warning(_WARNINGS.pop("DOCKER_COMPOSE_GET_CONFIG"))
285+
config_cmd = [*self.compose_command_property, "config", "--format", "json"]
286+
if not path_resolution:
287+
config_cmd.append("--no-path-resolution")
288+
if not normalize:
289+
config_cmd.append("--no-normalize")
290+
if not interpolate:
291+
config_cmd.append("--no-interpolate")
292+
293+
cmd_output = self._run_command(cmd=config_cmd).stdout
294+
return cast(dict[str, Any], loads(cmd_output))
295+
260296
def get_containers(self, include_all=False) -> list[ComposeContainer]:
261297
"""
262298
Fetch information about running containers via `docker compose ps --format json`.

0 commit comments

Comments
 (0)