Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add bootstrap cli flag for create/inspect #600

Merged
merged 6 commits into from
Jul 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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:
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that running the docker buildx inspect --boostrap [NAME] command is necessary, when the bootstrap flag is set to True, as the command modifies the targeted builder state.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That seems reasonable

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
Loading