-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun.sh
More file actions
executable file
·307 lines (272 loc) · 6.48 KB
/
Copy pathrun.sh
File metadata and controls
executable file
·307 lines (272 loc) · 6.48 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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
#!/usr/bin/env bash
set -euo pipefail
usage() {
cat <<'EOF'
Usage: ./run.sh [up|down|build|config|logs|ps] [options] [-- extra docker compose args]
Modes:
--local Include the local Logto service (default)
--remote Use an external Logto service
--bench Just like --local, but changes entrypoint to a benchmark instead of the web server
TimescaleDB always runs as a local container in --local and --remote alike.
AI:
--local-model [cpu|nvidia|amd]
Include a local Ollama model (CPU by default)
Networking:
dashboard Published on localhost:3001
logto Published on localhost:3011 and localhost:3002 in --local mode
backend/qdrant Internal Docker network only
timescaledb Published on localhost:5432
Accelerators:
--gpu [nvidia|amd] Enable backend GPU (bare --gpu keeps NVIDIA compatibility)
--local-model cpu Run Ollama on CPU
--local-model nvidia
Run Ollama on NVIDIA GPU
--local-model amd Run Ollama on AMD GPU with ROCm
--qdrant cpu Use CPU Qdrant (default)
--qdrant nvidia Enable NVIDIA GPU Qdrant image
--qdrant amd Enable AMD GPU Qdrant image
Common flags:
-d, --detach Run docker compose up in detached mode
--no-build Skip --build for docker compose up
-h, --help Show this help
Examples:
./run.sh up
./run.sh up --remote
./run.sh up --gpu nvidia --qdrant nvidia
./run.sh up --remote --gpu amd
./run.sh up --local-model amd
./run.sh up --gpu amd --local-model amd
./run.sh up --local-model amd --qdrant amd
./run.sh config --gpu amd
./run.sh up --bench
EOF
}
load_root_env() {
if [ -f ./.env ]; then
set -a
# shellcheck disable=SC1091
. ./.env
set +a
fi
}
load_amd_device_group_ids() {
local group_name group_id variable_name
for group_name in video render; do
variable_name="${group_name^^}_GID"
group_id="${!variable_name:-}"
if [ -z "$group_id" ]; then
group_id="$(getent group "$group_name" | awk -F: 'NR == 1 { print $3 }')"
fi
if [ -z "$group_id" ]; then
echo "ERROR: host group '$group_name' was not found; set $variable_name manually." >&2
exit 1
fi
export "$variable_name=$group_id"
done
}
ensure_gdrive_oauth_client_config() {
if [ -f "./secrets/client_secret.json" ]; then
return 0
fi
if [ -n "${CLIENT_SECRET:-}" ]; then
return 0
fi
echo "ERROR: Google Drive OAuth client config missing." >&2
echo "Provide ./secrets/client_secret.json or set CLIENT_SECRET (e.g. in .env)." >&2
exit 1
}
ensure_bench_results_writable() {
local dir="benchmark/results"
mkdir -p "$dir"
chmod 0777 "$dir"
}
action="up"
mode="local"
backend_accelerator="cpu"
qdrant_accelerator="cpu"
local_model=0
ollama_accelerator="cpu"
detach=0
build_on_up=1
extra_args=()
while [ "$#" -gt 0 ]; do
case "$1" in
up|down|build|config|logs|ps)
action="$1"
shift
;;
--local)
mode="local"
shift
;;
--remote)
mode="remote"
shift
;;
--bench)
mode="bench"
shift
;;
--gpu)
if [ "$#" -ge 2 ]; then
case "$2" in
cpu|none)
backend_accelerator="cpu"
shift 2
;;
nvidia|amd)
backend_accelerator="$2"
shift 2
;;
--*|up|down|build|config|logs|ps)
backend_accelerator="nvidia"
shift
;;
*)
echo "ERROR: --gpu accepts one of: nvidia, amd" >&2
exit 1
;;
esac
else
backend_accelerator="nvidia"
shift
fi
;;
--local-model)
local_model=1
if [ "$#" -ge 2 ]; then
case "$2" in
cpu|nvidia|amd)
ollama_accelerator="$2"
shift 2
;;
--*)
shift
;;
*)
echo "ERROR: --local-model accepts one of: cpu, nvidia, amd" >&2
exit 1
;;
esac
else
shift
fi
;;
--qdrant)
if [ "$#" -lt 2 ]; then
echo "ERROR: --qdrant requires one of: cpu, nvidia, amd" >&2
exit 1
fi
qdrant_accelerator="$2"
shift 2
;;
-d|--detach)
detach=1
shift
;;
--no-build)
build_on_up=0
shift
;;
-h|--help)
usage
exit 0
;;
--)
shift
extra_args+=("$@")
break
;;
*)
extra_args+=("$1")
shift
;;
esac
done
case "$backend_accelerator" in
cpu|nvidia|amd)
;;
*)
echo "ERROR: unsupported backend accelerator '$backend_accelerator'" >&2
exit 1
;;
esac
case "$qdrant_accelerator" in
cpu|nvidia|amd)
;;
*)
echo "ERROR: unsupported Qdrant accelerator '$qdrant_accelerator'" >&2
exit 1
;;
esac
case "$ollama_accelerator" in
cpu|nvidia|amd)
;;
*)
echo "ERROR: unsupported Ollama accelerator '$ollama_accelerator'" >&2
exit 1
;;
esac
if [ "$action" = "up" ]; then
load_root_env
ensure_gdrive_oauth_client_config
if [ "$mode" = "bench" ]; then
ensure_bench_results_writable
fi
fi
if [ "$backend_accelerator" = "amd" ] || [ "$qdrant_accelerator" = "amd" ]; then
load_amd_device_group_ids
fi
compose_args=()
if [ "$mode" = "bench" ]; then
compose_args+=(-f docker-compose.bench.yml)
else
# TimescaleDB always runs locally, in --local and --remote alike
compose_args+=(-f docker-compose.yml -f docker-compose.timescaledb.yml)
fi
if [ "$mode" = "local" ]; then
compose_args+=(-f docker-compose.local.yml)
fi
if [ "$local_model" -eq 1 ]; then
compose_args+=(-f docker-compose.ollama.yml)
case "$ollama_accelerator" in
nvidia)
compose_args+=(-f docker-compose.ollama-nvidia.yml)
;;
amd)
compose_args+=(-f docker-compose.ollama-amd.yml)
;;
esac
fi
case "$backend_accelerator" in
nvidia)
compose_args+=(-f docker-compose.gpu.yml)
;;
amd)
compose_args+=(-f docker-compose.gpu-amd.yml)
;;
esac
case "$qdrant_accelerator" in
nvidia)
compose_args+=(-f docker-compose.qdrant-nvidia.yml)
;;
amd)
compose_args+=(-f docker-compose.qdrant-amd.yml)
;;
esac
cmd=(docker compose "${compose_args[@]}" "$action")
if [ "$action" = "up" ]; then
if [ "$build_on_up" -eq 1 ]; then
cmd+=(--build)
fi
if [ "$detach" -eq 1 ]; then
cmd+=(-d)
fi
fi
if [ "${#extra_args[@]}" -gt 0 ]; then
cmd+=("${extra_args[@]}")
fi
printf 'Running:'
printf ' %q' "${cmd[@]}"
printf '\n'
exec "${cmd[@]}"