File tree Expand file tree Collapse file tree 5 files changed +40
-3
lines changed Expand file tree Collapse file tree 5 files changed +40
-3
lines changed Original file line number Diff line number Diff line change 1
1
ARG PYTHON_VERSION=3.10
2
2
FROM python:${PYTHON_VERSION}-slim-bookworm
3
+ ARG POETRY_EXTRAS
4
+
5
+ ENV PYTHONPATH=/workspace
3
6
4
7
ENV POETRY_NO_INTERACTION=1 \
5
8
POETRY_VIRTUALENVS_IN_PROJECT=1 \
@@ -20,10 +23,18 @@ RUN bash -c 'python -m venv /opt/poetry-venv && source $_/bin/activate && pip in
20
23
# install dependencies with poetry
21
24
COPY pyproject.toml .
22
25
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
24
31
25
32
# copy project source
26
33
COPY . .
27
34
28
35
# 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
Original file line number Diff line number Diff line change 4
4
from typing import Callable
5
5
from testcontainers .core .container import DockerClient
6
6
from pprint import pprint
7
+ from testcontainers .core .utils import is_arm
7
8
import sys
8
9
10
+ from .list_arm_extras import get_arm_extras
11
+
9
12
PROJECT_DIR = Path (__file__ ).parent .parent .parent .resolve ()
10
13
11
14
@@ -25,11 +28,16 @@ def python_testcontainer_image() -> str:
25
28
py_version = "." .join (map (str , sys .version_info [:2 ]))
26
29
image_name = f"testcontainers-python:{ py_version } "
27
30
client = DockerClient ()
31
+ build_args = {"PYTHON_VERSION" : py_version }
32
+
33
+ if is_arm ():
34
+ build_args ["POETRY_EXTRAS" ] = get_arm_extras ()
35
+
28
36
client .build (
29
37
path = str (PROJECT_DIR ),
30
38
tag = image_name ,
31
39
rm = False ,
32
- buildargs = { "PYTHON_VERSION" : py_version } ,
40
+ buildargs = build_args ,
33
41
)
34
42
return image_name
35
43
Original file line number Diff line number Diff line change
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 )
You can’t perform that action at this time.
0 commit comments