-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathstart_windows.cmd
More file actions
316 lines (280 loc) · 10.2 KB
/
Copy pathstart_windows.cmd
File metadata and controls
316 lines (280 loc) · 10.2 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
308
309
310
311
312
313
314
315
316
@echo off
setlocal enabledelayedexpansion
set "ROOT_DIR=%~dp0"
if "%ROOT_DIR:~-1%"=="\" set "ROOT_DIR=%ROOT_DIR:~0,-1%"
set "STATE_FILE=%ROOT_DIR%\.installer_state.env"
set "HEALTH_URL=http://localhost:5107/"
set "HOST_MOUNT_OVERRIDE_FILE=docker-compose.host-mounts.generated.yml"
set "ROCM_RUNTIME_OVERRIDE_FILE=docker-compose.rocm-runtime.generated.yml"
set "VOICE_PACK_OVERRIDE_FILE=docker-compose.voice-pack.local.yml"
set "START_COMMAND=start_windows.cmd"
set "ENV_FILE=.env"
set "MODE=install"
set "FIX_MODE=0"
set "INSTALLER_MODE=0"
set "BACKEND_OVERRIDE="
set "COMPOSE_MODE=ghcr"
:parse_args
if "%~1"=="" goto args_done
if /I "%~1"=="--doctor" (
set "MODE=doctor"
shift
goto parse_args
)
if /I "%~1"=="--fix" (
set "FIX_MODE=1"
shift
goto parse_args
)
if /I "%~1"=="--backend" (
if "%~2"=="" call :fail Missing value for --backend
set "BACKEND_OVERRIDE=%~2"
shift
shift
goto parse_args
)
if /I "%~1"=="--compose" (
if "%~2"=="" call :fail Missing value for --compose
set "COMPOSE_MODE=%~2"
shift
shift
goto parse_args
)
if /I "%~1"=="--installer" (
set "INSTALLER_MODE=1"
shift
goto parse_args
)
if /I "%~1"=="--help" goto usage
if /I "%~1"=="-h" goto usage
call :fail Unknown option: %~1
:args_done
if "%INSTALLER_MODE%"=="1" (
set "DOCKER_DIR=%ROOT_DIR%\installer\docker"
set "DOCKER_DIRECTORY=installer/docker"
) else (
set "DOCKER_DIR=%ROOT_DIR%\docker"
set "DOCKER_DIRECTORY=docker"
)
if not exist "%DOCKER_DIR%" call :fail Docker directory not found: %DOCKER_DIR%
if /I not "%COMPOSE_MODE%"=="ghcr" if /I not "%COMPOSE_MODE%"=="local" call :fail --compose must be ghcr or local
if not "%BACKEND_OVERRIDE%"=="" (
if /I not "%BACKEND_OVERRIDE%"=="cpu" if /I not "%BACKEND_OVERRIDE%"=="cuda13" if /I not "%BACKEND_OVERRIDE%"=="rocm" if /I not "%BACKEND_OVERRIDE%"=="slim" if /I not "%BACKEND_OVERRIDE%"=="vulkan" call :fail --backend must be cpu, cuda13, rocm, slim, or vulkan
)
call :log Running preflight checks...
where docker >nul 2>nul || (
if "%FIX_MODE%"=="1" (
call :warn Docker CLI missing. Attempting winget install for Docker Desktop...
where winget >nul 2>nul && winget install -e --id Docker.DockerDesktop
)
where docker >nul 2>nul || call :fail Docker CLI not found.
)
docker compose version >nul 2>nul || call :fail Docker Compose plugin not found (docker compose).
docker info >nul 2>nul || call :fail Docker daemon is not reachable. Start Docker Desktop and rerun.
call :check_wsl
call :detect_backend
call :validate_backend
call :select_compose_file
call :select_vulkan_runtime
call :select_rocm_runtime
if "%INSTALLER_MODE%"=="1" (
call :log Installer layout: using %DOCKER_DIRECTORY% for compose, volumes, and overrides.
)
call :log Selected backend: %SELECTED_BACKEND%
call :log Compose file: %DOCKER_DIRECTORY%\%COMPOSE_FILE%
if /I "%MODE%"=="doctor" (
call :log Doctor mode complete. No changes were made.
call :save_state
exit /b 0
)
pushd "%DOCKER_DIR%" || call :fail Could not open docker directory.
set "COMPOSE_ARGS=-f %COMPOSE_FILE%"
if exist "%HOST_MOUNT_OVERRIDE_FILE%" (
docker compose -f "%COMPOSE_FILE%" -f "%HOST_MOUNT_OVERRIDE_FILE%" --env-file "%ENV_FILE%" config >nul 2>nul
if errorlevel 1 (
call :warn Ignoring invalid host mount override %DOCKER_DIRECTORY%\%HOST_MOUNT_OVERRIDE_FILE%. Recreate mounts to regenerate it.
) else (
set "COMPOSE_ARGS=%COMPOSE_ARGS% -f %HOST_MOUNT_OVERRIDE_FILE%"
call :log Including host mount override: %HOST_MOUNT_OVERRIDE_FILE%
)
)
if exist "%ROCM_RUNTIME_OVERRIDE_FILE%" (
docker compose -f "%COMPOSE_FILE%" -f "%ROCM_RUNTIME_OVERRIDE_FILE%" --env-file "%ENV_FILE%" config >nul 2>nul
if errorlevel 1 (
call :warn Ignoring invalid ROCm runtime override %DOCKER_DIRECTORY%\%ROCM_RUNTIME_OVERRIDE_FILE%.
) else (
set "COMPOSE_ARGS=%COMPOSE_ARGS% -f %ROCM_RUNTIME_OVERRIDE_FILE%"
call :log Including ROCm runtime override: %ROCM_RUNTIME_OVERRIDE_FILE%
)
)
if exist "%VOICE_PACK_OVERRIDE_FILE%" (
docker compose -f "%COMPOSE_FILE%" -f "%VOICE_PACK_OVERRIDE_FILE%" --env-file "%ENV_FILE%" config >nul 2>nul
if errorlevel 1 (
call :warn Ignoring invalid voice pack override %DOCKER_DIRECTORY%\%VOICE_PACK_OVERRIDE_FILE%.
) else (
set "COMPOSE_ARGS=%COMPOSE_ARGS% -f %VOICE_PACK_OVERRIDE_FILE%"
call :log Including voice pack override: %VOICE_PACK_OVERRIDE_FILE%
)
)
docker compose %COMPOSE_ARGS% --env-file "%ENV_FILE%" up -d || (
popd
call :fail docker compose up failed.
)
popd
call :wait_for_health
if errorlevel 1 (
call :warn GuideAnts did not pass health check in time. Check: docker compose -f %DOCKER_DIRECTORY%\%COMPOSE_FILE% ps
) else (
call :log GuideAnts is up: %HEALTH_URL%
start "" "%HEALTH_URL%"
)
call :save_state
exit /b 0
:check_wsl
wsl --status >nul 2>nul
if errorlevel 1 (
if "%FIX_MODE%"=="1" (
call :warn WSL is not available. Attempting install...
wsl --install >nul 2>nul
)
wsl --status >nul 2>nul || call :warn WSL check failed. Docker Desktop may still work if configured differently.
exit /b 0
)
for /f "tokens=1,* delims=:" %%a in ('wsl --status 2^>nul ^| findstr /I "Default Version"') do (
set "WSL_DEFAULT_VERSION=%%b"
)
if defined WSL_DEFAULT_VERSION (
echo !WSL_DEFAULT_VERSION! | findstr /R "2" >nul || call :warn WSL default version is not 2.
)
exit /b 0
:detect_backend
if not "%BACKEND_OVERRIDE%"=="" (
set "SELECTED_BACKEND=%BACKEND_OVERRIDE%"
exit /b 0
)
where nvidia-smi >nul 2>nul || (
goto detect_amd
)
nvidia-smi >nul 2>nul || (
goto detect_amd
)
set "SELECTED_BACKEND=cuda13"
exit /b 0
:detect_amd
for /f "delims=" %%a in ('powershell -NoProfile -Command "$g=(Get-CimInstance Win32_VideoController 2>$null | Select-Object -ExpandProperty Name) -join ''`n''; if($g -match ''AMD|Radeon''){''rocm''} else {''cpu''}"') do set "SELECTED_BACKEND=%%a"
if not defined SELECTED_BACKEND set "SELECTED_BACKEND=cpu"
exit /b 0
:validate_backend
if /I not "%SELECTED_BACKEND%"=="cuda13" exit /b 0
set "NVIDIA_DRIVER_VERSION="
for /f "delims=" %%a in ('nvidia-smi --query-gpu^=driver_version --format^=csv^,noheader 2^>nul') do (
if not defined NVIDIA_DRIVER_VERSION set "NVIDIA_DRIVER_VERSION=%%a"
)
if not defined NVIDIA_DRIVER_VERSION (
if not "%BACKEND_OVERRIDE%"=="" (
call :fail Could not read NVIDIA driver version from nvidia-smi. Remove --backend cuda13 or fix NVIDIA driver/runtime.
)
call :warn Could not read NVIDIA driver version from nvidia-smi. Falling back to vulkan backend.
set "SELECTED_BACKEND=vulkan"
exit /b 0
)
for /f "tokens=1 delims=." %%a in ("%NVIDIA_DRIVER_VERSION%") do set "NVIDIA_DRIVER_MAJOR=%%a"
if not defined NVIDIA_DRIVER_MAJOR set "NVIDIA_DRIVER_MAJOR=0"
set /a NVIDIA_DRIVER_MAJOR_NUM=%NVIDIA_DRIVER_MAJOR% >nul 2>nul
if errorlevel 1 (
if not "%BACKEND_OVERRIDE%"=="" (
call :fail Could not parse NVIDIA driver version "%NVIDIA_DRIVER_VERSION%". Remove --backend cuda13 or fix NVIDIA drivers.
exit /b 1
)
call :warn Could not parse NVIDIA driver version "%NVIDIA_DRIVER_VERSION%". Falling back to vulkan backend.
set "SELECTED_BACKEND=vulkan"
exit /b 0
)
rem CUDA 13 requires NVIDIA R580+ drivers.
if %NVIDIA_DRIVER_MAJOR_NUM% LSS 580 (
if not "%BACKEND_OVERRIDE%"=="" (
call :fail NVIDIA driver %NVIDIA_DRIVER_VERSION% is too old for cuda13. Install R580+ driver or use --backend cpu.
exit /b 1
)
call :warn NVIDIA driver %NVIDIA_DRIVER_VERSION% is below the CUDA 13 minimum ^(R580^). Falling back to vulkan backend.
set "SELECTED_BACKEND=vulkan"
exit /b 0
)
call :log NVIDIA driver %NVIDIA_DRIVER_VERSION% satisfies CUDA 13 minimum ^(R580^).
exit /b 0
:select_compose_file
if /I "%COMPOSE_MODE%"=="local" (
if /I "%SELECTED_BACKEND%"=="slim" (
set "COMPOSE_FILE=docker-compose.slim.yml"
) else if /I "%SELECTED_BACKEND%"=="cuda13" (
set "COMPOSE_FILE=docker-compose.cuda.yml"
) else if /I "%SELECTED_BACKEND%"=="rocm" (
set "COMPOSE_FILE=docker-compose.rocm.yml"
) else if /I "%SELECTED_BACKEND%"=="vulkan" (
set "COMPOSE_FILE=docker-compose.vulkan.yml"
) else (
set "COMPOSE_FILE=docker-compose.cpu.yml"
)
) else (
if /I "%SELECTED_BACKEND%"=="slim" (
set "COMPOSE_FILE=docker-compose.ghcr-slim.yml"
) else if /I "%SELECTED_BACKEND%"=="cuda13" (
set "COMPOSE_FILE=docker-compose.ghcr-cuda13.yml"
) else if /I "%SELECTED_BACKEND%"=="rocm" (
set "COMPOSE_FILE=docker-compose.ghcr-rocm.yml"
) else if /I "%SELECTED_BACKEND%"=="vulkan" (
set "COMPOSE_FILE=docker-compose.ghcr-vulkan.yml"
) else (
set "COMPOSE_FILE=docker-compose.ghcr-cpu.yml"
)
)
exit /b 0
:select_vulkan_runtime
if /I not "%SELECTED_BACKEND%"=="vulkan" exit /b 0
call :log Vulkan: Docker Desktop -^> Mesa dzn over D3D12 (/dev/dxg). Using built-in defaults (no env).
exit /b 0
:select_rocm_runtime
if /I not "%SELECTED_BACKEND%"=="rocm" exit /b 0
powershell -NoProfile -ExecutionPolicy Bypass -File "%ROOT_DIR%\installer\scripts\rocm-runtime-compose.ps1" -DockerDir "%DOCKER_DIR%" -Backend "%SELECTED_BACKEND%"
exit /b 0
:wait_for_health
set /a _max=120
set /a _count=0
:wait_loop
set /a _count+=1
curl -fsS "%HEALTH_URL%" >nul 2>nul && exit /b 0
if %_count% GEQ %_max% exit /b 1
timeout /t 2 /nobreak >nul
goto wait_loop
:save_state
(
echo BACKEND=%SELECTED_BACKEND%
echo COMPOSE_MODE=%COMPOSE_MODE%
echo COMPOSE_FILE=%COMPOSE_FILE%
echo HOST_MOUNT_OVERRIDE_FILE=%HOST_MOUNT_OVERRIDE_FILE%
echo VOICE_PACK_OVERRIDE_FILE=%VOICE_PACK_OVERRIDE_FILE%
echo DOCKER_DIRECTORY=%DOCKER_DIRECTORY%
echo START_COMMAND=%START_COMMAND%
for /f %%i in ('powershell -NoProfile -Command "[int][double]::Parse((Get-Date -UFormat %%s))"') do echo LAST_RUN_EPOCH=%%i
) > "%STATE_FILE%"
exit /b 0
:log
echo [guideants-installer] %*
exit /b 0
:warn
echo [guideants-installer][warn] %* 1>&2
exit /b 0
:fail
echo [guideants-installer][error] %* 1>&2
exit /b 1
:usage
echo Usage: start_windows.cmd [options]
echo.
echo Options:
echo --doctor Run checks only, do not change anything.
echo --fix Attempt limited auto-remediation where possible.
echo --backend cpu^|cuda13^|rocm^|slim^|vulkan Force backend selection. slim and vulkan are explicit only and are not auto-detected.
echo --compose ghcr^|local Use GHCR compose files ^(default^) or local build files.
echo --installer Use installer/docker compose files, volumes, and overrides.
echo --help Show this help.
exit /b 0