mirror of
https://github.com/meta-llama/llama-stack.git
synced 2025-12-06 18:40:57 +00:00
chore: migrate stack build
# What does this PR do? ## Test Plan
This commit is contained in:
parent
ffeb86385c
commit
8e3b309e5f
2 changed files with 59 additions and 26 deletions
|
|
@ -156,6 +156,16 @@ DISTRO=$(echo "$DISTRO" | sed 's/^docker://')
|
||||||
|
|
||||||
CONTAINER_NAME="llama-stack-test-$DISTRO"
|
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
|
# Function to check if container is running
|
||||||
is_container_running() {
|
is_container_running() {
|
||||||
docker ps --filter "name=^${CONTAINER_NAME}$" --format '{{.Names}}' | grep -q "^${CONTAINER_NAME}$"
|
docker ps --filter "name=^${CONTAINER_NAME}$" --format '{{.Names}}' | grep -q "^${CONTAINER_NAME}$"
|
||||||
|
|
@ -183,20 +193,29 @@ stop_container() {
|
||||||
build_image() {
|
build_image() {
|
||||||
echo "=== Building Docker Image for distribution: $DISTRO ==="
|
echo "=== Building Docker Image for distribution: $DISTRO ==="
|
||||||
# Get the repo root (parent of scripts directory)
|
# Get the repo root (parent of scripts directory)
|
||||||
SCRIPT_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
|
local script_dir
|
||||||
REPO_ROOT=$(cd "$SCRIPT_DIR/.." && pwd)
|
script_dir=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
|
||||||
|
local repo_root
|
||||||
|
repo_root=$(cd "$script_dir/.." && pwd)
|
||||||
|
|
||||||
# Determine whether to copy or mount source
|
local containerfile="$repo_root/containers/Containerfile"
|
||||||
# Copy in CI or if explicitly requested, otherwise mount for live development
|
if [[ ! -f "$containerfile" ]]; then
|
||||||
BUILD_ENV="LLAMA_STACK_DIR=$REPO_ROOT"
|
echo "❌ Containerfile not found at $containerfile"
|
||||||
if [[ "$USE_COPY_NOT_MOUNT" == "true" ]] || [[ "${CI:-false}" == "true" ]] || [[ "${GITHUB_ACTIONS:-false}" == "true" ]]; then
|
exit 1
|
||||||
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"
|
|
||||||
fi
|
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"
|
echo "❌ Failed to build Docker image"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
@ -224,7 +243,7 @@ start_container() {
|
||||||
# Check if image exists (with or without localhost/ prefix)
|
# Check if image exists (with or without localhost/ prefix)
|
||||||
if ! docker images --format "{{.Repository}}:{{.Tag}}" | grep -q "distribution-$DISTRO:dev$"; then
|
if ! docker images --format "{{.Repository}}:{{.Tag}}" | grep -q "distribution-$DISTRO:dev$"; then
|
||||||
echo "❌ Error: Image distribution-$DISTRO:dev does not exist"
|
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
|
exit 1
|
||||||
fi
|
fi
|
||||||
echo "✅ Found existing image for distribution-$DISTRO:dev"
|
echo "✅ Found existing image for distribution-$DISTRO:dev"
|
||||||
|
|
@ -236,8 +255,10 @@ start_container() {
|
||||||
echo "=== Starting Docker Container ==="
|
echo "=== Starting Docker Container ==="
|
||||||
|
|
||||||
# Get the repo root for volume mount
|
# Get the repo root for volume mount
|
||||||
SCRIPT_DIR=$(cd "$(dirname "${BASH_SOURCE[0]:-$0}")" && pwd)
|
local script_dir
|
||||||
REPO_ROOT=$(cd "$SCRIPT_DIR/.." && pwd)
|
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)
|
# Determine the actual image name (may have localhost/ prefix)
|
||||||
IMAGE_NAME=$(docker images --format "{{.Repository}}:{{.Tag}}" | grep "distribution-$DISTRO:dev$" | head -1)
|
IMAGE_NAME=$(docker images --format "{{.Repository}}:{{.Tag}}" | grep "distribution-$DISTRO:dev$" | head -1)
|
||||||
|
|
@ -279,10 +300,18 @@ start_container() {
|
||||||
NETWORK_MODE="--network host"
|
NETWORK_MODE="--network host"
|
||||||
fi
|
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" \
|
docker run -d $NETWORK_MODE --name "$CONTAINER_NAME" \
|
||||||
-p $PORT:$PORT \
|
-p $PORT:$PORT \
|
||||||
$DOCKER_ENV_VARS \
|
$DOCKER_ENV_VARS \
|
||||||
-v "$REPO_ROOT":/app/llama-stack-source \
|
$source_mount \
|
||||||
"$IMAGE_NAME" \
|
"$IMAGE_NAME" \
|
||||||
--port $PORT
|
--port $PORT
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -252,19 +252,24 @@ if [[ "$STACK_CONFIG" == *"docker:"* && "$COLLECT_ONLY" == false ]]; then
|
||||||
export LLAMA_STACK_PORT=8321
|
export LLAMA_STACK_PORT=8321
|
||||||
|
|
||||||
echo "=== Building Docker Image for distribution: $DISTRO ==="
|
echo "=== Building Docker Image for distribution: $DISTRO ==="
|
||||||
# Set LLAMA_STACK_DIR to repo root
|
containerfile="$ROOT_DIR/containers/Containerfile"
|
||||||
# USE_COPY_NOT_MOUNT copies files into image (for CI), otherwise mounts for live development
|
if [[ ! -f "$containerfile" ]]; then
|
||||||
BUILD_ENV="LLAMA_STACK_DIR=$ROOT_DIR"
|
echo "❌ Containerfile not found at $containerfile"
|
||||||
if [[ "${CI:-false}" == "true" ]] || [[ "${GITHUB_ACTIONS:-false}" == "true" ]]; then
|
exit 1
|
||||||
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"
|
|
||||||
fi
|
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"
|
echo "❌ Failed to build Docker image"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
@ -304,7 +309,6 @@ if [[ "$STACK_CONFIG" == *"docker:"* && "$COLLECT_ONLY" == false ]]; then
|
||||||
docker run -d --network host --name "$container_name" \
|
docker run -d --network host --name "$container_name" \
|
||||||
-p $LLAMA_STACK_PORT:$LLAMA_STACK_PORT \
|
-p $LLAMA_STACK_PORT:$LLAMA_STACK_PORT \
|
||||||
$DOCKER_ENV_VARS \
|
$DOCKER_ENV_VARS \
|
||||||
-v $ROOT_DIR:/app/llama-stack-source \
|
|
||||||
"$IMAGE_NAME" \
|
"$IMAGE_NAME" \
|
||||||
--port $LLAMA_STACK_PORT
|
--port $LLAMA_STACK_PORT
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue