1212import sys
1313import os
1414from pathlib import Path
15+ from packaging import version
1516
1617CURRENT_LLAMA_STACK_VERSION = "0.2.23"
1718LLAMA_STACK_VERSION = os .getenv ("LLAMA_STACK_VERSION" , CURRENT_LLAMA_STACK_VERSION )
@@ -51,6 +52,26 @@ def is_install_from_source(llama_stack_version):
5152 return "." not in llama_stack_version
5253
5354
55+ def get_entrypoint (llama_stack_version ):
56+ """Determine the appropriate ENTRYPOINT based on llama-stack version."""
57+ # If installing from source (commit SHA), use the new entrypoint
58+ if is_install_from_source (llama_stack_version ):
59+ return 'ENTRYPOINT ["llama", "stack", "run"]'
60+
61+ # Parse current LLS version and compare with threshold LLS version
62+ try :
63+ current_version = version .parse (llama_stack_version )
64+ threshold_version = version .parse ("0.2.23" )
65+
66+ if current_version < threshold_version :
67+ return 'ENTRYPOINT ["python", "-m", "llama_stack.core.server.server"]'
68+ else :
69+ return 'ENTRYPOINT ["llama", "stack", "run"]'
70+ except Exception as e :
71+ print (f"Error: Could not parse version { llama_stack_version } : { e } " )
72+ sys .exit (1 )
73+
74+
5475def check_llama_installed ():
5576 """Check if llama binary is installed and accessible."""
5677 if not shutil .which ("llama" ):
@@ -171,7 +192,7 @@ def get_dependencies():
171192 sys .exit (1 )
172193
173194
174- def generate_containerfile (dependencies , llama_stack_install ):
195+ def generate_containerfile (dependencies , llama_stack_install , entrypoint ):
175196 """Generate Containerfile from template with dependencies."""
176197 template_path = Path ("distribution/Containerfile.in" )
177198 output_path = Path ("distribution/Containerfile" )
@@ -191,6 +212,7 @@ def generate_containerfile(dependencies, llama_stack_install):
191212 containerfile_content = warning + template_content .format (
192213 dependencies = dependencies .rstrip (),
193214 llama_stack_install_source = llama_stack_install if llama_stack_install else "" ,
215+ entrypoint = entrypoint ,
194216 )
195217
196218 # Remove any blank lines that result from empty substitutions
@@ -221,8 +243,11 @@ def main():
221243 print ("Getting llama-stack install..." )
222244 llama_stack_install = get_llama_stack_install (LLAMA_STACK_VERSION )
223245
246+ print ("Getting entrypoint..." )
247+ entrypoint = get_entrypoint (LLAMA_STACK_VERSION )
248+
224249 print ("Generating Containerfile..." )
225- generate_containerfile (dependencies , llama_stack_install )
250+ generate_containerfile (dependencies , llama_stack_install , entrypoint )
226251
227252 print ("Done!" )
228253
0 commit comments