feat: export distribution container build artifacts

Add a new --export-dir flag to the `llama stack build` command that
allows users to export container build artifacts to a specified
directory instead of building the container directly. This feature is
useful for:

- Building containers in different environments
- Sharing build configurations
- Customizing the build process

The exported tarball includes:
- Containerfile (Dockerfile)
- Run configuration file (if building from config)
- External provider files (if specified)
- Build script for assistance

The tarball is named with a timestamp for uniqueness: <distro-name>_<timestamp>.tar.gz

Documentation has been updated in building_distro.md to reflect this new
functionality as well as integration tests.

Signed-off-by: Sébastien Han <seb@redhat.com>
This commit is contained in:
Sébastien Han 2025-05-16 11:37:56 +02:00
parent 047303e339
commit e9bcb0e827
No known key found for this signature in database
7 changed files with 186 additions and 22 deletions

View file

@ -230,6 +230,7 @@ def run_stack_build_command(args: argparse.Namespace) -> None:
image_name=image_name,
config_path=args.config,
template_name=args.template,
export_dir=args.export_dir,
)
except (Exception, RuntimeError) as exc:
@ -343,6 +344,7 @@ def _run_stack_build_command_from_build_config(
image_name: str | None = None,
template_name: str | None = None,
config_path: str | None = None,
export_dir: str | None = None,
) -> str:
image_name = image_name or build_config.image_name
if build_config.image_type == LlamaStackImageType.CONTAINER.value:
@ -385,6 +387,7 @@ def _run_stack_build_command_from_build_config(
image_name,
template_or_config=template_name or config_path or str(build_file_path),
run_config=run_config_file,
export_dir=export_dir,
)
if return_code != 0:
raise RuntimeError(f"Failed to build image {image_name}")