From 682ff914a0a0461dc7cb1e63a9d68ee3fa30e09b Mon Sep 17 00:00:00 2001 From: fizzgig1888 <55842001+fizzgig1888@users.noreply.github.com> Date: Sun, 28 Jul 2024 19:43:05 +0200 Subject: [PATCH] Add bootstrap cli flag for create/inspect (#600) --- .../components/buildx/cli_wrapper.py | 16 +++++++++++++++- .../buildx/test_buildx_cli_wrapper.py | 17 +++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/python_on_whales/components/buildx/cli_wrapper.py b/python_on_whales/components/buildx/cli_wrapper.py index be837240..4ac4e492 100644 --- a/python_on_whales/components/buildx/cli_wrapper.py +++ b/python_on_whales/components/buildx/cli_wrapper.py @@ -454,6 +454,7 @@ def _method_to_get_image(self, builder: Optional[str]) -> GetImageMethod: def create( self, context_or_endpoint: Optional[str] = None, + bootstrap: bool = False, buildkitd_flags: Optional[str] = None, config: Optional[ValidPath] = None, platforms: Optional[List[str]] = None, @@ -466,6 +467,7 @@ def create( Parameters: context_or_endpoint: + bootstrap: Boot builder after creation buildkitd_flags: Flags for buildkitd daemon config: BuildKit config file platforms: Comma-separated list of platforms of the form OS/architecture/variant. Ex: @@ -481,6 +483,7 @@ def create( """ full_cmd = self.docker_cmd + ["buildx", "create"] + full_cmd.add_flag("--bootstrap", bootstrap) full_cmd.add_simple_arg("--buildkitd-flags", buildkitd_flags) full_cmd.add_simple_arg("--config", config) if platforms is not None: @@ -501,16 +504,27 @@ def disk_usage(self): """Not yet implemented""" raise NotImplementedError - def inspect(self, x: Optional[str] = None) -> Builder: + def inspect( + self, + x: Optional[str] = None, + bootstrap: bool = False, + ) -> Builder: """Returns a builder instance from the name. Parameters: x: If `None` (the default), returns the current builder. If a string is provided, the builder that has this name is returned. + bootstrap: If set to True, ensure builder has booted before inspecting. # Returns A `python_on_whales.Builder` object. """ + if bootstrap: + full_cmd = self.docker_cmd + ["buildx", "inspect"] + if x is not None: + full_cmd.append(x) + full_cmd.add_flag("--bootstrap", bootstrap) + run(full_cmd) return Builder(self.client_config, x, is_immutable_id=False) def list(self) -> List[Builder]: diff --git a/tests/python_on_whales/components/buildx/test_buildx_cli_wrapper.py b/tests/python_on_whales/components/buildx/test_buildx_cli_wrapper.py index d5ae9bfc..3b945135 100644 --- a/tests/python_on_whales/components/buildx/test_buildx_cli_wrapper.py +++ b/tests/python_on_whales/components/buildx/test_buildx_cli_wrapper.py @@ -366,6 +366,15 @@ def test_inspect(): assert docker.buildx.inspect() == my_builder +def test_buildx_inspect_bootstrap(): + my_builder = docker.buildx.create() + with my_builder: + docker.buildx.inspect(my_builder.name, bootstrap=True) + assert my_builder.status == "running" + # Must contain at least the host native platform + assert my_builder.platforms + + def test_builder_name(): my_builder = docker.buildx.create(name="some_builder") with my_builder: @@ -475,6 +484,14 @@ def test_buildx_create_remove(): docker.buildx.remove(builder) +def test_buildx_create_bootstrap(): + my_builder = docker.buildx.create(bootstrap=True) + with my_builder: + assert my_builder.status == "running" + # Must contain at least the host native platform + assert my_builder.platforms + + def test_buildx_create_remove_with_platforms(): builder = docker.buildx.create(platforms=["linux/amd64", "linux/arm64"])