fix(macos-container): anchor relative Dockerfile path to build context
test / unit (pull_request) Successful in 33s
test / integration (pull_request) Successful in 17s
lint / lint (push) Successful in 1m49s
test / unit (push) Successful in 33s
test / integration (push) Successful in 18s
Update Quality Badges / update-badges (push) Successful in 1m19s
test / unit (pull_request) Successful in 33s
test / integration (pull_request) Successful in 17s
lint / lint (push) Successful in 1m49s
test / unit (push) Successful in 33s
test / integration (push) Successful in 18s
Update Quality Badges / update-badges (push) Successful in 1m19s
`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 <noreply@anthropic.com>
This commit was merged in pull request #273.
This commit is contained in:
@@ -68,6 +68,11 @@ def build_image(ref: str, context: str, *, dockerfile: str = "") -> None:
|
|||||||
_ensure_builder_dns()
|
_ensure_builder_dns()
|
||||||
args = [_CONTAINER, "build", "-t", ref, "--dns", dns_server()]
|
args = [_CONTAINER, "build", "-t", ref, "--dns", dns_server()]
|
||||||
if dockerfile:
|
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.extend(["-f", dockerfile])
|
||||||
args.append(context)
|
args.append(context)
|
||||||
subprocess.run(args, check=True)
|
subprocess.run(args, check=True)
|
||||||
|
|||||||
@@ -73,6 +73,33 @@ resolver #2
|
|||||||
)
|
)
|
||||||
self.assertTrue(run.call_args_list[-1].kwargs["check"])
|
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):
|
def test_commit_container_execs_tar_and_builds_image(self):
|
||||||
# stderr is bytes because subprocess.run uses stderr=PIPE without text=True
|
# stderr is bytes because subprocess.run uses stderr=PIPE without text=True
|
||||||
completed = util.subprocess.CompletedProcess(
|
completed = util.subprocess.CompletedProcess(
|
||||||
|
|||||||
Reference in New Issue
Block a user