From cff40a7cb77ed211593a46b1f37956091724458c Mon Sep 17 00:00:00 2001 From: Eric Huang Date: Mon, 20 Oct 2025 16:01:42 -0700 Subject: [PATCH] chore: migrate stack build # What does this PR do? ## Test Plan --- llama_stack/core/server/server.py | 1 + scripts/docker.sh | 59 +++++++++++++++++++++++-------- scripts/integration-tests.sh | 26 ++++++++------ 3 files changed, 60 insertions(+), 26 deletions(-) diff --git a/llama_stack/core/server/server.py b/llama_stack/core/server/server.py index db7584b01..aa2c50587 100644 --- a/llama_stack/core/server/server.py +++ b/llama_stack/core/server/server.py @@ -31,6 +31,7 @@ from fastapi.responses import JSONResponse, StreamingResponse from openai import BadRequestError from pydantic import BaseModel, ValidationError +# test from llama_stack.apis.common.errors import ConflictError, ResourceNotFoundError from llama_stack.apis.common.responses import PaginatedResponse from llama_stack.core.access_control.access_control import AccessDeniedError diff --git a/scripts/docker.sh b/scripts/docker.sh index 7a5c3e6e0..a0690c8a9 100755 --- a/scripts/docker.sh +++ b/scripts/docker.sh @@ -156,6 +156,16 @@ DISTRO=$(echo "$DISTRO" | sed 's/^docker://') CONTAINER_NAME="llama-stack-test-$DISTRO" +should_copy_source() { + if [[ "$USE_COPY_NOT_MOUNT" == "true" ]]; then + return 0 + fi + if [[ "${CI:-false}" == "true" ]] || [[ "${GITHUB_ACTIONS:-false}" == "true" ]]; then + return 0 + fi + return 1 +} + # Function to check if container is running is_container_running() { docker ps --filter "name=^${CONTAINER_NAME}$" --format '{{.Names}}' | grep -q "^${CONTAINER_NAME}$" @@ -183,20 +193,29 @@ stop_container() { build_image() { echo "=== Building Docker Image for distribution: $DISTRO ===" # Get the repo root (parent of scripts directory) - SCRIPT_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd) - REPO_ROOT=$(cd "$SCRIPT_DIR/.." && pwd) + local script_dir + script_dir=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd) + local repo_root + repo_root=$(cd "$script_dir/.." && pwd) - # Determine whether to copy or mount source - # Copy in CI or if explicitly requested, otherwise mount for live development - BUILD_ENV="LLAMA_STACK_DIR=$REPO_ROOT" - if [[ "$USE_COPY_NOT_MOUNT" == "true" ]] || [[ "${CI:-false}" == "true" ]] || [[ "${GITHUB_ACTIONS:-false}" == "true" ]]; then - echo "Copying source into image (USE_COPY_NOT_MOUNT=true, CI=${CI:-false}, GITHUB_ACTIONS=${GITHUB_ACTIONS:-false})" - BUILD_ENV="USE_COPY_NOT_MOUNT=true $BUILD_ENV" - else - echo "Will mount source for live development" + local containerfile="$repo_root/containers/Containerfile" + if [[ ! -f "$containerfile" ]]; then + echo "❌ Containerfile not found at $containerfile" + exit 1 fi - if ! eval "$BUILD_ENV llama stack build --distro '$DISTRO' --image-type container"; then + local build_cmd=( + docker + build + "$repo_root" + -f "$containerfile" + --tag "localhost/distribution-$DISTRO:dev" + --build-arg "DISTRO_NAME=$DISTRO" + --build-arg "INSTALL_MODE=editable" + --build-arg "LLAMA_STACK_DIR=/workspace" + ) + + if ! "${build_cmd[@]}"; then echo "❌ Failed to build Docker image" exit 1 fi @@ -224,7 +243,7 @@ start_container() { # Check if image exists (with or without localhost/ prefix) if ! docker images --format "{{.Repository}}:{{.Tag}}" | grep -q "distribution-$DISTRO:dev$"; then echo "❌ Error: Image distribution-$DISTRO:dev does not exist" - echo "Either build it first without --no-rebuild, or run: llama stack build --distro $DISTRO --image-type container" + echo "Either build it first without --no-rebuild, or run: docker build . -f containers/Containerfile --build-arg DISTRO_NAME=$DISTRO --tag localhost/distribution-$DISTRO:dev" exit 1 fi echo "✅ Found existing image for distribution-$DISTRO:dev" @@ -236,8 +255,10 @@ start_container() { echo "=== Starting Docker Container ===" # Get the repo root for volume mount - SCRIPT_DIR=$(cd "$(dirname "${BASH_SOURCE[0]:-$0}")" && pwd) - REPO_ROOT=$(cd "$SCRIPT_DIR/.." && pwd) + local script_dir + script_dir=$(cd "$(dirname "${BASH_SOURCE[0]:-$0}")" && pwd) + local repo_root + repo_root=$(cd "$script_dir/.." && pwd) # Determine the actual image name (may have localhost/ prefix) IMAGE_NAME=$(docker images --format "{{.Repository}}:{{.Tag}}" | grep "distribution-$DISTRO:dev$" | head -1) @@ -279,10 +300,18 @@ start_container() { NETWORK_MODE="--network host" fi + local source_mount="" + if should_copy_source; then + echo "Source baked into image (no volume mount)" + else + source_mount="-v \"$repo_root\":/workspace" + echo "Mounting $repo_root into /workspace" + fi + docker run -d $NETWORK_MODE --name "$CONTAINER_NAME" \ -p $PORT:$PORT \ $DOCKER_ENV_VARS \ - -v "$REPO_ROOT":/app/llama-stack-source \ + $source_mount \ "$IMAGE_NAME" \ --port $PORT diff --git a/scripts/integration-tests.sh b/scripts/integration-tests.sh index e19a5cc55..daf6ccd1b 100755 --- a/scripts/integration-tests.sh +++ b/scripts/integration-tests.sh @@ -252,19 +252,24 @@ if [[ "$STACK_CONFIG" == *"docker:"* && "$COLLECT_ONLY" == false ]]; then export LLAMA_STACK_PORT=8321 echo "=== Building Docker Image for distribution: $DISTRO ===" - # Set LLAMA_STACK_DIR to repo root - # USE_COPY_NOT_MOUNT copies files into image (for CI), otherwise mounts for live development - BUILD_ENV="LLAMA_STACK_DIR=$ROOT_DIR" - if [[ "${CI:-false}" == "true" ]] || [[ "${GITHUB_ACTIONS:-false}" == "true" ]]; then - echo "CI detected (CI=$CI, GITHUB_ACTIONS=$GITHUB_ACTIONS): copying source into image" - BUILD_ENV="USE_COPY_NOT_MOUNT=true $BUILD_ENV" - else - echo "Local mode: will mount source for live development" + containerfile="$ROOT_DIR/containers/Containerfile" + if [[ ! -f "$containerfile" ]]; then + echo "❌ Containerfile not found at $containerfile" + exit 1 fi - eval "$BUILD_ENV llama stack build --distro '$DISTRO' --image-type container" + build_cmd=( + docker + build + "$ROOT_DIR" + -f "$containerfile" + --tag "localhost/distribution-$DISTRO:dev" + --build-arg "DISTRO_NAME=$DISTRO" + --build-arg "INSTALL_MODE=editable" + --build-arg "LLAMA_STACK_DIR=/workspace" + ) - if [ $? -ne 0 ]; then + if ! "${build_cmd[@]}"; then echo "❌ Failed to build Docker image" exit 1 fi @@ -304,7 +309,6 @@ if [[ "$STACK_CONFIG" == *"docker:"* && "$COLLECT_ONLY" == false ]]; then docker run -d --network host --name "$container_name" \ -p $LLAMA_STACK_PORT:$LLAMA_STACK_PORT \ $DOCKER_ENV_VARS \ - -v $ROOT_DIR:/app/llama-stack-source \ "$IMAGE_NAME" \ --port $LLAMA_STACK_PORT