-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdocker-start
More file actions
executable file
·70 lines (67 loc) · 3.31 KB
/
Copy pathdocker-start
File metadata and controls
executable file
·70 lines (67 loc) · 3.31 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
#!/usr/bin/env bash
set -euo pipefail
repo_dir=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)
config_file="$repo_dir/config.json"
[[ -f "$config_file" ]] || { echo "Copy config.example.json to config.json first." >&2; exit 2; }
eval "$(python3 - "$config_file" "$repo_dir" <<'PY'
import json, shlex, sys
from pathlib import Path
config = json.load(open(sys.argv[1], encoding="utf-8")); repo = Path(sys.argv[2])
paths = config.get("paths", {}); enrichment = config.get("enrichment", {}); receiver = config.get("receiver", {})
def host_path(value):
path = Path(value).expanduser()
return path.resolve() if path.is_absolute() else (repo / path).resolve()
legacy_output_root = Path(paths.get("output_root", "./processing-output")).expanduser()
output_file = Path(receiver.get("output_path", legacy_output_root / "observations.jsonl")).expanduser()
if not output_file.is_absolute(): output_file = (repo / output_file).resolve()
output_file.parent.mkdir(parents=True, exist_ok=True)
data_root = host_path(paths["data_root"])
backup_root = host_path(paths["backup_root"])
data_root.mkdir(parents=True, exist_ok=True)
backup_root.mkdir(parents=True, exist_ok=True)
values = {
"OBSERVATION_OUTPUT_HOST": output_file.parent,
"OBSERVATION_OUTPUT_FILE": output_file.name,
"OBSERVATION_DATA_HOST": data_root,
"OBSERVATION_BACKUP_HOST": backup_root,
"OBSERVATION_RECEIVER_BIND_HOST": receiver.get("bind_host", receiver.get("host", "127.0.0.1")),
"OBSERVATION_RECEIVER_PORT": receiver.get("port", 8766),
"OBSERVATION_ANOMALY_THRESHOLD": enrichment.get("anomaly_threshold", 0.25),
"OBSERVATION_ANOMALY_ONLY": str(bool(enrichment.get("anomaly_only", False))).lower(),
"OBSERVATION_GPU": str(enrichment.get("gpu", "auto")).lower(),
"OBSERVATION_GPU_DEVICES": enrichment.get("gpu_devices", "all"),
"OBSERVATION_PYTORCH_VERSION": enrichment.get("pytorch_version", "2.7.1"),
"OBSERVATION_PYTORCH_INDEX_URL": enrichment.get("pytorch_index_url", "https://download.pytorch.org/whl/cu118"),
"OBSERVATION_MAX_MESSAGE_BYTES": receiver.get("max_message_bytes", 25000000),
"OBSERVATION_TEXT_MODEL": enrichment.get("text_model", "gpt-4o-mini"),
"OBSERVATION_VISION_MODEL": enrichment.get("vision_model", "gpt-4o-mini"),
"OBSERVATION_OPENAI_API_KEY": enrichment.get("openai_api_key", ""),
"OBSERVATION_GOOGLE_PLACES_API_KEY": enrichment.get("google_places_api_key", ""),
}
for key, value in values.items(): print(f"export {key}={shlex.quote(str(value))}")
PY
)"
compose=(docker compose --project-directory "$repo_dir" -f "$repo_dir/compose.yaml")
gpu_available=false
if command -v nvidia-smi >/dev/null 2>&1 && nvidia-smi -L >/dev/null 2>&1; then
if docker info --format '{{json .Runtimes}}' 2>/dev/null | grep -q '"nvidia"'; then
gpu_available=true
fi
fi
case "$OBSERVATION_GPU" in
true|yes|1)
compose+=(-f "$repo_dir/compose.gpu.yaml")
;;
auto)
if [[ "$gpu_available" == true ]]; then compose+=(-f "$repo_dir/compose.gpu.yaml"); fi
;;
false|no|0) ;;
*) echo "enrichment.gpu must be auto, true, or false" >&2; exit 2 ;;
esac
action=${1:-help}; shift || true
case "$action" in
up) exec "${compose[@]}" up -d --build "$@" ;;
down|stop|start|restart|ps|logs|build|pull) exec "${compose[@]}" "$action" "$@" ;;
config) exec "${compose[@]}" config --quiet ;;
*) echo "Usage: ./docker-start {up|down|stop|start|restart|ps|logs|build|pull|config}" ;;
esac