Skip to content

Commit 6813227

Browse files
authored
Make run yaml optional so dockers can start with just --env (#492)
When running with dockers, the idea is that users be able to work purely with the `llama stack` CLI. They should not need to know about the existence of any YAMLs unless they need to. This PR enables it. The docker command now doesn't need to volume mount a yaml and can simply be: ```bash docker run -v ~/.llama/:/root/.llama \ --env A=a --env B=b ``` ## Test Plan Check with conda first (no regressions): ```bash LLAMA_STACK_DIR=. llama stack build --template ollama llama stack run ollama --port 5001 # server starts up correctly ``` Check with docker ```bash # build the docker LLAMA_STACK_DIR=. llama stack build --template ollama --image-type docker export INFERENCE_MODEL="meta-llama/Llama-3.2-3B-Instruct" docker run -it -p 5001:5001 \ -v ~/.llama:/root/.llama \ -v $PWD:/app/llama-stack-source \ localhost/distribution-ollama:dev \ --port 5001 \ --env INFERENCE_MODEL=$INFERENCE_MODEL \ --env OLLAMA_URL=http://host.docker.internal:11434 ``` Note that volume mounting to `/app/llama-stack-source` is only needed because we built the docker with uncommitted source code.
1 parent 1d8d059 commit 6813227

3 files changed

Lines changed: 44 additions & 8 deletions

File tree

llama_stack/cli/stack/run.py

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,12 @@
55
# the root directory of this source tree.
66

77
import argparse
8+
from pathlib import Path
89

910
from llama_stack.cli.subcommand import Subcommand
1011

12+
REPO_ROOT = Path(__file__).parent.parent.parent.parent
13+
1114

1215
class StackRun(Subcommand):
1316
def __init__(self, subparsers: argparse._SubParsersAction):
@@ -48,8 +51,6 @@ def _add_arguments(self):
4851
)
4952

5053
def _run_stack_run_cmd(self, args: argparse.Namespace) -> None:
51-
from pathlib import Path
52-
5354
import pkg_resources
5455
import yaml
5556

@@ -66,19 +67,27 @@ def _run_stack_run_cmd(self, args: argparse.Namespace) -> None:
6667
return
6768

6869
config_file = Path(args.config)
69-
if not config_file.exists() and not args.config.endswith(".yaml"):
70+
has_yaml_suffix = args.config.endswith(".yaml")
71+
72+
if not config_file.exists() and not has_yaml_suffix:
73+
# check if this is a template
74+
config_file = (
75+
Path(REPO_ROOT) / "llama_stack" / "templates" / args.config / "run.yaml"
76+
)
77+
78+
if not config_file.exists() and not has_yaml_suffix:
7079
# check if it's a build config saved to conda dir
7180
config_file = Path(
7281
BUILDS_BASE_DIR / ImageType.conda.value / f"{args.config}-run.yaml"
7382
)
7483

75-
if not config_file.exists() and not args.config.endswith(".yaml"):
84+
if not config_file.exists() and not has_yaml_suffix:
7685
# check if it's a build config saved to docker dir
7786
config_file = Path(
7887
BUILDS_BASE_DIR / ImageType.docker.value / f"{args.config}-run.yaml"
7988
)
8089

81-
if not config_file.exists() and not args.config.endswith(".yaml"):
90+
if not config_file.exists() and not has_yaml_suffix:
8291
# check if it's a build config saved to ~/.llama dir
8392
config_file = Path(
8493
DISTRIBS_BASE_DIR
@@ -92,6 +101,7 @@ def _run_stack_run_cmd(self, args: argparse.Namespace) -> None:
92101
)
93102
return
94103

104+
print(f"Using config file: {config_file}")
95105
config_dict = yaml.safe_load(config_file.read_text())
96106
config = parse_and_maybe_upgrade_config(config_dict)
97107

llama_stack/distribution/build_container.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ add_to_docker <<EOF
122122
# This would be good in production but for debugging flexibility lets not add it right now
123123
# We need a more solid production ready entrypoint.sh anyway
124124
#
125-
ENTRYPOINT ["python", "-m", "llama_stack.distribution.server.server"]
125+
ENTRYPOINT ["python", "-m", "llama_stack.distribution.server.server", "--template", "$build_name"]
126126
127127
EOF
128128

llama_stack/distribution/server/server.py

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import warnings
1717

1818
from contextlib import asynccontextmanager
19+
from pathlib import Path
1920
from ssl import SSLError
2021
from typing import Any, Dict, Optional
2122

@@ -49,6 +50,9 @@
4950
from .endpoints import get_all_api_endpoints
5051

5152

53+
REPO_ROOT = Path(__file__).parent.parent.parent.parent
54+
55+
5256
def warn_with_traceback(message, category, filename, lineno, file=None, line=None):
5357
log = file if hasattr(file, "write") else sys.stderr
5458
traceback.print_stack(file=log)
@@ -279,9 +283,12 @@ def main():
279283
parser = argparse.ArgumentParser(description="Start the LlamaStack server.")
280284
parser.add_argument(
281285
"--yaml-config",
282-
default="llamastack-run.yaml",
283286
help="Path to YAML configuration file",
284287
)
288+
parser.add_argument(
289+
"--template",
290+
help="One of the template names in llama_stack/templates (e.g., tgi, fireworks, remote-vllm, etc.)",
291+
)
285292
parser.add_argument("--port", type=int, default=5000, help="Port to listen on")
286293
parser.add_argument(
287294
"--disable-ipv6", action="store_true", help="Whether to disable IPv6 support"
@@ -303,10 +310,29 @@ def main():
303310
print(f"Error: {str(e)}")
304311
sys.exit(1)
305312

306-
with open(args.yaml_config, "r") as fp:
313+
if args.yaml_config:
314+
# if the user provided a config file, use it, even if template was specified
315+
config_file = Path(args.yaml_config)
316+
if not config_file.exists():
317+
raise ValueError(f"Config file {config_file} does not exist")
318+
print(f"Using config file: {config_file}")
319+
elif args.template:
320+
config_file = (
321+
Path(REPO_ROOT) / "llama_stack" / "templates" / args.template / "run.yaml"
322+
)
323+
if not config_file.exists():
324+
raise ValueError(f"Template {args.template} does not exist")
325+
print(f"Using template {args.template} config file: {config_file}")
326+
else:
327+
raise ValueError("Either --yaml-config or --template must be provided")
328+
329+
with open(config_file, "r") as fp:
307330
config = replace_env_vars(yaml.safe_load(fp))
308331
config = StackRunConfig(**config)
309332

333+
print("Run configuration:")
334+
print(yaml.dump(config.model_dump(), indent=2))
335+
310336
app = FastAPI()
311337

312338
try:

0 commit comments

Comments
 (0)