Skip to content

Commit

Permalink
fix: move TESTCONTAINERS_HOST_OVERRIDE to config.py (#603)
Browse files Browse the repository at this point in the history
fix #602
  • Loading branch information
alexanderankin authored Jun 7, 2024
1 parent 54822de commit 2a5a190
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
6 changes: 6 additions & 0 deletions core/testcontainers/core/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
RYUK_DISABLED: bool = environ.get("TESTCONTAINERS_RYUK_DISABLED", "false") == "true"
RYUK_DOCKER_SOCKET: str = environ.get("TESTCONTAINERS_DOCKER_SOCKET_OVERRIDE", "/var/run/docker.sock")
RYUK_RECONNECTION_TIMEOUT: str = environ.get("RYUK_RECONNECTION_TIMEOUT", "10s")
TC_HOST_OVERRIDE: Optional[str] = environ.get("TC_HOST", environ.get("TESTCONTAINERS_HOST_OVERRIDE"))

TC_FILE = ".testcontainers.properties"
TC_GLOBAL = Path.home() / TC_FILE
Expand Down Expand Up @@ -52,6 +53,11 @@ class TestcontainersConfiguration:
ryuk_reconnection_timeout: str = RYUK_RECONNECTION_TIMEOUT
tc_properties: dict[str, str] = field(default_factory=read_tc_properties)
_docker_auth_config: Optional[str] = field(default_factory=lambda: environ.get("DOCKER_AUTH_CONFIG"))
tc_host_override: Optional[str] = TC_HOST_OVERRIDE
"""
https://github.com/testcontainers/testcontainers-go/blob/dd76d1e39c654433a3d80429690d07abcec04424/docker.go#L644
if os env TC_HOST is set, use it
"""

@property
def docker_auth_config(self):
Expand Down
8 changes: 2 additions & 6 deletions core/testcontainers/core/docker_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,18 +187,14 @@ def host(self) -> str:
"""
Get the hostname or ip address of the docker host.
"""
# https://github.com/testcontainers/testcontainers-go/blob/dd76d1e39c654433a3d80429690d07abcec04424/docker.go#L644
# if os env TC_HOST is set, use it
host = os.environ.get("TC_HOST")
if not host:
host = os.environ.get("TESTCONTAINERS_HOST_OVERRIDE")
host = c.tc_host_override
if host:
return host
try:
url = urllib.parse.urlparse(self.client.api.base_url)

except ValueError:
return None
return "localhost"
if "http" in url.scheme or "tcp" in url.scheme:
return url.hostname
if inside_container() and ("unix" in url.scheme or "npipe" in url.scheme):
Expand Down

0 comments on commit 2a5a190

Please sign in to comment.