Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:Bentoml BentoML Buildah Backend

From Leeroopedia
Knowledge Sources
Domains Container, OCI
Last Updated 2026-02-13 15:00 GMT

Overview

Implements the Buildah container builder backend for BentoML, extending the OCIBuilder base class to build OCI images using the Buildah CLI tool.

Description

The buildah module provides the Buildah backend implementation for BentoML's container build system. It extends the OCIBuilder base class and exports the standard backend interface:

  • BUILDKIT_SUPPORT -- Set to False since Buildah does not use Docker BuildKit.
  • ENV -- Default environment variables: BUILDAH_FORMAT=oci (OCI image format v2) and DOCKER_BUILDKIT=0.
  • find_binary() -- Locates the buildah executable using shutil.which.
  • health() -- Checks if Buildah is installed and available in PATH.
  • construct_build_args() -- Builds the CLI argument list for buildah bud (build-using-dockerfile). Supports the following options:
    • add_host -- Host-to-IP mappings (dict or tuple)
    • annotation -- Image annotations (dict or tuple)
    • label -- Image labels (dict or tuple)
    • build_arg -- Build-time variables (dict or tuple)
    • creds -- Registry credentials (string or dict)
    • decryption_key -- Decryption keys (string or dict)
    • runtime_flag -- Runtime flags (string or dict)
    • secret -- Build secrets (string or dict)
    • ulimit -- Resource limits (string or dict with (soft, hard) tuples)
    • volume -- Volume mounts (string or (host, container, options) tuple)
    • Additional keyword arguments are passed through with underscores replaced by hyphens.

The parse_dict_opt helper formats dictionaries into comma-separated key=value strings for CLI options.

Usage

Use this backend when building OCI container images with Buildah, particularly in rootless or daemonless container build environments.

Code Reference

Source Location

Signature

BUILDKIT_SUPPORT = False
ENV = {"BUILDAH_FORMAT": "oci", "DOCKER_BUILDKIT": "0"}

def find_binary() -> str | None: ...
def health() -> bool: ...
def construct_build_args(
    *,
    context_path: PathType = ".",
    add_host: dict[str, str] | ArgType = None,
    annotation: dict[str, str] | ArgType = None,
    label: dict[str, str] | ArgType = None,
    build_arg: dict[str, str] | ArgType = None,
    creds: str | dict[str, str] | ArgType = None,
    decryption_key: str | dict[str, str] | ArgType = None,
    runtime_flag: str | dict[str, str] | ArgType = None,
    secret: str | dict[str, str] | ArgType = None,
    ulimit: str | dict[str, tuple[int, int]] | ArgType = None,
    volume: str | tuple[str, str, str] | None = None,
    **kwargs: t.Any,
) -> Arguments: ...

Import

from bentoml._internal.container import buildah

I/O Contract

Inputs

Name Type Required Description
context_path PathType No Build context directory (default: ".")
add_host dict or tuple No Extra host-to-IP mappings
annotation dict or tuple No Image annotations
label dict or tuple No Image labels
build_arg dict or tuple No Build-time variables
creds str or dict No Registry credentials
secret str or dict No Build secrets
volume str or tuple No Volume mount specification

Outputs

Name Type Description
Arguments Arguments Constructed CLI argument list for buildah build command
bool bool Health check result
str or None str or None Path to buildah binary (from find_binary)

Usage Examples

from bentoml._internal.container import buildah

# Check if buildah is available
if buildah.health():
    # Construct build arguments
    args = buildah.construct_build_args(
        context_path="/path/to/project",
        build_arg={"VERSION": "1.0", "ENV": "production"},
        label={"maintainer": "team@example.com"},
        tag=("myimage:latest",),
    )

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment