Repository navigation
Expand file tree
/
Copy pathdev
More file actions
executable file
·132 lines (110 loc) · 3.52 KB
/
Copy pathdev
File metadata and controls
executable file
·132 lines (110 loc) · 3.52 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
#!/usr/bin/env bash
set -euo pipefail
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
COMPOSE=(docker compose -f "$ROOT/bifrost-server/docker-compose.yml")
PIDS=()
STARTED_STACK=0
# Shared with the vite proxy so the usage page can call the orchestrator quota route.
export BIFROST_QUOTA_ACCESS_TOKEN="${BIFROST_QUOTA_ACCESS_TOKEN:-local-dev-quota-token}"
cleanup() {
trap - EXIT INT TERM
echo
echo "Stopping frontends…"
for pid in "${PIDS[@]:-}"; do
# Signal the process group even if the pnpm leader has already exited.
kill -- "-$pid" 2>/dev/null || kill "$pid" 2>/dev/null || true
wait "$pid" 2>/dev/null || true
done
if (( STARTED_STACK )); then
echo "Stopping Docker stack…"
"${COMPOSE[@]}" stop
fi
}
need() {
if ! command -v "$1" >/dev/null 2>&1; then
echo "Missing required command: $1" >&2
exit 1
fi
}
need docker
need pnpm
need bash
if ! docker info >/dev/null 2>&1; then
echo "Docker is not running." >&2
exit 1
fi
if ! command -v setsid >/dev/null 2>&1; then
echo "Missing required command: setsid" >&2
exit 1
fi
if ! bash -c 'sleep 0 & wait -n' >/dev/null 2>&1; then
echo "This launcher requires Bash with 'wait -n' support." >&2
exit 1
fi
dump_failed_containers() {
local ids
# Include exited/dead/restarting and running-but-unhealthy; --wait failures can leave either.
ids="$("${COMPOSE[@]}" ps -aq --status exited --status dead --status restarting 2>/dev/null || true)"
local running
running="$("${COMPOSE[@]}" ps -aq --status running 2>/dev/null || true)"
if [[ -n "${running}" ]]; then
while IFS= read -r id; do
[[ -z "${id}" ]] && continue
local health
health="$(docker inspect -f '{{if .State.Health}}{{.State.Health.Status}}{{else}}none{{end}}' "${id}" 2>/dev/null || echo none)"
if [[ "${health}" == "unhealthy" ]]; then
ids="${ids}"$'\n'"${id}"
fi
done <<<"${running}"
fi
if [[ -z "${ids//[[:space:]]/}" ]]; then
return 0
fi
echo
echo "Docker stack failed to become healthy. Logs from failed containers:" >&2
echo >&2
while IFS= read -r id; do
[[ -z "${id}" ]] && continue
local name
name="$(docker inspect -f '{{.Name}} ({{.State.Status}}, exit {{.State.ExitCode}})' "${id}" 2>/dev/null | sed 's#^/##')"
echo "──── ${name} ────" >&2
docker logs --tail 80 "${id}" >&2 || true
echo >&2
done <<<"${ids}"
}
trap cleanup EXIT INT TERM
echo "Starting Bifrost Docker stack…"
if ! "${COMPOSE[@]}" up --build -d --wait; then
dump_failed_containers
echo "Stopping partially started Docker stack…" >&2
"${COMPOSE[@]}" stop || true
exit 1
fi
STARTED_STACK=1
ensure_pnpm() {
local app="$1"
local dir="$ROOT/web/$app"
local lock="$dir/pnpm-lock.yaml"
# Always install before startup so a package.json change without a lock update fails fast.
echo "Installing $app dependencies…"
if [[ -f "$lock" ]]; then
(cd "$dir" && pnpm install --frozen-lockfile)
else
(cd "$dir" && pnpm install)
fi
}
ensure_pnpm orchestrator
echo "Starting orchestrator UI on http://127.0.0.1:5174 …"
setsid pnpm --dir "$ROOT/web/orchestrator" run dev --host 127.0.0.1 --port 5174 --strictPort </dev/null &
PIDS+=($!)
cat <<EOF
Bifrost local stack is up.
Orchestrator UI http://127.0.0.1:5174
Work items API http://127.0.0.1:8080
Orchestrator API http://127.0.0.1:8081
Skills API http://127.0.0.1:8082
RabbitMQ mgmt http://127.0.0.1:15672 (bifrost / bifrost)
Ctrl+C stops the frontend and the Docker stack (volumes are kept).
EOF
wait -n "${PIDS[@]}"
exit 1