Skip to content

chore: Update pyproject and tests to support Mac's/arm local development #814

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions core/testcontainers/core/docker_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ def find_host_network(self) -> Optional[str]:
except ipaddress.AddressValueError:
continue
if docker_host in subnet:
return cast(str, network.name)
return cast("str", network.name)
except (ipaddress.AddressValueError, OSError):
pass
return None
Expand All @@ -163,7 +163,7 @@ def port(self, container_id: str, port: int) -> str:
port_mappings = self.client.api.port(container_id, port)
if not port_mappings:
raise ConnectionError(f"Port mapping for container {container_id} and port {port} is not available")
return cast(str, port_mappings[0]["HostPort"])
return cast("str", port_mappings[0]["HostPort"])

def get_container(self, container_id: str) -> dict[str, Any]:
"""
Expand All @@ -172,7 +172,7 @@ def get_container(self, container_id: str) -> dict[str, Any]:
containers = self.client.api.containers(filters={"id": container_id})
if not containers:
raise RuntimeError(f"Could not get container with id {container_id}")
return cast(dict[str, Any], containers[0])
return cast("dict[str, Any]", containers[0])

def bridge_ip(self, container_id: str) -> str:
"""
Expand Down Expand Up @@ -241,7 +241,7 @@ def host(self) -> str:
hostname = url.hostname
if not hostname or (hostname == "localnpipe" and utils.is_windows()):
return "localhost"
return cast(str, url.hostname)
return cast("str", url.hostname)
if utils.inside_container() and ("unix" in url.scheme or "npipe" in url.scheme):
ip_address = utils.default_gateway_ip()
if ip_address:
Expand All @@ -257,7 +257,7 @@ def login(self, auth_config: DockerAuthInfo) -> None:

def client_networks_create(self, name: str, param: dict[str, Any]) -> dict[str, Any]:
labels = create_labels("", param.get("labels"))
return cast(dict[str, Any], self.client.networks.create(name, **{**param, "labels": labels}))
return cast("dict[str, Any]", self.client.networks.create(name, **{**param, "labels": labels}))


def get_docker_host() -> Optional[str]:
Expand Down
9 changes: 9 additions & 0 deletions core/tests/test_core_registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,13 @@
from testcontainers.core.waiting_utils import wait_container_is_ready

from testcontainers.registry import DockerRegistryContainer
from testcontainers.core.utils import is_mac


@pytest.mark.skipif(
is_mac(),
reason="Docker Desktop on macOS does not support insecure private registries without daemon reconfiguration",
)
def test_missing_on_private_registry(monkeypatch):
username = "user"
password = "pass"
Expand All @@ -41,6 +46,10 @@ def test_missing_on_private_registry(monkeypatch):
wait_container_is_ready(test_container)


@pytest.mark.skipif(
is_mac(),
reason="Docker Desktop on macOS does not support local insecure registries over HTTP without modifying daemon settings",
)
@pytest.mark.parametrize(
"image,tag,username,password",
[
Expand Down
8 changes: 8 additions & 0 deletions core/tests/test_docker_in_docker.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from testcontainers.core.container import DockerContainer
from testcontainers.core.docker_client import DockerClient, LOGGER
from testcontainers.core.utils import inside_container
from testcontainers.core.utils import is_mac
from testcontainers.core.waiting_utils import wait_for_logs


Expand All @@ -36,6 +37,7 @@ def _wait_for_dind_return_ip(client, dind):
return docker_host_ip


@pytest.mark.skipif(is_mac(), reason="Docker socket forwarding (socat) is unsupported on Docker Desktop for macOS")
def test_wait_for_logs_docker_in_docker():
# real dind isn't possible (AFAIK) in CI
# forwarding the socket to a container port is at least somewhat the same
Expand Down Expand Up @@ -64,6 +66,9 @@ def test_wait_for_logs_docker_in_docker():
not_really_dind.remove()


@pytest.mark.skipif(
is_mac(), reason="Bridge networking and Docker socket forwarding are not supported on Docker Desktop for macOS"
)
def test_dind_inherits_network():
client = DockerClient()
try:
Expand Down Expand Up @@ -158,6 +163,9 @@ def test_find_host_network_in_dood() -> None:
assert DockerClient().find_host_network() == os.environ[EXPECTED_NETWORK_VAR]


@pytest.mark.skipif(
is_mac(), reason="Docker socket mounting and container networking do not work reliably on Docker Desktop for macOS"
)
@pytest.mark.skipif(not Path(tcc.ryuk_docker_socket).exists(), reason="No docker socket available")
def test_dood(python_testcontainer_image: str) -> None:
"""
Expand Down
8 changes: 8 additions & 0 deletions core/tests/test_ryuk.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,14 @@
from testcontainers.core.config import testcontainers_config
from testcontainers.core.container import Reaper
from testcontainers.core.container import DockerContainer
from testcontainers.core.utils import is_mac
from testcontainers.core.waiting_utils import wait_for_logs


@pytest.mark.skipif(
is_mac(),
reason="Ryuk container reaping is unreliable on Docker Desktop for macOS due to VM-based container lifecycle handling",
)
@pytest.mark.inside_docker_check
def test_wait_for_reaper(monkeypatch: MonkeyPatch):
Reaper.delete_instance()
Expand Down Expand Up @@ -41,6 +46,9 @@ def test_wait_for_reaper(monkeypatch: MonkeyPatch):
Reaper.delete_instance()


@pytest.mark.skipif(
is_mac(), reason="Ryuk disabling behavior is unreliable on Docker Desktop for macOS due to Docker socket emulation"
)
@pytest.mark.inside_docker_check
def test_container_without_ryuk(monkeypatch: MonkeyPatch):
Reaper.delete_instance()
Expand Down
8 changes: 4 additions & 4 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ httpx = { version = "*", optional = true }
azure-cosmos = { version = "*", optional = true }
cryptography = { version = "*", optional = true }
trino = { version = "*", optional = true }
ibm_db_sa = { version = "*", optional = true }
ibm_db_sa = { version = "*", optional = true, markers = "platform_machine != 'aarch64' and platform_machine != 'arm64'" }

[tool.poetry.extras]
arangodb = ["python-arango"]
Expand Down