-
-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathstart.bat
More file actions
317 lines (271 loc) · 12.2 KB
/
Copy pathstart.bat
File metadata and controls
317 lines (271 loc) · 12.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
317
@echo off
setlocal EnableExtensions
echo ============================================
echo Draft to Take Beta
echo ============================================
echo.
cd /d "%~dp0"
if not exist ".env" (
copy ".env.example" ".env" >nul
echo [INFO] Created .env from .env.example.
)
call :ValidateEnvFile ".env"
if errorlevel 1 (
pause
exit /b 1
)
for /f "usebackq eol=# tokens=1,* delims==" %%A in (".env") do (
if not "%%A"=="" set "%%A=%%B"
)
if not defined DRAFT_TO_TAKE_HOME set "DRAFT_TO_TAKE_HOME=%USERPROFILE%\DraftToTake"
if not defined DRAFT_TO_TAKE_SHARED_DIR set "DRAFT_TO_TAKE_SHARED_DIR=%DRAFT_TO_TAKE_HOME%\shared"
set "DRAFT_TO_TAKE_RUNTIME_ENV=.draft-to-take-runtime.env"
call :ValidateSharedDir
if errorlevel 1 (
pause
exit /b 1
)
for %%d in (
"%DRAFT_TO_TAKE_SHARED_DIR%\models"
"%DRAFT_TO_TAKE_SHARED_DIR%\models\checkpoints"
"%DRAFT_TO_TAKE_SHARED_DIR%\models\llm"
"%DRAFT_TO_TAKE_SHARED_DIR%\audio"
"%DRAFT_TO_TAKE_SHARED_DIR%\audio\speakers"
"%DRAFT_TO_TAKE_SHARED_DIR%\audio\source_clips"
"%DRAFT_TO_TAKE_SHARED_DIR%\audio\outputs"
"%DRAFT_TO_TAKE_SHARED_DIR%\audio\sfx"
"%DRAFT_TO_TAKE_SHARED_DIR%\audio\ambience"
"%DRAFT_TO_TAKE_SHARED_DIR%\audio\music"
"%DRAFT_TO_TAKE_SHARED_DIR%\data"
) do (
if not exist "%%~d" mkdir "%%~d"
)
if not defined INDTEXTS_FRONTEND_HOST_PORT (
for /f %%i in ('powershell -NoProfile -Command "$ports = 3000..3010; foreach ($port in $ports) { if (-not (Get-NetTCPConnection -LocalPort $port -State Listen -ErrorAction SilentlyContinue)) { $port; break } }"') do set "INDTEXTS_FRONTEND_HOST_PORT=%%i"
)
if not defined INDTEXTS_BACKEND_HOST_PORT (
for /f %%i in ('powershell -NoProfile -Command "$ports = 8001..8010; foreach ($port in $ports) { if (-not (Get-NetTCPConnection -LocalPort $port -State Listen -ErrorAction SilentlyContinue)) { $port; break } }"') do set "INDTEXTS_BACKEND_HOST_PORT=%%i"
)
if not defined INDTEXTS_FRONTEND_HOST_PORT (
echo [ERROR] Could not find a free frontend host port in the 3000-3010 range.
pause
exit /b 1
)
if not defined INDTEXTS_BACKEND_HOST_PORT (
echo [ERROR] Could not find a free backend host port in the 8001-8010 range.
pause
exit /b 1
)
call :ValidatePort INDTEXTS_FRONTEND_HOST_PORT 3000
call :ValidatePort INDTEXTS_BACKEND_HOST_PORT 8001
call :ValidatePort INDTEXTS_SCRIPT_LLM_HOST_PORT 8030
call :ValidatePort INDTEXTS_SFX_HOST_PORT 8020
call :ValidatePort INDTEXTS_OMNIVOICE_HOST_PORT 8010
docker info >nul 2>&1
if errorlevel 1 (
echo [ERROR] Docker is not running. Please start Docker Desktop and try again.
pause
exit /b 1
)
echo [INFO] Checking NVIDIA GPU access from Docker...
docker run --rm --gpus all nvidia/cuda:12.8.0-base-ubuntu22.04 nvidia-smi >nul 2>&1
if errorlevel 1 (
echo [WARNING] NVIDIA GPU not detected through Docker.
echo Dialogue may run in CPU mode and will be much slower.
echo SFX/music generation is disabled unless you opt in manually.
set "INDTEXTS_USE_GPU=false"
set "INDTEXTS_DEVICE=cpu"
if "%INDTEXTS_SFX_ENABLED%"=="" set "INDTEXTS_SFX_ENABLED=false"
set "COMPOSE_FILES=-f docker-compose.yml"
) else (
echo [INFO] NVIDIA GPU detected.
set "INDTEXTS_USE_GPU=true"
if "%INDTEXTS_DEVICE%"=="" set "INDTEXTS_DEVICE=auto"
if "%INDTEXTS_USE_DEEPSPEED%"=="" set "INDTEXTS_USE_DEEPSPEED=true"
if "%INDTEXTS_SFX_ENABLED%"=="" set "INDTEXTS_SFX_ENABLED=true"
set "COMPOSE_FILES=-f docker-compose.yml -f docker-compose.gpu.yml"
)
if "%INDTEXTS_SCRIPT_LLM_ENABLED%"=="" set "INDTEXTS_SCRIPT_LLM_ENABLED=true"
if "%INDTEXTS_OMNIVOICE_ENABLED%"=="" set "INDTEXTS_OMNIVOICE_ENABLED=true"
set "COMPOSE_PROFILES_ARGS="
if /I not "%INDTEXTS_SCRIPT_LLM_ENABLED%"=="false" (
set "COMPOSE_PROFILES_ARGS=%COMPOSE_PROFILES_ARGS% --profile llm"
echo [INFO] Managed local Qwen sidecar: enabled
) else (
echo [INFO] Managed local Qwen sidecar: disabled
)
if /I not "%INDTEXTS_OMNIVOICE_ENABLED%"=="false" (
set "COMPOSE_PROFILES_ARGS=%COMPOSE_PROFILES_ARGS% --profile omnivoice"
echo [INFO] OmniVoice sidecar: enabled
) else (
echo [INFO] OmniVoice sidecar: disabled
)
if /I "%INDTEXTS_SFX_ENABLED%"=="true" (
set "COMPOSE_PROFILES_ARGS=%COMPOSE_PROFILES_ARGS% --profile sfx"
echo [INFO] SFX/music sidecar: enabled
) else (
echo [INFO] SFX/music sidecar: disabled
)
(
echo INDTEXTS_FRONTEND_HOST_PORT=%INDTEXTS_FRONTEND_HOST_PORT%
echo INDTEXTS_BACKEND_HOST_PORT=%INDTEXTS_BACKEND_HOST_PORT%
echo DRAFT_TO_TAKE_SHARED_DIR=%DRAFT_TO_TAKE_SHARED_DIR%
echo INDTEXTS_USE_GPU=%INDTEXTS_USE_GPU%
echo INDTEXTS_DEVICE=%INDTEXTS_DEVICE%
echo INDTEXTS_USE_DEEPSPEED=%INDTEXTS_USE_DEEPSPEED%
echo INDTEXTS_SCRIPT_LLM_ENABLED=%INDTEXTS_SCRIPT_LLM_ENABLED%
echo INDTEXTS_OMNIVOICE_ENABLED=%INDTEXTS_OMNIVOICE_ENABLED%
echo INDTEXTS_SFX_ENABLED=%INDTEXTS_SFX_ENABLED%
) > "%DRAFT_TO_TAKE_RUNTIME_ENV%"
set "COMPOSE_ENV_FILES=--env-file .env --env-file %DRAFT_TO_TAKE_RUNTIME_ENV%"
echo.
echo [INFO] Shared files live here:
echo %DRAFT_TO_TAKE_SHARED_DIR%
echo.
if "%DRAFT_TO_TAKE_PULL_RETRIES%"=="" set "DRAFT_TO_TAKE_PULL_RETRIES=3"
echo [INFO] Pulling Draft to Take beta images one service at a time...
echo First pulls are large. A full GPU setup can use roughly 25-40 GB
echo of Docker disk space before app models download into your shared folder.
echo Pull progress can pause near 99%% while Docker verifies and extracts layers.
echo That pause can last several minutes on slower disks.
echo Large first-time downloads can occasionally stop with unexpected EOF.
echo The launcher will retry each enabled image up to %DRAFT_TO_TAKE_PULL_RETRIES% times.
echo After updating between beta tags, old Docker images can remain on disk.
echo Run cleanup-docker-space.bat if Docker disk usage grows after updates.
echo.
echo [INFO] Current Docker disk usage:
docker system df
call :PullService frontend
if errorlevel 1 goto PullFailed
call :PullService backend
if errorlevel 1 goto PullFailed
if /I not "%INDTEXTS_SCRIPT_LLM_ENABLED%"=="false" (
call :PullService script-llm
if errorlevel 1 goto PullFailed
)
if /I not "%INDTEXTS_OMNIVOICE_ENABLED%"=="false" (
call :PullService omnivoice
if errorlevel 1 goto PullFailed
)
if /I "%INDTEXTS_SFX_ENABLED%"=="true" (
call :PullService sfx
if errorlevel 1 goto PullFailed
)
docker compose %COMPOSE_ENV_FILES% %COMPOSE_FILES% %COMPOSE_PROFILES_ARGS% up -d
if errorlevel 1 (
echo [ERROR] Docker Compose failed to start the beta stack.
pause
exit /b 1
)
call :CheckComposePort backend 8000 DRAFT_TO_TAKE_BACKEND_BINDING
if /I "%DRAFT_TO_TAKE_BACKEND_BINDING%"=="invalid IP:0" set "DRAFT_TO_TAKE_BACKEND_BINDING="
if "%DRAFT_TO_TAKE_BACKEND_BINDING%"=="" (
echo [ERROR] Backend container started, but Docker did not publish its host port.
echo Run collect-diagnostics.bat and include the Compose PS section in your bug report.
pause
exit /b 1
)
call :CheckComposePort frontend 80 DRAFT_TO_TAKE_FRONTEND_BINDING
if /I "%DRAFT_TO_TAKE_FRONTEND_BINDING%"=="invalid IP:0" set "DRAFT_TO_TAKE_FRONTEND_BINDING="
if "%DRAFT_TO_TAKE_FRONTEND_BINDING%"=="" (
echo [WARNING] Frontend container is running, but Docker did not publish its browser port.
echo Recreating the frontend container to repair the port binding...
docker compose %COMPOSE_ENV_FILES% %COMPOSE_FILES% %COMPOSE_PROFILES_ARGS% up -d --force-recreate frontend
if errorlevel 1 (
echo [ERROR] Frontend recreate failed.
pause
exit /b 1
)
call :CheckComposePort frontend 80 DRAFT_TO_TAKE_FRONTEND_BINDING
if /I "%DRAFT_TO_TAKE_FRONTEND_BINDING%"=="invalid IP:0" set "DRAFT_TO_TAKE_FRONTEND_BINDING="
)
if "%DRAFT_TO_TAKE_FRONTEND_BINDING%"=="" (
echo [ERROR] Frontend container is healthy inside Docker, but no Windows browser port is published.
echo Try setting INDTEXTS_FRONTEND_HOST_PORT=3001 in .env, then run start.bat again.
echo If it still fails, run collect-diagnostics.bat and include the Compose PS section.
pause
exit /b 1
)
if "%DRAFT_TO_TAKE_OPEN_BROWSER%"=="" set "DRAFT_TO_TAKE_OPEN_BROWSER=true"
echo.
echo ============================================
echo Draft to Take beta is starting
echo ============================================
echo.
echo Frontend: http://localhost:%INDTEXTS_FRONTEND_HOST_PORT%
echo Backend: http://localhost:%INDTEXTS_BACKEND_HOST_PORT%
echo API Docs: http://localhost:%INDTEXTS_BACKEND_HOST_PORT%/docs
echo Shared: %DRAFT_TO_TAKE_SHARED_DIR%
echo Docker frontend binding: %DRAFT_TO_TAKE_FRONTEND_BINDING%
echo.
echo First start may download large models.
echo Keep this window open if you want to watch logs.
echo.
echo View logs: collect-diagnostics.bat or docker compose logs -f
echo Stop: stop.bat
echo ============================================
echo.
if /I not "%DRAFT_TO_TAKE_OPEN_BROWSER%"=="false" (
echo [INFO] Opening Draft to Take in your browser...
powershell -NoProfile -ExecutionPolicy Bypass -Command "Start-Process ('http://localhost:' + $env:INDTEXTS_FRONTEND_HOST_PORT)"
)
timeout /t 5 /nobreak >nul
docker compose %COMPOSE_ENV_FILES% %COMPOSE_FILES% %COMPOSE_PROFILES_ARGS% logs backend --tail 30
pause
exit /b 0
:ValidateEnvFile
set "DTT_ENV_FILE=%~f1"
powershell -NoProfile -ExecutionPolicy Bypass -Command "$path=$env:DTT_ENV_FILE; $badChars=[char[]](34,38,60,62,94,124); $lineNo=0; foreach ($line in Get-Content -LiteralPath $path -ErrorAction Stop) { $lineNo++; $trim=$line.Trim(); if ($trim -eq '' -or $trim.StartsWith('#')) { continue }; $eq=$line.IndexOf('='); if ($eq -lt 1) { continue }; $key=$line.Substring(0,$eq).Trim(); $value=$line.Substring($eq+1); $unsafe=$key -notmatch '^[A-Za-z_][A-Za-z0-9_]*$'; foreach ($ch in $badChars) { if ($value.Contains($ch)) { $unsafe=$true } }; if ($unsafe) { Write-Host ('[ERROR] Unsafe env entry on line {0}: {1}' -f $lineNo,$key); exit 2 } }; exit 0"
set "DTT_ENV_FILE="
exit /b %ERRORLEVEL%
:ValidateSharedDir
powershell -NoProfile -ExecutionPolicy Bypass -Command "$p=$env:DRAFT_TO_TAKE_SHARED_DIR; $badChars=[char[]](34,38,60,62,94,124); if ([string]::IsNullOrWhiteSpace($p)) { exit 1 }; foreach ($ch in $badChars) { if ($p.Contains($ch)) { exit 2 } }; try { [System.IO.Path]::GetFullPath($p) | Out-Null; exit 0 } catch { exit 3 }"
if errorlevel 1 (
echo [ERROR] DRAFT_TO_TAKE_SHARED_DIR is not a safe Windows folder path.
exit /b 1
)
exit /b 0
:ValidatePort
set "DTT_PORT_VAR=%~1"
set "DTT_PORT_FALLBACK=%~2"
powershell -NoProfile -ExecutionPolicy Bypass -Command "$name=$env:DTT_PORT_VAR; $p=[Environment]::GetEnvironmentVariable($name); $port=0; if (-not [string]::IsNullOrWhiteSpace($p) -and [int]::TryParse($p, [ref]$port) -and [string]$port -eq $p -and $port -ge 1 -and $port -le 65535) { exit 0 }; exit 2"
if errorlevel 1 (
echo [WARNING] Invalid %~1; using %~2.
set "%~1=%~2"
)
set "DTT_PORT_VAR="
set "DTT_PORT_FALLBACK="
exit /b 0
:CheckComposePort
set "%~3="
for /f "tokens=* delims=" %%i in ('docker compose %COMPOSE_ENV_FILES% %COMPOSE_FILES% %COMPOSE_PROFILES_ARGS% port %~1 %~2 2^>nul') do (
if not defined %~3 set "%~3=%%i"
)
exit /b 0
:PullService
set "DRAFT_TO_TAKE_PULL_SERVICE=%~1"
set /a DRAFT_TO_TAKE_PULL_ATTEMPT=1
:PullServiceAttempt
echo.
echo [INFO] Pulling %DRAFT_TO_TAKE_PULL_SERVICE% image (attempt %DRAFT_TO_TAKE_PULL_ATTEMPT%/%DRAFT_TO_TAKE_PULL_RETRIES%)...
docker compose %COMPOSE_ENV_FILES% %COMPOSE_FILES% %COMPOSE_PROFILES_ARGS% pull %DRAFT_TO_TAKE_PULL_SERVICE%
if not errorlevel 1 (
echo [OK] Pulled %DRAFT_TO_TAKE_PULL_SERVICE% image.
exit /b 0
)
if %DRAFT_TO_TAKE_PULL_ATTEMPT% GEQ %DRAFT_TO_TAKE_PULL_RETRIES% (
echo [ERROR] Could not pull %DRAFT_TO_TAKE_PULL_SERVICE% after %DRAFT_TO_TAKE_PULL_RETRIES% attempts.
exit /b 1
)
echo [WARNING] Pull failed for %DRAFT_TO_TAKE_PULL_SERVICE%; retrying in 10 seconds...
set /a DRAFT_TO_TAKE_PULL_ATTEMPT+=1
timeout /t 10 /nobreak >nul
goto PullServiceAttempt
:PullFailed
echo.
echo [ERROR] Docker image pull failed after retries.
echo The images are public, so docker login should not normally be required.
echo If the error was unexpected EOF, restart Docker Desktop and run start.bat again.
echo If containers later fail with exec format error, run repair-docker-images.bat.
pause
exit /b 1