Repository navigation
Expand file tree
/
Copy pathstart.ps1
More file actions
342 lines (294 loc) · 10.6 KB
/
Copy pathstart.ps1
File metadata and controls
342 lines (294 loc) · 10.6 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
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
#!/usr/bin/env pwsh
# 1proxy Platform Startup Script for Windows
# This script starts the entire 1proxy platform with all required services
param(
[switch]$Docker,
[switch]$Local,
[switch]$Help
)
# Color output functions
function Write-Success { param($msg) Write-Host "✅ $msg" -ForegroundColor Green }
function Write-Info { param($msg) Write-Host "ℹ️ $msg" -ForegroundColor Cyan }
function Write-Warning { param($msg) Write-Host "⚠️ $msg" -ForegroundColor Yellow }
function Write-Error { param($msg) Write-Host "❌ $msg" -ForegroundColor Red }
function Write-Header { param($msg) Write-Host "`n🚀 $msg" -ForegroundColor Magenta }
# Help message
if ($Help) {
Write-Host @"
1proxy Platform Startup Script
USAGE:
.\start.ps1 [-Docker] [-Local] [-Help]
OPTIONS:
-Docker Start using Docker Compose (recommended)
-Local Start locally (requires Python 3.12+ and Node.js 18+)
-Help Show this help message
EXAMPLES:
.\start.ps1 -Docker # Start with Docker
.\start.ps1 -Local # Start locally
.\start.ps1 # Interactive mode (asks which method)
REQUIREMENTS:
Docker mode: Docker Desktop installed and running
Local mode: Python 3.12+, Node.js 18+, pip, npm
"@
exit 0
}
# Determine startup mode
$mode = $null
if ($Docker) { $mode = "docker" }
elseif ($Local) { $mode = "local" }
else {
Write-Header "1proxy Platform Startup"
Write-Host ""
Write-Host "Select startup mode:"
Write-Host " [1] Docker Compose (recommended)"
Write-Host " [2] Local Development"
Write-Host " [3] Exit"
Write-Host ""
$choice = Read-Host "Enter choice (1-3)"
switch ($choice) {
"1" { $mode = "docker" }
"2" { $mode = "local" }
"3" { exit 0 }
default {
Write-Error "Invalid choice. Exiting."
exit 1
}
}
}
# Change to project root
$projectRoot = Split-Path -Parent $MyInvocation.MyCommand.Path
Set-Location $projectRoot
Write-Header "Starting 1proxy Platform in $mode mode..."
# ============================================================================
# DOCKER MODE
# ============================================================================
if ($mode -eq "docker") {
Write-Info "Checking Docker installation..."
# Check if Docker is installed
try {
$dockerVersion = docker --version
Write-Success "Docker found: $dockerVersion"
}
catch {
Write-Error "Docker is not installed or not in PATH"
Write-Info "Please install Docker Desktop from: https://www.docker.com/products/docker-desktop"
exit 1
}
# Check if Docker is running
try {
docker ps | Out-Null
Write-Success "Docker daemon is running"
}
catch {
Write-Error "Docker daemon is not running"
Write-Info "Please start Docker Desktop and try again"
exit 1
}
# Check if docker-compose.yml exists
if (-not (Test-Path "docker-compose.yml")) {
Write-Error "docker-compose.yml not found in current directory"
exit 1
}
# Check for .env file
if (-not (Test-Path ".env")) {
Write-Warning ".env file not found"
if (Test-Path ".env.example") {
Write-Info "Creating .env from .env.example..."
Copy-Item ".env.example" ".env"
Write-Warning "Please edit .env file with your OAuth credentials before continuing"
Write-Info "Press any key to continue after editing .env..."
$null = $Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")
}
}
Write-Info "Starting Docker Compose services..."
Write-Host ""
# Start Docker Compose
docker-compose up --build -d
if ($LASTEXITCODE -eq 0) {
Write-Host ""
Write-Success "Docker services started successfully!"
Write-Host ""
Write-Info "Waiting for services to be ready..."
Start-Sleep -Seconds 5
# Check service health
Write-Info "Checking service status..."
docker-compose ps
Write-Host ""
Write-Success "1proxy Platform is running!"
Write-Host ""
Write-Host "🌐 Frontend: http://localhost:3000" -ForegroundColor Cyan
Write-Host "🔧 Backend API: http://localhost:8000" -ForegroundColor Cyan
Write-Host "📚 API Docs: http://localhost:8000/docs" -ForegroundColor Cyan
Write-Host "🗄️ Redis: localhost:6379" -ForegroundColor Cyan
Write-Host ""
Write-Info "To view logs: docker-compose logs -f"
Write-Info "To stop: docker-compose down"
Write-Host ""
}
else {
Write-Error "Failed to start Docker services"
Write-Info "Check logs with: docker-compose logs"
exit 1
}
}
# ============================================================================
# LOCAL MODE
# ============================================================================
elseif ($mode -eq "local") {
Write-Info "Checking prerequisites..."
# Check Python
try {
$pythonVersion = python --version 2>&1
Write-Success "Python found: $pythonVersion"
}
catch {
Write-Error "Python is not installed or not in PATH"
Write-Info "Please install Python 3.12+ from: https://www.python.org/downloads/"
exit 1
}
# Check Node.js
try {
$nodeVersion = node --version
Write-Success "Node.js found: $nodeVersion"
}
catch {
Write-Error "Node.js is not installed or not in PATH"
Write-Info "Please install Node.js 18+ from: https://nodejs.org/"
exit 1
}
# Check npm
try {
$npmVersion = npm --version
Write-Success "npm found: v$npmVersion"
}
catch {
Write-Error "npm is not installed or not in PATH"
exit 1
}
Write-Host ""
Write-Header "Setting up Backend..."
# Copy .env from root to backend if it exists
if (Test-Path ".env") {
Write-Info "Copying .env to backend directory..."
Copy-Item ".env" "1proxy-backend\.env" -Force
Write-Success ".env synced to backend"
}
elseif (-not (Test-Path "1proxy-backend\.env")) {
Write-Warning "No .env file found. OAuth features will not work."
Write-Info "Copy .env.example to .env and configure your credentials"
}
# Backend setup
Set-Location "1proxy-backend"
# Check if venv exists
if (-not (Test-Path "venv")) {
Write-Info "Creating Python virtual environment..."
python -m venv venv
}
# Activate venv
Write-Info "Activating virtual environment..."
& ".\venv\Scripts\Activate.ps1"
# Upgrade pip first
Write-Info "Upgrading pip..."
python -m pip install --upgrade pip --quiet
# Install dependencies
if (-not (Test-Path "venv\Lib\site-packages\fastapi")) {
Write-Info "Installing Python dependencies..."
pip install -r requirements.txt
if ($LASTEXITCODE -ne 0) {
Write-Error "Failed to install Python dependencies"
Write-Info "Cleaning up virtual environment..."
Set-Location $projectRoot
Remove-Item "1proxy-backend\venv" -Recurse -Force -ErrorAction SilentlyContinue
Write-Info "Please run the script again to recreate the virtual environment"
exit 1
}
}
else {
Write-Success "Python dependencies already installed"
}
# Check if database exists
if (-not (Test-Path "data\1proxy.db")) {
Write-Info "Running database migrations..."
alembic upgrade head
}
else {
Write-Success "Database already exists"
}
# Start backend in background
Write-Info "Starting FastAPI backend..."
$backendJob = Start-Job -ScriptBlock {
param($path)
Set-Location $path
& ".\venv\Scripts\Activate.ps1"
python run.py
} -ArgumentList (Get-Location).Path
Write-Success "Backend started (Job ID: $($backendJob.Id))"
# Wait for backend to be ready
Write-Info "Waiting for backend to be ready..."
Start-Sleep -Seconds 5
# Frontend setup
Set-Location "$projectRoot\1proxy-frontend"
Write-Host ""
Write-Header "Setting up Frontend..."
# Install dependencies
if (-not (Test-Path "node_modules")) {
Write-Info "Installing Node.js dependencies..."
npm install
}
else {
Write-Success "Node.js dependencies already installed"
}
# Start frontend in background
Write-Info "Starting Next.js frontend..."
$env:NEXT_PUBLIC_API_URL = "http://localhost:8000"
$frontendJob = Start-Job -ScriptBlock {
param($path)
Set-Location $path
$env:NEXT_PUBLIC_API_URL = "http://localhost:8000"
npm run dev
} -ArgumentList (Get-Location).Path
Write-Success "Frontend started (Job ID: $($frontendJob.Id))"
# Return to project root
Set-Location $projectRoot
Write-Host ""
Write-Success "1proxy Platform is running!"
Write-Host ""
Write-Host "🌐 Frontend: http://localhost:3000" -ForegroundColor Cyan
Write-Host "🔧 Backend API: http://localhost:8000" -ForegroundColor Cyan
Write-Host "📚 API Docs: http://localhost:8000/docs" -ForegroundColor Cyan
Write-Host ""
Write-Info "Backend Job ID: $($backendJob.Id)"
Write-Info "Frontend Job ID: $($frontendJob.Id)"
Write-Host ""
Write-Warning "Press Ctrl+C to stop all services"
Write-Host ""
# Monitor jobs
try {
while ($true) {
Start-Sleep -Seconds 2
# Check if jobs are still running
$backendState = (Get-Job -Id $backendJob.Id).State
$frontendState = (Get-Job -Id $frontendJob.Id).State
if ($backendState -eq "Failed") {
Write-Error "Backend job failed!"
Receive-Job -Id $backendJob.Id
break
}
if ($frontendState -eq "Failed") {
Write-Error "Frontend job failed!"
Receive-Job -Id $frontendJob.Id
break
}
}
}
finally {
# Cleanup
Write-Host ""
Write-Info "Stopping services..."
Stop-Job -Id $backendJob.Id -ErrorAction SilentlyContinue
Stop-Job -Id $frontendJob.Id -ErrorAction SilentlyContinue
Remove-Job -Id $backendJob.Id -Force -ErrorAction SilentlyContinue
Remove-Job -Id $frontendJob.Id -Force -ErrorAction SilentlyContinue
Write-Success "All services stopped"
}
}