Skip to content

Commit 67fc897

Browse files
feat: allow for dynamic server start command and custom run.yaml
this commit changes the server start command to be dynamically generated based on Llama Stack version it allows users to pass a custom run.yaml if they so choose will keeping the official run.yaml we ship with the distro image as a default Signed-off-by: Nathan Weinberg <nweinber@redhat.com>
1 parent 8c752da commit 67fc897

File tree

3 files changed

+31
-4
lines changed

3 files changed

+31
-4
lines changed

distribution/Containerfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,4 +59,5 @@ RUN pip install --no-deps sentence-transformers
5959
RUN pip install --no-cache llama-stack==0.2.23
6060
RUN mkdir -p ${HOME}/.llama ${HOME}/.cache
6161
COPY distribution/run.yaml ${APP_ROOT}/run.yaml
62-
ENTRYPOINT ["llama", "stack", "run", "/opt/app-root/run.yaml"]
62+
ENTRYPOINT ["llama", "stack", "run"]
63+
CMD [ ${APP_ROOT}/run.yaml ]

distribution/Containerfile.in

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@ RUN pip install --no-cache llama-stack==0.2.23
88
RUN mkdir -p ${{HOME}}/.llama ${{HOME}}/.cache
99
COPY distribution/run.yaml ${{APP_ROOT}}/run.yaml
1010

11-
ENTRYPOINT ["llama", "stack", "run", "/opt/app-root/run.yaml"]
11+
{entrypoint}
12+
CMD [ ${{APP_ROOT}}/run.yaml ]

distribution/build.py

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import sys
1313
import os
1414
from pathlib import Path
15+
from packaging import version
1516

1617
CURRENT_LLAMA_STACK_VERSION = "0.2.23"
1718
LLAMA_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+
5475
def 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

Comments
 (0)