Skip to content

Commit 2907cf8

Browse files
committed
try to force linux/amd64
1 parent 72b9178 commit 2907cf8

File tree

2 files changed

+17
-7
lines changed

2 files changed

+17
-7
lines changed

eval_protocol/cli_commands/local_test.py

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,16 @@ def _run_pytest_host(pytest_target: str) -> int:
2424
return proc.returncode
2525

2626

27-
def _build_docker_image(dockerfile_path: str, image_tag: str) -> bool:
27+
def _build_docker_image(dockerfile_path: str, image_tag: str, platform: str | None = None) -> bool:
2828
context_dir = os.path.dirname(dockerfile_path)
2929
print(f"Building Docker image '{image_tag}' from {dockerfile_path} ...")
3030
try:
31+
cmd = ["docker", "build"]
32+
if platform:
33+
cmd += ["--platform", platform]
34+
cmd += ["-t", image_tag, "-f", dockerfile_path, context_dir]
3135
proc = subprocess.run(
32-
["docker", "build", "-t", image_tag, "-f", dockerfile_path, context_dir],
36+
cmd,
3337
stdout=subprocess.PIPE,
3438
stderr=subprocess.STDOUT,
3539
text=True,
@@ -41,7 +45,7 @@ def _build_docker_image(dockerfile_path: str, image_tag: str) -> bool:
4145
return False
4246

4347

44-
def _run_pytest_in_docker(project_root: str, image_tag: str, pytest_target: str) -> int:
48+
def _run_pytest_in_docker(project_root: str, image_tag: str, pytest_target: str, platform: str | None = None) -> int:
4549
workdir = "/workspace"
4650
# Mount read-only is safer; but tests may write artifacts. Use read-write.
4751
cmd = [
@@ -57,6 +61,8 @@ def _run_pytest_in_docker(project_root: str, image_tag: str, pytest_target: str)
5761
"-w",
5862
workdir,
5963
]
64+
if platform:
65+
cmd += ["--platform", platform]
6066
# Try to match host user to avoid permission problems on mounted volume
6167
try:
6268
uid = os.getuid() # type: ignore[attr-defined]
@@ -136,15 +142,19 @@ def local_test_command(args: argparse.Namespace) -> int:
136142
os.makedirs(os.path.join(project_root, ".eval_protocol"), exist_ok=True)
137143
except Exception:
138144
pass
145+
# Choose platform to emulate Linux host (default to amd64 on macOS, override with EP_DOCKER_PLATFORM)
146+
selected_platform = os.environ.get("EP_DOCKER_PLATFORM")
147+
if not selected_platform and sys.platform == "darwin":
148+
selected_platform = "linux/amd64"
139149
image_tag = "ep-evaluator:local"
140-
ok = _build_docker_image(dockerfiles[0], image_tag)
150+
ok = _build_docker_image(dockerfiles[0], image_tag, platform=selected_platform)
141151
if not ok:
142152
print("Docker build failed. See logs above.")
143153
return 1
144154
if not pytest_target:
145155
print("Error: Failed to resolve a pytest target to run.")
146156
return 1
147-
return _run_pytest_in_docker(project_root, image_tag, pytest_target)
157+
return _run_pytest_in_docker(project_root, image_tag, pytest_target, platform=selected_platform)
148158

149159
# No Dockerfile: run on host
150160
if not pytest_target:

tests/test_cli_local_test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,11 +95,11 @@ def test_local_test_builds_and_runs_in_docker(tmp_path, monkeypatch):
9595
from eval_protocol.cli_commands import local_test as lt
9696

9797
monkeypatch.setattr(lt, "_find_dockerfiles", lambda root: [str(project / "Dockerfile")])
98-
monkeypatch.setattr(lt, "_build_docker_image", lambda dockerfile, tag: True)
98+
monkeypatch.setattr(lt, "_build_docker_image", lambda dockerfile, tag, platform=None: True)
9999

100100
captured = {"target": "", "image": ""}
101101

102-
def _fake_run_docker(root: str, image_tag: str, pytest_target: str) -> int:
102+
def _fake_run_docker(root: str, image_tag: str, pytest_target: str, platform=None) -> int:
103103
captured["target"] = pytest_target
104104
captured["image"] = image_tag
105105
return 0

0 commit comments

Comments
 (0)