From 9537b1d5b501ab0116cd7774110917a0fb39a1a7 Mon Sep 17 00:00:00 2001 From: didericis Date: Thu, 25 Jun 2026 03:03:08 -0400 Subject: [PATCH] fix(macos-container): anchor relative Dockerfile path to build context `container build` resolves -f relative to the current working directory, not the build context, so builds failed from any cwd other than the repo root. Anchor a relative Dockerfile to the context before passing it. Co-Authored-By: Claude Opus 4.8 --- bot_bottle/backend/macos_container/util.py | 5 ++++ tests/unit/test_macos_container_util.py | 27 ++++++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/bot_bottle/backend/macos_container/util.py b/bot_bottle/backend/macos_container/util.py index 52ea20d..ccb8f06 100644 --- a/bot_bottle/backend/macos_container/util.py +++ b/bot_bottle/backend/macos_container/util.py @@ -68,6 +68,11 @@ def build_image(ref: str, context: str, *, dockerfile: str = "") -> None: _ensure_builder_dns() args = [_CONTAINER, "build", "-t", ref, "--dns", dns_server()] if dockerfile: + # `container build` resolves -f relative to the current working + # directory, not the build context. Anchor a relative Dockerfile to + # the context so builds work from any cwd. + if not os.path.isabs(dockerfile): + dockerfile = os.path.join(context, dockerfile) args.extend(["-f", dockerfile]) args.append(context) subprocess.run(args, check=True) diff --git a/tests/unit/test_macos_container_util.py b/tests/unit/test_macos_container_util.py index 9943163..2e0f3bd 100644 --- a/tests/unit/test_macos_container_util.py +++ b/tests/unit/test_macos_container_util.py @@ -73,6 +73,33 @@ resolver #2 ) self.assertTrue(run.call_args_list[-1].kwargs["check"]) + def test_build_image_anchors_relative_dockerfile_to_context(self): + status = util.subprocess.CompletedProcess( + args=[], + returncode=0, + stdout=( + '[{"status":{"state":"running"},' + '"configuration":{"dns":{"nameservers":["9.9.9.9"]}}}]' + ), + stderr="", + ) + with patch.object(util.subprocess, "run", return_value=status) as run, \ + patch.object(util.os, "environ", { + "BOT_BOTTLE_MACOS_CONTAINER_DNS": "9.9.9.9", + }): + util.build_image( + "bot-bottle-sidecars:latest", + "/repo", + dockerfile="Dockerfile.sidecars", + ) + self.assertEqual( + [ + "container", "build", "-t", "bot-bottle-sidecars:latest", + "--dns", "9.9.9.9", "-f", "/repo/Dockerfile.sidecars", "/repo", + ], + run.call_args_list[-1].args[0], + ) + def test_commit_container_execs_tar_and_builds_image(self): # stderr is bytes because subprocess.run uses stderr=PIPE without text=True completed = util.subprocess.CompletedProcess(