-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdocker-entrypoint.sh
More file actions
executable file
·180 lines (157 loc) · 6.22 KB
/
docker-entrypoint.sh
File metadata and controls
executable file
·180 lines (157 loc) · 6.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
#!/bin/bash
# MUXI Runtime - Docker Entrypoint
# This script is the entry point for the MUXI Runtime container
set -e # Exit on error
# In SIF (Singularity / Apptainer) mode the runtime is sealed off from the
# network. Model weights live on the HOST at ~/.muxi/server/cache and are
# bind-mounted in at /opt/hf-cache by muxi-server. The SIF itself ships no
# weights (see Dockerfile R3) — an empty /opt/hf-cache therefore guarantees
# a runtime failure at the first embedding call. We fail fast here with an
# actionable error instead of surfacing a confusing "model not found" from
# inside the application later.
if [ -n "$APPTAINER_CONTAINER" ] || [ -n "$SINGULARITY_CONTAINER" ] || [ "$MUXI_SIF_MODE" = "1" ]; then
export HF_HUB_OFFLINE=1
export TRANSFORMERS_OFFLINE=1
# Apptainer sets LD_LIBRARY_PATH to only /.singularity.d/libs, which hides
# system libraries installed via apt-get in the Docker image (e.g. libpoppler,
# libtesseract). Append the standard system paths so they remain discoverable.
export LD_LIBRARY_PATH="${LD_LIBRARY_PATH}:/usr/lib:/usr/lib64:/usr/local/lib:/usr/lib/x86_64-linux-gnu:/usr/lib/aarch64-linux-gnu"
# Cache assertion: at least one ``models--*`` directory must be present.
# Using ``find`` rather than shell globbing keeps the check portable and
# avoids nullglob / literal-glob pitfalls.
model_count=$(find /opt/hf-cache -maxdepth 1 -name 'models--*' -type d 2>/dev/null | wc -l)
if [ "$model_count" -eq 0 ]; then
echo "======================================" >&2
echo "ERROR: HuggingFace cache is empty" >&2
echo "======================================" >&2
echo "" >&2
echo "The SIF runtime runs offline (HF_HUB_OFFLINE=1) and ships no" >&2
echo "embedding model weights. /opt/hf-cache must be populated by the" >&2
echo "host at launch time via bind-mount." >&2
echo "" >&2
echo "Expected: at least one models--* directory under /opt/hf-cache." >&2
echo "" >&2
echo "If launched via muxi-server, this indicates the host cache at" >&2
echo "~/.muxi/server/cache is empty. Populate it with:" >&2
echo "" >&2
echo " HF_HUB_CACHE=~/.muxi/server/cache \\" >&2
echo " HF_HOME=~/.muxi/server/cache \\" >&2
echo " onellm download local/nomic-ai/nomic-embed-text-v1.5" >&2
echo "" >&2
echo "For ad-hoc apptainer runs, bind-mount the host cache yourself:" >&2
echo "" >&2
echo " apptainer run \\" >&2
echo " --bind \${HOME}/.muxi/server/cache:/opt/hf-cache \\" >&2
echo " <sif-path> <formation-path>" >&2
echo "" >&2
exit 1
fi
fi
echo "======================================"
echo "🚀 MUXI Runtime Container Starting"
echo "======================================"
echo ""
# Function to display usage
show_usage() {
cat << EOF
MUXI Runtime Container
USAGE:
docker run -v /path/to/formation:/formation \\
-e OPENAI_API_KEY=your-key \\
-p 8000:8000 \\
muxi-runtime /formation/formation.afs
ENVIRONMENT VARIABLES:
OPENAI_API_KEY OpenAI API key (if using OpenAI models)
ANTHROPIC_API_KEY Anthropic API key (if using Claude)
FORMATION_PORT Override server port (default: 8000)
FORMATION_HOST Override server host (default: 0.0.0.0)
REQUIRED:
- Formation YAML path as first argument
- Formation must be mounted as volume
- API keys must be set via environment variables
EXAMPLES:
# Run with OpenAI
docker run -v ./my-formation:/formation \\
-e OPENAI_API_KEY=sk-... \\
-p 8000:8000 \\
muxi-runtime /formation/formation.afs
# Run with custom port
docker run -v ./my-formation:/formation \\
-e OPENAI_API_KEY=sk-... \\
-e FORMATION_PORT=9000 \\
-p 9000:9000 \\
muxi-runtime /formation/formation.afs
EOF
}
# Check if formation path is provided
if [ -z "$1" ]; then
echo "❌ Error: No formation path provided"
echo ""
show_usage
exit 1
fi
FORMATION_PATH="$1"
shift # Remove formation path from args
# Parse remaining arguments (--port, --host)
while [[ $# -gt 0 ]]; do
case $1 in
--port)
CLI_PORT="$2"
shift 2
;;
--host)
CLI_HOST="$2"
shift 2
;;
*)
shift
;;
esac
done
# Check if formation file exists
if [ ! -f "$FORMATION_PATH" ]; then
echo "❌ Error: Formation file not found: $FORMATION_PATH"
echo ""
echo "Make sure you:"
echo " 1. Mount your formation directory as a volume"
echo " 2. Provide the correct path to formation.afs"
echo ""
echo "Example:"
echo " docker run -v ./my-formation:/formation \\"
echo " muxi-runtime /formation/formation.afs"
echo ""
exit 1
fi
# Priority: CLI args > environment vars > defaults
PORT="${CLI_PORT:-${PORT:-${FORMATION_PORT:-8000}}}"
HOST="${CLI_HOST:-${HOST:-${FORMATION_HOST:-127.0.0.1}}}"
# Display configuration
echo "📋 Configuration:"
echo " Formation: $FORMATION_PATH"
echo " Host: $HOST"
echo " Port: $PORT"
echo ""
# Check for required API keys (basic check)
if [ -z "$OPENAI_API_KEY" ] && [ -z "$ANTHROPIC_API_KEY" ]; then
echo "⚠️ Warning: No API keys detected"
echo " Set OPENAI_API_KEY or ANTHROPIC_API_KEY environment variable"
echo ""
fi
# Set up secrets if API keys are provided
mkdir -p ~/.muxi
if [ -n "$OPENAI_API_KEY" ]; then
echo "🔐 Setting up OPENAI_API_KEY secret..."
python -m muxi.runtime.utils.add_secret OPENAI_API_KEY "$OPENAI_API_KEY" 2>/dev/null || true
fi
if [ -n "$ANTHROPIC_API_KEY" ]; then
echo "🔐 Setting up ANTHROPIC_API_KEY secret..."
python -m muxi.runtime.utils.add_secret ANTHROPIC_API_KEY "$ANTHROPIC_API_KEY" 2>/dev/null || true
fi
echo ""
echo "======================================"
echo "🎯 Starting Formation Server..."
echo "======================================"
echo ""
# Run the formation server with port and host overrides
# The formation will load secrets from ~/.muxi/secrets.enc
exec python -m muxi.runtime.utils.run_formation "$FORMATION_PATH" --port "$PORT" --host "$HOST"