Implementation:Bentoml BentoML Buildx Backend
| Knowledge Sources | |
|---|---|
| Domains | Container, OCI |
| Last Updated | 2026-02-13 15:00 GMT |
Overview
Implements the Docker Buildx container builder backend for BentoML, extending the OCIBuilder base class to build OCI images using docker buildx build with support for multi-platform builds and attestations.
Description
The buildx module provides the Docker Buildx backend implementation for BentoML's container build system. It extends the OCIBuilder base class and exports the standard backend interface:
- BUILDKIT_SUPPORT -- Set to True as Buildx uses BuildKit natively.
- BUILD_CMD -- Set to ["buildx", "build"], overriding the default build sub-command.
- health() -- Delegates to Docker's health check first, then verifies that the buildx plugin is installed by checking for "--builder string" in docker buildx --help output.
- supports_attestation() -- Checks the Buildx version (must be > 0.10.0) to determine if attestation features (provenance, SBOM) are supported.
- construct_build_args() -- Builds the CLI argument list with extensive options:
- platform -- Multi-platform build targets; warns if multiple platforms are used without --push.
- push/load -- Push to registry or load locally (mutually handled: push disables load).
- output -- Custom output configuration; local output disables both push and load.
- add_host, build_arg, build_context, label -- Standard Docker build options.
- cache_from, cache_to -- Cache import/export configuration.
- no_cache_filter -- Selective cache invalidation.
- secret, ulimit -- Build secrets and resource limits.
- attest, provenance, sbom -- Attestation options (only added if Buildx version supports them).
- Additional keyword arguments are passed through with underscores replaced by hyphens.
The module reuses ENV and find_binary from the Docker backend.
Usage
Use this backend for advanced Docker builds requiring multi-platform support, BuildKit caching strategies, or supply chain attestation features.
Code Reference
Source Location
- Repository: Bentoml_BentoML
- File: src/bentoml/_internal/container/buildx.py
- Lines: 1-148
Signature
BUILDKIT_SUPPORT = True
BUILD_CMD = ["buildx", "build"]
def health() -> bool: ...
def supports_attestation() -> bool: ...
def construct_build_args(
*,
context_path: PathType = ".",
add_host: dict[str, str] | ArgType = None,
attest: str | dict[str, str] | ArgType = None,
build_arg: dict[str, str] | ArgType = None,
build_context: dict[str, str] | ArgType = None,
cache_from: str | dict[str, str] | ArgType = None,
cache_to: str | dict[str, str] | ArgType = None,
label: dict[str, str] | ArgType = None,
load: bool = True,
no_cache_filter: str | dict[str, str] | ArgType = None,
output: str | dict[str, str] | ArgType = None,
platform: str | ArgType = None,
pull: bool = False,
provenance: str | dict[str, str] | ArgType = None,
sbom: str | dict[str, str] | ArgType = None,
push: bool = False,
secret: str | dict[str, str] | ArgType = None,
ulimit: str | dict[str, tuple[int, int]] | ArgType = None,
**kwargs: t.Any,
) -> Arguments: ...
Import
from bentoml._internal.container import buildx
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| context_path | PathType | No | Build context directory (default: ".") |
| platform | str or tuple | No | Target platform(s) for multi-platform build |
| push | bool | No | Push image to registry (default: False) |
| load | bool | No | Load image into local Docker (default: True) |
| cache_from | str or dict | No | Cache source configuration |
| cache_to | str or dict | No | Cache destination configuration |
| attest | str or dict | No | Attestation configuration (requires Buildx > 0.10.0) |
| provenance | str or dict | No | Provenance attestation config |
| sbom | str or dict | No | SBOM attestation config |
Outputs
| Name | Type | Description |
|---|---|---|
| Arguments | Arguments | Constructed CLI argument list for docker buildx build command |
| bool | bool | Health check or attestation support result |
Usage Examples
from bentoml._internal.container import buildx
# Check if docker buildx is available
if buildx.health():
# Multi-platform build with push
args = buildx.construct_build_args(
context_path="/path/to/project",
platform=("linux/amd64", "linux/arm64"),
push=True,
build_arg={"VERSION": "1.0"},
cache_from={"type": "registry", "ref": "myrepo/cache"},
tag=("myimage:latest",),
)
# Check attestation support
if buildx.supports_attestation():
args = buildx.construct_build_args(
context_path=".",
provenance={"mode": "max"},
sbom=True,
)