Skip to content
Open
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
27 changes: 27 additions & 0 deletions launch/core/platforms/windows.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,32 @@
from docker.models.containers import Container


# Passing a host Docker daemon into an evaluated task container is privileged.
# Keep it opt-in and let callers select the source pipe explicitly.
WINDOWS_CONTAINER_DOCKER_PIPE_SOURCE_ENV = "REPOLAUNCH_WINDOWS_CONTAINER_DOCKER_PIPE_SOURCE"
WINDOWS_DOCKER_PIPE_TARGET = r"\\.\pipe\docker_engine"


def build_windows_container_docker_mounts() -> list[Any]:
"""Return an explicit host-Docker npipe mount for Windows task containers.

Some Windows projects invoke Docker from inside the task container and use
Docker's conventional ``\\\\.\\pipe\\docker_engine`` endpoint. Native engines
may expose a differently named host pipe. The evaluator must not expose
the host daemon by default; callers can opt in by setting
``REPOLAUNCH_WINDOWS_CONTAINER_DOCKER_PIPE_SOURCE`` to the host npipe path.
An empty value explicitly disables the mount.
"""
source = os.environ.get(WINDOWS_CONTAINER_DOCKER_PIPE_SOURCE_ENV, "").strip()
if not source:
return []
return [docker.types.Mount(
source=source,
target=WINDOWS_DOCKER_PIPE_TARGET,
type="npipe",
)]


class WindowsRuntime(LinuxRuntime):

def __init__(
Expand Down Expand Up @@ -148,6 +174,7 @@ def _start_container(
run_kwargs = {
"cpu_count": CPU_CORES, # cpu_quota is Linux-only
"mem_limit": MEM_LIMIT,
"mounts": build_windows_container_docker_mounts(),
}

container = client.containers.run(
Expand Down
49 changes: 49 additions & 0 deletions tests/windows_container_docker_pipe_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
from __future__ import annotations

import os
import sys
import unittest
from pathlib import Path
from unittest import mock

sys.path.insert(0, str(Path(__file__).resolve().parents[1]))

from launch.core.platforms import windows


class WindowsContainerDockerPipeTest(unittest.TestCase):
def test_mount_is_disabled_without_an_explicit_source(self) -> None:
with mock.patch.dict(
os.environ,
{windows.WINDOWS_CONTAINER_DOCKER_PIPE_SOURCE_ENV: ""},
clear=False,
):
self.assertEqual(windows.build_windows_container_docker_mounts(), [])

def test_explicit_source_is_mounted_at_the_conventional_guest_pipe(self) -> None:
observed: list[dict[str, str]] = []

def fake_mount(**kwargs: str) -> dict[str, str]:
observed.append(kwargs)
return kwargs

with mock.patch.dict(
os.environ,
{
windows.WINDOWS_CONTAINER_DOCKER_PIPE_SOURCE_ENV:
r"\\.\pipe\docker_engine_windows"
},
clear=False,
), mock.patch.object(windows.docker.types, "Mount", side_effect=fake_mount):
mounts = windows.build_windows_container_docker_mounts()

self.assertEqual(mounts, observed)
self.assertEqual(observed, [{
"source": r"\\.\pipe\docker_engine_windows",
"target": r"\\.\pipe\docker_engine",
"type": "npipe",
}])


if __name__ == "__main__":
unittest.main()