-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.bat
More file actions
195 lines (177 loc) · 6.4 KB
/
Copy pathsetup.bat
File metadata and controls
195 lines (177 loc) · 6.4 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
@echo off
setlocal EnableDelayedExpansion
:: ---------------------------------------------------------------------------
:: BGSTM One-Command Setup Script (Windows)
:: ---------------------------------------------------------------------------
echo.
echo ██████ ██████ ███████ ████████ ███ ███
echo ██ ██ ██ ██ ██ ████ ████
echo ██████ ██ ███ ███████ ██ ██ ████ ██
echo ██ ██ ██ ██ ██ ██ ██ ██ ██
echo ██████ ██████ ███████ ██ ██ ██
echo.
echo BGSTM One-Command Installer
echo -------------------------------------------------
echo.
:: ---------------------------------------------------------------------------
:: 1. Check requirements: Docker
:: ---------------------------------------------------------------------------
echo [INFO] Checking requirements...
where docker >nul 2>&1
if %ERRORLEVEL% NEQ 0 (
echo [ERROR] Docker is not installed.
echo.
echo Please install Docker Desktop:
echo https://docs.docker.com/desktop/install/windows-install/
echo.
pause
exit /b 1
)
docker info >nul 2>&1
if %ERRORLEVEL% NEQ 0 (
echo [ERROR] Docker daemon is not running.
echo Please start Docker Desktop and try again.
echo.
pause
exit /b 1
)
:: Support both 'docker compose' (v2) and 'docker-compose' (v1)
set DC=docker compose
docker compose version >nul 2>&1
if %ERRORLEVEL% NEQ 0 (
where docker-compose >nul 2>&1
if %ERRORLEVEL% NEQ 0 (
echo [ERROR] Docker Compose is not available.
echo.
echo Please install Docker Desktop ^(which includes Docker Compose^):
echo https://docs.docker.com/desktop/install/windows-install/
echo.
pause
exit /b 1
)
set DC=docker-compose
)
for /f "tokens=3" %%v in ('docker --version') do (
set DOCKER_VER=%%v
)
set DOCKER_VER=!DOCKER_VER:,=!
echo [OK] Docker !DOCKER_VER! and Docker Compose found.
:: ---------------------------------------------------------------------------
:: 2. Copy .env.example -> .env (idempotent)
:: ---------------------------------------------------------------------------
cd /d "%~dp0"
if exist ".env" (
echo [WARN] .env already exists -- skipping copy ^(using existing file^).
) else (
if not exist ".env.example" (
echo [ERROR] .env.example not found.
echo Are you running this script from the BGSTM root directory?
pause
exit /b 1
)
copy ".env.example" ".env" >nul
echo [OK] Created .env from .env.example.
)
:: ---------------------------------------------------------------------------
:: 3. Start all services
:: ---------------------------------------------------------------------------
echo [INFO] Starting services with Docker Compose...
echo ^(this may take a few minutes on first run^)
echo.
%DC% up -d --build
if %ERRORLEVEL% NEQ 0 (
echo [ERROR] Docker Compose failed to start services.
echo Check the output above for details.
pause
exit /b 1
)
echo [OK] Docker Compose services started.
:: ---------------------------------------------------------------------------
:: 4. Health checks
:: ---------------------------------------------------------------------------
set TIMEOUT=120
set INTERVAL=5
echo [INFO] Waiting for Backend API to be ready...
call :wait_for "http://localhost:8000/health" %TIMEOUT% %INTERVAL%
if %ERRORLEVEL% NEQ 0 (
echo [ERROR] Backend API did not become ready within %TIMEOUT%s.
echo.
echo Troubleshooting tips:
echo - Check logs: %DC% logs -f
echo - Common cause: port 8000 already in use
echo - Try: %DC% down ^&^& %DC% up -d --build
pause
exit /b 1
)
echo [OK] Backend API is ready.
echo [INFO] Waiting for Frontend to be ready...
call :wait_for "http://localhost" %TIMEOUT% %INTERVAL%
if %ERRORLEVEL% NEQ 0 (
echo [ERROR] Frontend did not become ready within %TIMEOUT%s.
echo.
echo Troubleshooting tips:
echo - Check logs: %DC% logs -f
echo - Common cause: port 80 already in use
echo - Try: %DC% down ^&^& %DC% up -d --build
pause
exit /b 1
)
echo [OK] Frontend is ready.
:: ---------------------------------------------------------------------------
:: 5. Optional: load sample data
:: ---------------------------------------------------------------------------
echo.
set /p LOAD_SAMPLE="Load sample data? (y/n) "
echo.
if /i "!LOAD_SAMPLE!"=="y" (
echo [INFO] Loading sample data...
%DC% exec backend python -m app.db.sample_data
if %ERRORLEVEL% NEQ 0 (
echo [WARN] Sample data load encountered an error.
echo You can try again later with:
echo %DC% exec backend python -m app.db.sample_data
) else (
echo [OK] Sample data loaded.
)
) else (
echo [INFO] Skipping sample data.
)
:: ---------------------------------------------------------------------------
:: 6. Open browser
:: ---------------------------------------------------------------------------
echo [INFO] Opening browser at http://localhost ...
start "" "http://localhost"
:: ---------------------------------------------------------------------------
:: 7. Summary
:: ---------------------------------------------------------------------------
echo.
echo ================================================
echo BGSTM is up and running!
echo ================================================
echo.
echo Frontend: http://localhost
echo Backend API: http://localhost:8000
echo API Docs: http://localhost:8000/docs
echo.
echo Stop services: %DC% down
echo View logs: %DC% logs -f
echo.
pause
exit /b 0
:: ---------------------------------------------------------------------------
:: Subroutine: wait_for <url> <timeout_seconds> <interval_seconds>
:: Returns 0 on success, 1 on timeout
:: ---------------------------------------------------------------------------
:wait_for
set _URL=%~1
set _TIMEOUT=%~2
set _INTERVAL=%~3
set _ELAPSED=0
:wait_loop
curl -sf --max-time 3 "%_URL%" >nul 2>&1
if %ERRORLEVEL% EQU 0 exit /b 0
if !_ELAPSED! GEQ %_TIMEOUT% exit /b 1
timeout /t %_INTERVAL% /nobreak >nul
set /a _ELAPSED=!_ELAPSED!+%_INTERVAL%
echo ... !_ELAPSED!s / %_TIMEOUT%s
goto wait_loop