-
Notifications
You must be signed in to change notification settings - Fork 91
LCORE-1859: Fix llama-stack startup as non-root user #1859
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,25 @@ | ||||||||||||||||||||||||||||||
| #!/bin/bash | ||||||||||||||||||||||||||||||
| # Entrypoint for the library-mode lightspeed-stack container. | ||||||||||||||||||||||||||||||
| # Seeds the RAG kvstore into a writable location, then starts lightspeed-stack. | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| set -e | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| # Seed the RAG kvstore into the writable storage volume. | ||||||||||||||||||||||||||||||
| # | ||||||||||||||||||||||||||||||
| # The seed db is mounted read-only from the host (owned by the host user), but | ||||||||||||||||||||||||||||||
| # the embedded llama-stack runs as a non-root user and must write to this | ||||||||||||||||||||||||||||||
| # kvstore at startup (the resource registry shares it). Copying it into the | ||||||||||||||||||||||||||||||
| # storage tree makes the runtime db owned by the container user, so it is | ||||||||||||||||||||||||||||||
| # writable regardless of the host UID. See run.yaml -> storage.backends.kv_default. | ||||||||||||||||||||||||||||||
| RAG_SEED_DIR="${RAG_SEED_DIR:-/opt/app-root/rag-seed}" | ||||||||||||||||||||||||||||||
| STORAGE_RAG_DIR="${STORAGE_RAG_DIR:-/opt/app-root/src/.llama/storage/rag}" | ||||||||||||||||||||||||||||||
| if [ -d "$RAG_SEED_DIR" ]; then | ||||||||||||||||||||||||||||||
| echo "Seeding RAG kvstore from $RAG_SEED_DIR into $STORAGE_RAG_DIR..." | ||||||||||||||||||||||||||||||
| mkdir -p "$STORAGE_RAG_DIR" | ||||||||||||||||||||||||||||||
| cp -f "$RAG_SEED_DIR"/*.db "$STORAGE_RAG_DIR"/ | ||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||
|
Comment on lines
+16
to
+20
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧹 Nitpick | 🔵 Trivial | ⚡ Quick win Improve error handling for missing seed files. If 🛡️ Proposed fix to add validation if [ -d "$RAG_SEED_DIR" ]; then
echo "Seeding RAG kvstore from $RAG_SEED_DIR into $STORAGE_RAG_DIR..."
mkdir -p "$STORAGE_RAG_DIR"
+ if ! compgen -G "$RAG_SEED_DIR/*.db" > /dev/null; then
+ echo "ERROR: No .db files found in $RAG_SEED_DIR"
+ exit 1
+ fi
cp -f "$RAG_SEED_DIR"/*.db "$STORAGE_RAG_DIR"/
fi📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| # Use the venv interpreter explicitly: overriding the image entrypoint changes | ||||||||||||||||||||||||||||||
| # PATH ordering, so a bare `python3.12` may resolve to the system interpreter | ||||||||||||||||||||||||||||||
| # (without the app's dependencies) instead of the venv at /app-root/.venv. | ||||||||||||||||||||||||||||||
| exec /app-root/.venv/bin/python3.12 src/lightspeed_stack.py "$@" | ||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -8,6 +8,21 @@ INPUT_CONFIG="${LLAMA_STACK_CONFIG:-/opt/app-root/run.yaml}" | |||||||||||||||||||||||||||||
| ENRICHED_CONFIG="/tmp/enriched-run.yaml" | ||||||||||||||||||||||||||||||
| LIGHTSPEED_CONFIG="${LIGHTSPEED_CONFIG:-/opt/app-root/lightspeed-stack.yaml}" | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| # Seed the RAG kvstore into the writable storage volume. | ||||||||||||||||||||||||||||||
| # | ||||||||||||||||||||||||||||||
| # The seed db is mounted read-only from the host (owned by the host user), but | ||||||||||||||||||||||||||||||
| # llama-stack runs as a non-root user and must write to this kvstore at startup | ||||||||||||||||||||||||||||||
| # (the resource registry shares it). Copying it into the storage volume makes | ||||||||||||||||||||||||||||||
| # the runtime db owned by the container user, so it is writable regardless of | ||||||||||||||||||||||||||||||
| # the host UID. See run.yaml -> storage.backends.kv_default. | ||||||||||||||||||||||||||||||
| RAG_SEED_DIR="${RAG_SEED_DIR:-/opt/app-root/rag-seed}" | ||||||||||||||||||||||||||||||
| STORAGE_RAG_DIR="${STORAGE_RAG_DIR:-/opt/app-root/src/.llama/storage/rag}" | ||||||||||||||||||||||||||||||
| if [ -d "$RAG_SEED_DIR" ]; then | ||||||||||||||||||||||||||||||
| echo "Seeding RAG kvstore from $RAG_SEED_DIR into $STORAGE_RAG_DIR..." | ||||||||||||||||||||||||||||||
| mkdir -p "$STORAGE_RAG_DIR" | ||||||||||||||||||||||||||||||
| cp -f "$RAG_SEED_DIR"/*.db "$STORAGE_RAG_DIR"/ | ||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||
|
Comment on lines
+18
to
+24
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧹 Nitpick | 🔵 Trivial | ⚡ Quick win Consider extracting duplicated seeding logic. The RAG seeding block (lines 18-24) is identical to the logic in ♻️ Example: Extract to a shared functionCreate a shared script (e.g., #!/bin/bash
# Shared function to seed RAG kvstore
seed_rag_kvstore() {
local RAG_SEED_DIR="${RAG_SEED_DIR:-/opt/app-root/rag-seed}"
local STORAGE_RAG_DIR="${STORAGE_RAG_DIR:-/opt/app-root/src/.llama/storage/rag}"
if [ -d "$RAG_SEED_DIR" ]; then
echo "Seeding RAG kvstore from $RAG_SEED_DIR into $STORAGE_RAG_DIR..."
mkdir -p "$STORAGE_RAG_DIR"
if ! compgen -G "$RAG_SEED_DIR/*.db" > /dev/null; then
echo "ERROR: No .db files found in $RAG_SEED_DIR"
exit 1
fi
cp -f "$RAG_SEED_DIR"/*.db "$STORAGE_RAG_DIR"/
fi
}Then source and call it in both entrypoint scripts: source /app-root/seed-rag-kvstore.sh
seed_rag_kvstore🤖 Prompt for AI Agents
Comment on lines
+20
to
+24
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧹 Nitpick | 🔵 Trivial | ⚡ Quick win Improve error handling for missing seed files. If 🛡️ Proposed fix to add validation if [ -d "$RAG_SEED_DIR" ]; then
echo "Seeding RAG kvstore from $RAG_SEED_DIR into $STORAGE_RAG_DIR..."
mkdir -p "$STORAGE_RAG_DIR"
+ if ! compgen -G "$RAG_SEED_DIR/*.db" > /dev/null; then
+ echo "ERROR: No .db files found in $RAG_SEED_DIR"
+ exit 1
+ fi
cp -f "$RAG_SEED_DIR"/*.db "$STORAGE_RAG_DIR"/
fi📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| # Enrich config if lightspeed config exists | ||||||||||||||||||||||||||||||
| if [ -f "$LIGHTSPEED_CONFIG" ]; then | ||||||||||||||||||||||||||||||
| echo "Enriching llama-stack config..." | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧹 Nitpick | 🔵 Trivial | 💤 Low value
Inconsistent SELinux label casing between mounts.
The RAG seed mount uses
:ro,Z(private label) while the entrypoint script mount uses:ro,z(shared label). For consistency and clarity, consider using the same casing unless the different labeling is intentional.🤖 Prompt for AI Agents