Elffuss BraidHub

kikocis/llama-stack public

7d178b9d269a · 2.8 KiB · executableRawPermalink
1#!/bin/bash
2
3LLAMA_MODELS_DIR=${LLAMA_MODELS_DIR:-}
4LLAMA_TOOLCHAIN_DIR=${LLAMA_TOOLCHAIN_DIR:-}
5TEST_PYPI_VERSION=${TEST_PYPI_VERSION:-}
6
7if [ "$#" -ne 4 ]; then
8 echo "Usage: $0 <distribution_type> <build_name> <docker_base> <pip_dependencies>
9 echo "Example: $0 distribution_type my-fastapi-app python:3.9-slim 'fastapi uvicorn'
10 exit 1
11fi
12
13distribution_type=$1
14build_name="$2"
15image_name="llamastack-$build_name"
16docker_base=$3
17pip_dependencies=$4
18
19# Define color codes
20RED='\033[0;31m'
21GREEN='\033[0;32m'
22NC='\033[0m' # No Color
23
24set -euo pipefail
25
26SCRIPT_DIR=$(dirname "$(readlink -f "$0")")
27REPO_DIR=$(dirname $(dirname "$SCRIPT_DIR"))
28
29TEMP_DIR=$(mktemp -d)
30
31add_to_docker() {
32 local input
33 output_file="$TEMP_DIR/Dockerfile"
34 if [ -t 0 ]; then
35 printf '%s\n' "$1" >>"$output_file"
36 else
37 # If stdin is not a terminal, read from it (heredoc)
38 cat >>"$output_file"
39 fi
40}
41
42add_to_docker <<EOF
43FROM $docker_base
44WORKDIR /app
45
46RUN apt-get update && apt-get install -y \
47 iputils-ping net-tools iproute2 dnsutils telnet \
48 curl wget telnet \
49 procps psmisc lsof \
50 traceroute \
51 bubblewrap \
52 && rm -rf /var/lib/apt/lists/*
53
54EOF
55
56toolchain_mount="/app/llama-toolchain-source"
57models_mount="/app/llama-models-source"
58
59if [ -n "$LLAMA_TOOLCHAIN_DIR" ]; then
60 if [ ! -d "$LLAMA_TOOLCHAIN_DIR" ]; then
61 echo "${RED}Warning: LLAMA_TOOLCHAIN_DIR is set but directory does not exist: $LLAMA_TOOLCHAIN_DIR${NC}" >&2
62 exit 1
63 fi
64 add_to_docker "RUN pip install $toolchain_mount"
65else
66 add_to_docker "RUN pip install llama-toolchain"
67fi
68
69if [ -n "$LLAMA_MODELS_DIR" ]; then
70 if [ ! -d "$LLAMA_MODELS_DIR" ]; then
71 echo "${RED}Warning: LLAMA_MODELS_DIR is set but directory does not exist: $LLAMA_MODELS_DIR${NC}" >&2
72 exit 1
73 fi
74
75 add_to_docker <<EOF
76RUN pip uninstall -y llama-models
77RUN pip install $models_mount
78
79EOF
80fi
81
82if [ -n "$pip_dependencies" ]; then
83 add_to_docker "RUN pip install $pip_dependencies"
84fi
85
86add_to_docker <<EOF
87
88# This would be good in production but for debugging flexibility lets not add it right now
89# We need a more solid production ready entrypoint.sh anyway
90#
91# ENTRYPOINT ["python", "-m", "llama_toolchain.core.server"]
92
93EOF
94
95printf "Dockerfile created successfully in $TEMP_DIR/Dockerfile"
96cat $TEMP_DIR/Dockerfile
97printf "\n"
98
99mounts=""
100if [ -n "$LLAMA_TOOLCHAIN_DIR" ]; then
101 mounts="$mounts -v $(readlink -f $LLAMA_TOOLCHAIN_DIR):$toolchain_mount"
102fi
103if [ -n "$LLAMA_MODELS_DIR" ]; then
104 mounts="$mounts -v $(readlink -f $LLAMA_MODELS_DIR):$models_mount"
105fi
106set -x
107podman build -t $image_name -f "$TEMP_DIR/Dockerfile" "$REPO_DIR" $mounts
108set +x
109
110printf "${GREEN}Succesfully setup Podman image. Configuring build...${NC}"
111echo "You can run it with: podman run -p 8000:8000 $image_name"
112
113$CONDA_PREFIX/bin/python3 -m llama_toolchain.cli.llama stack configure $distribution_type --name "$build_name" --type container