Skip to content

Commit

Permalink
feat: add --load to docker build
Browse files Browse the repository at this point in the history
supports alternative BuildKit drivers

Signed-off-by: Tom Plant <tom@tplant.com.au>
  • Loading branch information
pl4nty committed Mar 7, 2024
1 parent 26bcec8 commit e9193d8
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
4 changes: 3 additions & 1 deletion ctfcli/core/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
12 changes: 8 additions & 4 deletions tests/core/test_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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):
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit e9193d8

Please sign in to comment.