Skip to content

Commit 586e4e6

Browse files
Tranquility2alexanderankin
authored andcommitted
fix(core): Add kwargs to image build
1 parent f7c29cb commit 586e4e6

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

core/testcontainers/core/image.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,10 @@ def __init__(
4949
self._dockerfile_path = dockerfile_path
5050
self._no_cache = no_cache
5151

52-
def build(self, **kwargs) -> Self:
52+
def build(self) -> Self:
5353
logger.info(f"Building image from {self.path}")
5454
docker_client = self.get_docker_client()
55+
kwargs = self._kwargs
5556
self._image, self._logs = docker_client.build(
5657
path=str(self.path), tag=self.tag, dockerfile=self._dockerfile_path, nocache=self._no_cache, **kwargs
5758
)

core/tests/test_image.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,3 +64,24 @@ def test_docker_image_with_custom_dockerfile_path(dockerfile_path: Optional[Path
6464
with DockerContainer(str(image)) as container:
6565
assert container._container.image.short_id.endswith(image_short_id), "Image ID mismatch"
6666
assert container.get_logs() == (("Hello world!\n").encode(), b""), "Container logs mismatch"
67+
68+
69+
def test_docker_image_with_kwargs():
70+
with tempfile.TemporaryDirectory() as temp_directory:
71+
with open(f"{temp_directory}/Dockerfile", "w") as f:
72+
f.write(
73+
f"""
74+
FROM alpine:latest
75+
ARG TEST_ARG
76+
ENV TEST_ARG $TEST_ARG
77+
CMD echo $TEST_ARG
78+
"""
79+
)
80+
with DockerImage(
81+
path=temp_directory, tag="test", clean_up=True, no_cache=True, buildargs={"TEST_ARG": "new_arg"}
82+
) as image:
83+
image_short_id = image.short_id
84+
assert image.get_wrapped_image() is not None
85+
with DockerContainer(str(image)) as container:
86+
assert container._container.image.short_id.endswith(image_short_id), "Image ID mismatch"
87+
assert container.get_logs() == (("new_arg\n").encode(), b""), "Container logs mismatch"

0 commit comments

Comments
 (0)