tmp dockerfile_only flag

This commit is contained in:
Xi Yan 2025-01-14 13:59:20 -08:00
parent 91907b714e
commit 4747c844a2
3 changed files with 35 additions and 6 deletions

View file

@ -81,6 +81,14 @@ class StackBuild(Subcommand):
default="conda",
)
self.parser.add_argument(
"--dockerfile-only",
type=bool,
default=False,
action=argparse.BooleanOptionalAction,
help="Whether to generate a Dockerfile only (only valid when image-type is docker)",
)
def _run_stack_build_command(self, args: argparse.Namespace) -> None:
import textwrap
@ -92,6 +100,12 @@ class StackBuild(Subcommand):
from llama_stack.distribution.distribution import get_provider_registry
if args.dockerfile_only and args.image_type != "docker":
self.parser.error(
"dockerfile-only flag is only valid when image-type is docker"
)
return
if args.list_templates:
self._run_template_list_cmd(args)
return
@ -107,7 +121,9 @@ class StackBuild(Subcommand):
f"Please specify a image-type (docker | conda | venv) for {args.template}"
)
self._run_stack_build_command_from_build_config(
build_config, template_name=args.template
build_config,
template_name=args.template,
dockerfile_only=args.dockerfile_only,
)
return
@ -178,7 +194,9 @@ class StackBuild(Subcommand):
build_config = BuildConfig(
name=name, image_type=image_type, distribution_spec=distribution_spec
)
self._run_stack_build_command_from_build_config(build_config)
self._run_stack_build_command_from_build_config(
build_config, dockerfile_only=args.dockerfile_only
)
return
with open(args.config, "r") as f:
@ -187,7 +205,9 @@ class StackBuild(Subcommand):
except Exception as e:
self.parser.error(f"Could not parse config file {args.config}: {e}")
return
self._run_stack_build_command_from_build_config(build_config)
self._run_stack_build_command_from_build_config(
build_config, dockerfile_only=args.dockerfile_only
)
def _generate_run_config(self, build_config: BuildConfig, build_dir: Path) -> None:
"""
@ -261,7 +281,10 @@ class StackBuild(Subcommand):
)
def _run_stack_build_command_from_build_config(
self, build_config: BuildConfig, template_name: Optional[str] = None
self,
build_config: BuildConfig,
template_name: Optional[str] = None,
dockerfile_only: bool = False,
) -> None:
import json
import os
@ -281,7 +304,7 @@ class StackBuild(Subcommand):
to_write = json.loads(build_config.model_dump_json())
f.write(yaml.dump(to_write, sort_keys=False))
return_code = build_image(build_config, build_file_path)
return_code = build_image(build_config, build_file_path, dockerfile_only)
if return_code != 0:
return