Skip to content

Commit 8dd629c

Browse files
committed
feat(core): DockerCompose: support list of env_files
1 parent ef65bd1 commit 8dd629c

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

core/testcontainers/compose/compose.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ class DockerCompose:
137137
Wait for the services to be healthy
138138
(as per healthcheck definitions in the docker compose configuration)
139139
env_file:
140-
Path to an '.env' file containing environment variables
140+
Path(s) to an '.env' file containing environment variables
141141
to pass to docker compose.
142142
services:
143143
The list of services to use from this DockerCompose.
@@ -174,14 +174,16 @@ class DockerCompose:
174174
build: bool = False
175175
wait: bool = True
176176
keep_volumes: bool = False
177-
env_file: Optional[str] = None
177+
env_file: Optional[Union[str, list[str]]] = None
178178
services: Optional[list[str]] = None
179179
docker_command_path: Optional[str] = None
180180
profiles: Optional[list[str]] = None
181181

182182
def __post_init__(self) -> None:
183183
if isinstance(self.compose_file_name, str):
184184
self.compose_file_name = [self.compose_file_name]
185+
if isinstance(self.env_file, str):
186+
self.env_file = [self.env_file]
185187

186188
def __enter__(self) -> "DockerCompose":
187189
self.start()
@@ -210,7 +212,8 @@ def compose_command_property(self) -> list[str]:
210212
if self.profiles:
211213
docker_compose_cmd += [item for profile in self.profiles for item in ["--profile", profile]]
212214
if self.env_file:
213-
docker_compose_cmd += ["--env-file", self.env_file]
215+
for env_file in self.env_file:
216+
docker_compose_cmd += ["--env-file", env_file]
214217
return docker_compose_cmd
215218

216219
def start(self) -> None:

0 commit comments

Comments
 (0)