|
4 | 4 | from os.path import exists |
5 | 5 | from pathlib import Path |
6 | 6 | from typing import Optional, Union |
| 7 | +from urllib.parse import urlparse |
7 | 8 |
|
8 | 9 | MAX_TRIES = int(environ.get("TC_MAX_TRIES", 120)) |
9 | 10 | SLEEP_TIME = int(environ.get("TC_POOLING_INTERVAL", 1)) |
|
12 | 13 | RYUK_IMAGE: str = environ.get("RYUK_CONTAINER_IMAGE", "testcontainers/ryuk:0.8.1") |
13 | 14 | RYUK_PRIVILEGED: bool = environ.get("TESTCONTAINERS_RYUK_PRIVILEGED", "false") == "true" |
14 | 15 | RYUK_DISABLED: bool = environ.get("TESTCONTAINERS_RYUK_DISABLED", "false") == "true" |
15 | | -RYUK_DOCKER_SOCKET: str = environ.get("TESTCONTAINERS_DOCKER_SOCKET_OVERRIDE", "/var/run/docker.sock") |
| 16 | +RYUK_DOCKER_SOCKET: Optional[str] = environ.get("TESTCONTAINERS_DOCKER_SOCKET_OVERRIDE", None) |
16 | 17 | RYUK_RECONNECTION_TIMEOUT: str = environ.get("RYUK_RECONNECTION_TIMEOUT", "10s") |
17 | 18 | TC_HOST_OVERRIDE: Optional[str] = environ.get("TC_HOST", environ.get("TESTCONTAINERS_HOST_OVERRIDE")) |
18 | 19 |
|
@@ -49,7 +50,6 @@ class TestcontainersConfiguration: |
49 | 50 | ryuk_image: str = RYUK_IMAGE |
50 | 51 | ryuk_privileged: bool = RYUK_PRIVILEGED |
51 | 52 | ryuk_disabled: bool = RYUK_DISABLED |
52 | | - ryuk_docker_socket: str = RYUK_DOCKER_SOCKET |
53 | 53 | ryuk_reconnection_timeout: str = RYUK_RECONNECTION_TIMEOUT |
54 | 54 | tc_properties: dict[str, str] = field(default_factory=read_tc_properties) |
55 | 55 | _docker_auth_config: Optional[str] = field(default_factory=lambda: environ.get("DOCKER_AUTH_CONFIG")) |
@@ -79,6 +79,17 @@ def tc_properties_get_tc_host(self) -> Union[str, None]: |
79 | 79 | def timeout(self) -> int: |
80 | 80 | return self.max_tries * self.sleep_time |
81 | 81 |
|
| 82 | + @property |
| 83 | + def docker_host(self) -> Optional[str]: |
| 84 | + return self.tc_properties_get_tc_host() or environ.get("DOCKER_HOST") |
| 85 | + |
| 86 | + @property |
| 87 | + def ryuk_docker_socket(self) -> str: |
| 88 | + if RYUK_DOCKER_SOCKET: |
| 89 | + return RYUK_DOCKER_SOCKET |
| 90 | + if self.docker_host: |
| 91 | + return urlparse(self.docker_host).path |
| 92 | + return "/var/run/docker.sock" |
82 | 93 |
|
83 | 94 | testcontainers_config = TestcontainersConfiguration() |
84 | 95 |
|
|
0 commit comments