Skip to content

Commit 60f51ba

Browse files
committed
Fix improper reading of .testcontainers.properties
The environment variables were not overridden from the .testcontainers.properties file for ryuk variables. This causes the properties file to never actually be used. This commit detects the environment variable, and if unspecified falls back to the properties file, and if not specifed, defaults to false
1 parent fe206eb commit 60f51ba

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

core/testcontainers/core/config.py

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
import docker
1313

14+
ENABLE_FLAGS = ("yes", "true", "t", "y", "1")
1415

1516
class ConnectionMode(Enum):
1617
bridge_ip = "bridge_ip"
@@ -52,7 +53,7 @@ def get_bool_env(name: str) -> bool:
5253
Defaults to False.
5354
"""
5455
value = environ.get(name, "")
55-
return value.lower() in ("yes", "true", "t", "y", "1")
56+
return value.lower() in ENABLE_FLAGS
5657

5758

5859
TC_FILE = ".testcontainers.properties"
@@ -96,11 +97,19 @@ def read_tc_properties() -> dict[str, str]:
9697

9798
@dataclass
9899
class TestcontainersConfiguration:
100+
101+
def _render_bool(self, env_name: str, prop_name: str) -> bool:
102+
env_val = environ.get(env_name, None)
103+
if env_val is not None:
104+
return env_val.lower() in ENABLE_FLAGS
105+
prop_val = self.tc_properties.get(prop_name, None)
106+
if prop_val is not None:
107+
return prop_val.lower() in ENABLE_FLAGS
108+
return False
109+
99110
max_tries: int = int(environ.get("TC_MAX_TRIES", "120"))
100111
sleep_time: float = float(environ.get("TC_POOLING_INTERVAL", "1"))
101112
ryuk_image: str = environ.get("RYUK_CONTAINER_IMAGE", "testcontainers/ryuk:0.8.1")
102-
ryuk_privileged: bool = get_bool_env("TESTCONTAINERS_RYUK_PRIVILEGED")
103-
ryuk_disabled: bool = get_bool_env("TESTCONTAINERS_RYUK_DISABLED")
104113
_ryuk_docker_socket: str = ""
105114
ryuk_reconnection_timeout: str = environ.get("RYUK_RECONNECTION_TIMEOUT", "10s")
106115
tc_properties: dict[str, str] = field(default_factory=read_tc_properties)
@@ -129,6 +138,14 @@ def docker_auth_config(self, value: str) -> None:
129138
def tc_properties_get_tc_host(self) -> Union[str, None]:
130139
return self.tc_properties.get("tc.host")
131140

141+
@property
142+
def ryuk_privileged(self) -> bool:
143+
return self._render_bool("TESTCONTAINERS_RYUK_PRIVILEGED", "ryuk.container.privileged")
144+
145+
@property
146+
def ryuk_disabled(self) -> bool:
147+
return self._render_bool("TESTCONTAINERS_RYUK_DISABLED", "ryuk.disabled")
148+
132149
@property
133150
def timeout(self) -> float:
134151
return self.max_tries * self.sleep_time

0 commit comments

Comments
 (0)