Skip to content

Commit

Permalink
Add bootstrap cli flag for create/inspect (#600)
Browse files Browse the repository at this point in the history
  • Loading branch information
fizzgig1888 authored Jul 28, 2024
1 parent e0d77a6 commit 682ff91
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
16 changes: 15 additions & 1 deletion python_on_whales/components/buildx/cli_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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:
Expand All @@ -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:
Expand All @@ -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]:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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"])

Expand Down

0 comments on commit 682ff91

Please sign in to comment.