-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathstart_macos.sh
More file actions
232 lines (203 loc) · 7.21 KB
/
Copy pathstart_macos.sh
File metadata and controls
232 lines (203 loc) · 7.21 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
#!/usr/bin/env bash
set -euo pipefail
ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
STATE_FILE="$ROOT_DIR/.installer_state.env"
MODE="install" # install | doctor
FIX_MODE="0" # 0 | 1
INSTALLER_MODE="0" # 0 | 1
BACKEND_OVERRIDE="" # cpu | cuda13 | rocm | slim | vulkan
COMPOSE_MODE="ghcr" # ghcr | local
HEALTH_URL="http://localhost:5107/"
HOST_MOUNT_OVERRIDE_FILE="docker-compose.host-mounts.generated.yml"
ROCM_RUNTIME_OVERRIDE_FILE="docker-compose.rocm-runtime.generated.yml"
VOICE_PACK_OVERRIDE_FILE="docker-compose.voice-pack.local.yml"
START_COMMAND="start_macos.sh"
DOCKER_DIR=""
DOCKER_DIRECTORY=""
ENV_FILE=""
usage() {
cat <<'EOF'
Usage: ./start_macos.sh [options]
Options:
--doctor Run checks only, do not change anything.
--fix Attempt limited auto-remediation where possible.
--backend cpu|cuda13|rocm|slim|vulkan Force backend selection. slim and vulkan are explicit only and are not auto-detected.
--compose ghcr|local Use GHCR compose files (default) or local build files.
--installer Use installer/docker compose files, volumes, and overrides.
--help Show this help.
EOF
}
log() { printf '[guideants-installer] %s\n' "$*"; }
warn() { printf '[guideants-installer][warn] %s\n' "$*" >&2; }
fail() { printf '[guideants-installer][error] %s\n' "$*" >&2; exit 1; }
apply_docker_layout() {
if [[ "$INSTALLER_MODE" == "1" ]]; then
DOCKER_DIR="$ROOT_DIR/installer/docker"
DOCKER_DIRECTORY="installer/docker"
log "Installer layout: using $DOCKER_DIRECTORY for compose, volumes, and overrides."
else
DOCKER_DIR="$ROOT_DIR/docker"
DOCKER_DIRECTORY="docker"
fi
ENV_FILE="$DOCKER_DIR/.env"
[[ -d "$DOCKER_DIR" ]] || fail "Docker directory not found: $DOCKER_DIR"
}
# shellcheck source=installer/scripts/rocm-runtime-compose.sh
. "$ROOT_DIR/installer/scripts/rocm-runtime-compose.sh"
export ROCM_RUNTIME_LOG_FN=log
export ROCM_RUNTIME_WARN_FN=warn
save_state() {
cat >"$STATE_FILE" <<EOF
BACKEND=${SELECTED_BACKEND:-}
COMPOSE_MODE=${COMPOSE_MODE}
COMPOSE_FILE=${COMPOSE_FILE}
HOST_MOUNT_OVERRIDE_FILE=${HOST_MOUNT_OVERRIDE_FILE}
VOICE_PACK_OVERRIDE_FILE=${VOICE_PACK_OVERRIDE_FILE}
DOCKER_DIRECTORY=${DOCKER_DIRECTORY}
START_COMMAND=${START_COMMAND}
LAST_RUN_EPOCH=$(date +%s)
EOF
}
detect_backend() {
if [[ -n "$BACKEND_OVERRIDE" ]]; then
SELECTED_BACKEND="$BACKEND_OVERRIDE"
return
fi
if command -v system_profiler >/dev/null 2>&1; then
if system_profiler SPDisplaysDataType 2>/dev/null | grep -Eiq 'AMD|Radeon'; then
SELECTED_BACKEND="rocm"
return
fi
fi
SELECTED_BACKEND="cpu"
}
ensure_cmd() {
local cmd="$1"
command -v "$cmd" >/dev/null 2>&1 || return 1
}
check_prereqs() {
log "Running preflight checks..."
if ! ensure_cmd docker; then
if [[ "$FIX_MODE" == "1" ]]; then
if ensure_cmd brew; then
warn "Docker CLI missing. Install Docker Desktop manually or with Homebrew cask, then start Docker."
fi
fi
fail "Docker CLI not found."
fi
if ! docker compose version >/dev/null 2>&1; then
fail "Docker Compose plugin not found (docker compose)."
fi
if ! docker info >/dev/null 2>&1; then
fail "Docker daemon is not reachable. Start Docker Desktop and rerun."
fi
}
select_compose_file() {
if [[ "$COMPOSE_MODE" == "local" ]]; then
case "$SELECTED_BACKEND" in
slim) COMPOSE_FILE="docker-compose.slim.yml" ;;
cuda13) COMPOSE_FILE="docker-compose.cuda.yml" ;;
rocm) COMPOSE_FILE="docker-compose.rocm.yml" ;;
vulkan) COMPOSE_FILE="docker-compose.vulkan.yml" ;;
*) COMPOSE_FILE="docker-compose.cpu.yml" ;;
esac
else
case "$SELECTED_BACKEND" in
slim) COMPOSE_FILE="docker-compose.ghcr-slim.yml" ;;
cuda13) COMPOSE_FILE="docker-compose.ghcr-cuda13.yml" ;;
rocm) COMPOSE_FILE="docker-compose.ghcr-rocm.yml" ;;
vulkan) COMPOSE_FILE="docker-compose.ghcr-vulkan.yml" ;;
*) COMPOSE_FILE="docker-compose.ghcr-cpu.yml" ;;
esac
fi
}
select_vulkan_runtime() {
[[ "$SELECTED_BACKEND" == "vulkan" ]] || return 0
log "Vulkan: Docker Desktop → Mesa dzn over D3D12 (/dev/dxg). Using built-in defaults (no env)."
}
wait_for_health() {
log "Waiting for GuideAnts UI to become reachable at $HEALTH_URL"
for _ in $(seq 1 120); do
if curl -fsS "$HEALTH_URL" >/dev/null 2>&1; then
return 0
fi
sleep 2
done
return 1
}
open_browser() {
open "$HEALTH_URL" >/dev/null 2>&1 || true
}
while [[ $# -gt 0 ]]; do
case "$1" in
--doctor) MODE="doctor" ;;
--fix) FIX_MODE="1" ;;
--backend)
[[ $# -ge 2 ]] || fail "Missing value for --backend"
BACKEND_OVERRIDE="$2"
shift
;;
--compose)
[[ $# -ge 2 ]] || fail "Missing value for --compose"
COMPOSE_MODE="$2"
shift
;;
--installer) INSTALLER_MODE="1" ;;
--help|-h) usage; exit 0 ;;
*) fail "Unknown option: $1" ;;
esac
shift
done
[[ "$COMPOSE_MODE" == "ghcr" || "$COMPOSE_MODE" == "local" ]] || fail "--compose must be ghcr or local"
[[ -z "$BACKEND_OVERRIDE" || "$BACKEND_OVERRIDE" == "cpu" || "$BACKEND_OVERRIDE" == "cuda13" || "$BACKEND_OVERRIDE" == "rocm" || "$BACKEND_OVERRIDE" == "slim" || "$BACKEND_OVERRIDE" == "vulkan" ]] || fail "--backend must be cpu, cuda13, rocm, slim, or vulkan"
apply_docker_layout
check_prereqs
detect_backend
select_compose_file
select_vulkan_runtime
select_rocm_runtime "$DOCKER_DIR"
log "Selected backend: $SELECTED_BACKEND"
log "Compose file: $DOCKER_DIRECTORY/$COMPOSE_FILE"
if [[ "$MODE" == "doctor" ]]; then
log "Doctor mode complete. No changes were made."
save_state
exit 0
fi
if [[ "$(uname -m)" == "arm64" ]]; then
export DOCKER_DEFAULT_PLATFORM=linux/amd64
fi
pushd "$DOCKER_DIR" >/dev/null
compose_args=(-f "$COMPOSE_FILE")
if [[ -f "$HOST_MOUNT_OVERRIDE_FILE" ]]; then
if docker compose -f "$COMPOSE_FILE" -f "$HOST_MOUNT_OVERRIDE_FILE" --env-file "$ENV_FILE" config >/dev/null 2>&1; then
compose_args+=(-f "$HOST_MOUNT_OVERRIDE_FILE")
log "Including host mount override: $HOST_MOUNT_OVERRIDE_FILE"
else
warn "Ignoring invalid host mount override $DOCKER_DIRECTORY/$HOST_MOUNT_OVERRIDE_FILE. Recreate mounts to regenerate it."
fi
fi
if [[ -f "$ROCM_RUNTIME_OVERRIDE_FILE" ]]; then
if docker compose -f "$COMPOSE_FILE" -f "$ROCM_RUNTIME_OVERRIDE_FILE" --env-file "$ENV_FILE" config >/dev/null 2>&1; then
compose_args+=(-f "$ROCM_RUNTIME_OVERRIDE_FILE")
log "Including ROCm runtime override: $ROCM_RUNTIME_OVERRIDE_FILE"
else
warn "Ignoring invalid ROCm runtime override $DOCKER_DIRECTORY/$ROCM_RUNTIME_OVERRIDE_FILE."
fi
fi
if [[ -f "$VOICE_PACK_OVERRIDE_FILE" ]]; then
if docker compose -f "$COMPOSE_FILE" -f "$VOICE_PACK_OVERRIDE_FILE" --env-file "$ENV_FILE" config >/dev/null 2>&1; then
compose_args+=(-f "$VOICE_PACK_OVERRIDE_FILE")
log "Including voice pack override: $VOICE_PACK_OVERRIDE_FILE"
else
warn "Ignoring invalid voice pack override $DOCKER_DIRECTORY/$VOICE_PACK_OVERRIDE_FILE."
fi
fi
docker compose "${compose_args[@]}" --env-file "$ENV_FILE" up -d
popd >/dev/null
if wait_for_health; then
log "GuideAnts is up: $HEALTH_URL"
open_browser
else
warn "GuideAnts did not pass health check in time. Check: docker compose -f $DOCKER_DIRECTORY/$COMPOSE_FILE ps"
fi
save_state