55# This source code is licensed under the terms described in the LICENSE file in
66# the root directory of this source tree.
77
8- # Usage: ./distribution/build.py
8+ # Usage: ./distribution/build.py [--standalone] [--unified]
9+ # Or set STANDALONE=true or UNIFIED=true environment variables
910
11+ import os
1012import shutil
1113import subprocess
1214import sys
15+ import argparse
1316from pathlib import Path
1417
1518BASE_REQUIREMENTS = [
@@ -57,9 +60,10 @@ def check_llama_stack_version():
5760 print ("Continuing without version validation..." )
5861
5962
60- def get_dependencies ():
63+ def get_dependencies (standalone = False ):
6164 """Execute the llama stack build command and capture dependencies."""
62- cmd = "llama stack build --config distribution/build.yaml --print-deps-only"
65+ config_file = "distribution/build-standalone.yaml" if standalone else "distribution/build.yaml"
66+ cmd = f"llama stack build --config { config_file } --print-deps-only"
6367 try :
6468 result = subprocess .run (
6569 cmd , shell = True , capture_output = True , text = True , check = True
@@ -112,7 +116,7 @@ def get_dependencies():
112116 sys .exit (1 )
113117
114118
115- def generate_containerfile (dependencies ):
119+ def generate_containerfile (dependencies , standalone = False , unified = False ):
116120 """Generate Containerfile from template with dependencies."""
117121 template_path = Path ("distribution/Containerfile.in" )
118122 output_path = Path ("distribution/Containerfile" )
@@ -126,7 +130,13 @@ def generate_containerfile(dependencies):
126130 template_content = f .read ()
127131
128132 # Add warning message at the top
129- warning = "# WARNING: This file is auto-generated. Do not modify it manually.\n # Generated by: distribution/build.py\n \n "
133+ if unified :
134+ mode = "unified"
135+ elif standalone :
136+ mode = "standalone"
137+ else :
138+ mode = "full"
139+ warning = f"# WARNING: This file is auto-generated. Do not modify it manually.\n # Generated by: distribution/build.py --{ mode } \n \n "
130140
131141 # Process template using string formatting
132142 containerfile_content = warning + template_content .format (
@@ -141,19 +151,63 @@ def generate_containerfile(dependencies):
141151
142152
143153def main ():
154+ parser = argparse .ArgumentParser (
155+ description = "Build Llama Stack distribution" ,
156+ epilog = """
157+ Examples:
158+ %(prog)s # Build full version (default)
159+ %(prog)s --standalone # Build standalone version (no Kubernetes deps)
160+ %(prog)s --unified # Build unified version (supports both modes)
161+ STANDALONE=true %(prog)s # Build standalone via environment variable
162+ UNIFIED=true %(prog)s # Build unified via environment variable
163+ """ ,
164+ formatter_class = argparse .RawDescriptionHelpFormatter
165+ )
166+ parser .add_argument ("--standalone" , action = "store_true" ,
167+ help = "Build standalone version without Kubernetes dependencies" )
168+ parser .add_argument ("--unified" , action = "store_true" ,
169+ help = "Build unified version that supports both modes via environment variables" )
170+ args = parser .parse_args ()
171+
172+ # Check environment variable as fallback
173+ standalone = args .standalone or os .getenv ("STANDALONE" , "false" ).lower () in ("true" , "1" , "yes" )
174+ unified = args .unified or os .getenv ("UNIFIED" , "false" ).lower () in ("true" , "1" , "yes" )
175+
176+ if unified :
177+ mode = "unified"
178+ print ("Building unified version (supports both full and standalone modes)..." )
179+ else :
180+ mode = "standalone" if standalone else "full"
181+ print (f"Building { mode } version..." )
182+
144183 print ("Checking llama installation..." )
145184 check_llama_installed ()
146185
147186 print ("Checking llama-stack version..." )
148187 check_llama_stack_version ()
149188
150189 print ("Getting dependencies..." )
151- dependencies = get_dependencies ()
190+ dependencies = get_dependencies (standalone )
152191
153192 print ("Generating Containerfile..." )
154- generate_containerfile (dependencies )
193+ generate_containerfile (dependencies , standalone , unified )
155194
156195 print ("Done!" )
196+ print (f"\n To build the Docker image:" )
197+ if unified :
198+ print (" docker build -f distribution/Containerfile -t llama-stack-unified ." )
199+ print ("\n To run in standalone mode:" )
200+ print (" docker run -e STANDALONE=true -e VLLM_URL=http://host.docker.internal:8000/v1 -e INFERENCE_MODEL=your-model -p 8321:8321 llama-stack-unified" )
201+ print ("\n To run in full mode (requires Kubernetes):" )
202+ print (" docker run -p 8321:8321 llama-stack-unified" )
203+ elif standalone :
204+ print (" docker build -f distribution/Containerfile -t llama-stack-standalone ." )
205+ print ("\n To run in standalone mode:" )
206+ print (" docker run -e VLLM_URL=http://host.docker.internal:8000/v1 -e INFERENCE_MODEL=your-model -p 8321:8321 llama-stack-standalone" )
207+ else :
208+ print (" docker build -f distribution/Containerfile -t llama-stack-full ." )
209+ print ("\n To run with full features (requires Kubernetes):" )
210+ print (" docker run -p 8321:8321 llama-stack-full" )
157211
158212
159213if __name__ == "__main__" :
0 commit comments