From e9193d8716997ebd28372b6b688ea11a4ca34d77 Mon Sep 17 00:00:00 2001 From: Tom Plant Date: Thu, 7 Mar 2024 12:02:24 +0000 Subject: [PATCH] feat: add `--load` to `docker build` supports alternative BuildKit drivers Signed-off-by: Tom Plant --- ctfcli/core/image.py | 4 +++- tests/core/test_image.py | 12 ++++++++---- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/ctfcli/core/image.py b/ctfcli/core/image.py index e66e6e7..025187f 100644 --- a/ctfcli/core/image.py +++ b/ctfcli/core/image.py @@ -24,7 +24,9 @@ def __init__(self, name: str, build_path: Optional[Union[str, PathLike]] = None) self.built = False def build(self) -> Optional[str]: - docker_build = subprocess.call(["docker", "build", "-t", self.name, "."], cwd=self.build_path.absolute()) + docker_build = subprocess.call( + ["docker", "build", "--load", "-t", self.name, "."], cwd=self.build_path.absolute() + ) if docker_build != 0: return diff --git a/tests/core/test_image.py b/tests/core/test_image.py index 2e773f4..8e6ab37 100644 --- a/tests/core/test_image.py +++ b/tests/core/test_image.py @@ -56,7 +56,9 @@ def test_build(self, mock_call: MagicMock): self.assertTrue(image.built) self.assertEqual(image_name, "test-challenge") - mock_call.assert_called_once_with(["docker", "build", "-t", "test-challenge", "."], cwd=build_path.absolute()) + mock_call.assert_called_once_with( + ["docker", "build", "--load", "-t", "test-challenge", "."], cwd=build_path.absolute() + ) @mock.patch("ctfcli.core.image.subprocess.call", return_value=1) def test_build_returns_none_if_failed(self, mock_call: MagicMock): @@ -68,7 +70,9 @@ def test_build_returns_none_if_failed(self, mock_call: MagicMock): self.assertFalse(image.built) self.assertIsNone(image_name) - mock_call.assert_called_once_with(["docker", "build", "-t", "test-challenge", "."], cwd=build_path.absolute()) + mock_call.assert_called_once_with( + ["docker", "build", "--load", "-t", "test-challenge", "."], cwd=build_path.absolute() + ) @mock.patch("ctfcli.core.image.subprocess.call", return_value=0) def test_push_built_image(self, mock_call: MagicMock): @@ -150,7 +154,7 @@ def test_builds_image_before_push(self, mock_call: MagicMock): mock_call.assert_has_calls( [ call( - ["docker", "build", "-t", "test-challenge", "."], + ["docker", "build", "--load", "-t", "test-challenge", "."], cwd=build_path.absolute(), ), call( @@ -224,7 +228,7 @@ def test_builds_image_before_export(self, mock_call: MagicMock): mock_call.assert_has_calls( [ call( - ["docker", "build", "-t", "test-challenge", "."], + ["docker", "build", "--load", "-t", "test-challenge", "."], cwd=build_path.absolute(), ), call(