Skip to content

Commit cb83cb4

Browse files
committed
chore: enable docker in docker tests to pass on arm machines
1 parent b7d41dd commit cb83cb4

File tree

5 files changed

+40
-3
lines changed

5 files changed

+40
-3
lines changed

Dockerfile

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
ARG PYTHON_VERSION=3.10
22
FROM python:${PYTHON_VERSION}-slim-bookworm
3+
ARG POETRY_EXTRAS
4+
5+
ENV PYTHONPATH=/workspace
36

47
ENV POETRY_NO_INTERACTION=1 \
58
POETRY_VIRTUALENVS_IN_PROJECT=1 \
@@ -20,10 +23,18 @@ RUN bash -c 'python -m venv /opt/poetry-venv && source $_/bin/activate && pip in
2023
# install dependencies with poetry
2124
COPY pyproject.toml .
2225
COPY poetry.lock .
23-
RUN poetry install --all-extras --with dev --no-root
26+
RUN if [ "$POETRY_EXTRAS" = "" ]; then \
27+
poetry install --all-extras --with dev --no-root; \
28+
else \
29+
poetry install --extras "$POETRY_EXTRAS" --with dev --no-root; \
30+
fi
2431

2532
# copy project source
2633
COPY . .
2734

2835
# install project with poetry
29-
RUN poetry install --all-extras --with dev
36+
RUN if [ "$POETRY_EXTRAS" = "" ]; then \
37+
poetry install --all-extras --with dev; \
38+
else \
39+
poetry install --extras "$POETRY_EXTRAS" --with dev; \
40+
fi

core/__init__.py

Whitespace-only changes.

core/tests/__init__.py

Whitespace-only changes.

core/tests/conftest.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,11 @@
44
from typing import Callable
55
from testcontainers.core.container import DockerClient
66
from pprint import pprint
7+
from testcontainers.core.utils import is_arm
78
import sys
89

10+
from .list_arm_extras import get_arm_extras
11+
912
PROJECT_DIR = Path(__file__).parent.parent.parent.resolve()
1013

1114

@@ -25,11 +28,16 @@ def python_testcontainer_image() -> str:
2528
py_version = ".".join(map(str, sys.version_info[:2]))
2629
image_name = f"testcontainers-python:{py_version}"
2730
client = DockerClient()
31+
build_args = {"PYTHON_VERSION": py_version}
32+
33+
if is_arm():
34+
build_args["POETRY_EXTRAS"] = get_arm_extras()
35+
2836
client.build(
2937
path=str(PROJECT_DIR),
3038
tag=image_name,
3139
rm=False,
32-
buildargs={"PYTHON_VERSION": py_version},
40+
buildargs=build_args,
3341
)
3442
return image_name
3543

core/tests/list_arm_extras.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
from pathlib import Path
2+
from testcontainers.core.utils import is_arm
3+
4+
try:
5+
import tomllib # Python 3.11+
6+
except ImportError:
7+
import tomli as tomllib
8+
9+
SKIPPED_EXTRAS = {"db2"} # skip incompatible extras
10+
11+
12+
def get_arm_extras():
13+
with Path("pyproject.toml").open("rb") as f:
14+
data = tomllib.load(f)
15+
16+
extras = data["tool"]["poetry"]["extras"]
17+
skip = SKIPPED_EXTRAS
18+
return " ".join(k for k in extras if k not in skip)

0 commit comments

Comments
 (0)