deploy-test / build-and-deploy-test (push) Successful in 2m41s
Phase 3: 管理后台前端 (Vue3+Vite+Element Plus) - 登录页面/JWT认证/Pinia状态管理 - 首页大盘/站点管理/验证码日志/IP黑名单/套餐管理/系统设置 - 7个页面完整路由+API对接 Phase 4: 统计监控模块 - CaptchaLogAspect AOP自动记录 - RealtimeStatsService Redis实时计数 - HistoryStatsService 历史查询 - AnomalyDetectionService 异常检测 Phase 5: 部署和测试 - docker-compose.yml 5服务编排 - application-prod.yml 外部化配置 - CaptchaApiIntegrationTest 集成测试 - 前端 Dockerfile + nginx.conf
119 lines
4.6 KiB
PowerShell
119 lines
4.6 KiB
PowerShell
$ErrorActionPreference = "Stop"
|
|
|
|
$JAVA_HOME = "C:\Users\USER879511\.jdks\ms-21.0.11"
|
|
$MVN = "D:\Middleware\environment\apache-maven-3.9.16\bin\mvn.cmd"
|
|
$PG_PSQL = "D:\Middleware\gostgresql\bin\psql.exe"
|
|
$PG_PASSWORD = "XGYnJPysCNJsLeea"
|
|
$PROJECT_DIR = "D:\tianai-captcha-enhanced"
|
|
$JAR_PATH = "$PROJECT_DIR\tianai-captcha-platform\target\tianai-captcha-platform-2.0.0-SNAPSHOT.jar"
|
|
$PID_FILE = "$PROJECT_DIR\captcha-platform.pid"
|
|
$LOG_FILE = "$PROJECT_DIR\captcha-platform.log"
|
|
$DB_NAME = "captcha_forge"
|
|
|
|
function Ensure-Database {
|
|
Write-Host "[1/3] Checking database '$DB_NAME'..." -ForegroundColor Cyan
|
|
$env:PGPASSWORD = $PG_PASSWORD
|
|
$result = & $PG_PSQL -U postgres -h localhost -t -c "SELECT 1 FROM pg_database WHERE datname = '$DB_NAME'" 2>&1
|
|
if ($result -match "1 row" -or $result -match "1") {
|
|
Write-Host " Database '$DB_NAME' exists." -ForegroundColor Green
|
|
} else {
|
|
& $PG_PSQL -U postgres -h localhost -c "CREATE DATABASE $DB_NAME" 2>&1
|
|
Write-Host " Database '$DB_NAME' created." -ForegroundColor Green
|
|
}
|
|
}
|
|
|
|
function Build-Project {
|
|
Write-Host "[2/3] Building project..." -ForegroundColor Cyan
|
|
$env:JAVA_HOME = $JAVA_HOME
|
|
& $MVN -f "$PROJECT_DIR\pom.xml" package -DskipTests -q
|
|
if ($LASTEXITCODE -ne 0) {
|
|
Write-Host " BUILD FAILED!" -ForegroundColor Red
|
|
exit 1
|
|
}
|
|
Write-Host " Build successful." -ForegroundColor Green
|
|
}
|
|
|
|
function Start-Platform {
|
|
Write-Host "[3/3] Starting captcha platform..." -ForegroundColor Cyan
|
|
|
|
if (Test-Path $PID_FILE) {
|
|
$oldPid = Get-Content $PID_FILE
|
|
$oldProc = Get-Process -Id $oldPid -ErrorAction SilentlyContinue
|
|
if ($oldProc) {
|
|
Write-Host " Stopping old process (PID $oldPid)..." -ForegroundColor Yellow
|
|
Stop-Process -Id $oldPid -Force
|
|
Start-Sleep -Seconds 2
|
|
}
|
|
Remove-Item $PID_FILE -Force
|
|
}
|
|
|
|
$env:JAVA_HOME = $JAVA_HOME
|
|
$env:PATH = "$JAVA_HOME\bin;$env:PATH"
|
|
|
|
$proc = Start-Process -FilePath "$JAVA_HOME\bin\java.exe" `
|
|
-ArgumentList "-jar", $JAR_PATH, `
|
|
"--spring.datasource.url=jdbc:postgresql://localhost:5432/$DB_NAME", `
|
|
"--spring.datasource.password=$PG_PASSWORD", `
|
|
"--spring.sql.init.mode=always" `
|
|
-RedirectStandardOutput $LOG_FILE `
|
|
-RedirectStandardError "$PROJECT_DIR\captcha-platform-err.log" `
|
|
-NoNewWindow -PassThru
|
|
|
|
$proc.Id | Set-Content $PID_FILE
|
|
Write-Host " Started! PID=$($proc.Id)" -ForegroundColor Green
|
|
Write-Host " Log: $LOG_FILE" -ForegroundColor Gray
|
|
Write-Host ""
|
|
Write-Host " Waiting for startup (max 60s)..." -ForegroundColor Yellow
|
|
|
|
for ($i = 0; $i -lt 30; $i++) {
|
|
Start-Sleep -Seconds 2
|
|
try {
|
|
$resp = Invoke-WebRequest -Uri "http://localhost:18109/api/admin/sites" -Method GET -ErrorAction Stop
|
|
Write-Host ""
|
|
Write-Host " Platform is UP!" -ForegroundColor Green
|
|
Write-Host " API: http://localhost:18109/api" -ForegroundColor Cyan
|
|
Write-Host " Site: http://localhost:18109/api/challenge/generate" -ForegroundColor Cyan
|
|
Write-Host ""
|
|
Write-Host " Existing sites in DB:" -ForegroundColor Yellow
|
|
$env:PGPASSWORD = $PG_PASSWORD
|
|
& $PG_PSQL -U postgres -h localhost -d $DB_NAME -c "SELECT id, name, domain, site_key, verify_level, is_enabled FROM sites" 2>&1
|
|
return
|
|
} catch {}
|
|
Write-Host "." -NoNewline
|
|
}
|
|
Write-Host ""
|
|
Write-Host " Startup may still be in progress. Check: $LOG_FILE" -ForegroundColor Yellow
|
|
}
|
|
|
|
function Stop-Platform {
|
|
Write-Host "Stopping captcha platform..." -ForegroundColor Yellow
|
|
if (Test-Path $PID_FILE) {
|
|
$pid = Get-Content $PID_FILE
|
|
$proc = Get-Process -Id $pid -ErrorAction SilentlyContinue
|
|
if ($proc) {
|
|
Stop-Process -Id $pid -Force
|
|
Write-Host " Stopped (PID $pid)." -ForegroundColor Green
|
|
} else {
|
|
Write-Host " Process not running." -ForegroundColor Gray
|
|
}
|
|
Remove-Item $PID_FILE -Force
|
|
} else {
|
|
Write-Host " No PID file found." -ForegroundColor Gray
|
|
}
|
|
}
|
|
|
|
Write-Host ""
|
|
Write-Host "============================================" -ForegroundColor Cyan
|
|
Write-Host " tianai-captcha-enhanced Launcher v2.0.0" -ForegroundColor Cyan
|
|
Write-Host " JDK 21 | Spring Boot 3.4 | PostgreSQL" -ForegroundColor Gray
|
|
Write-Host "============================================" -ForegroundColor Cyan
|
|
Write-Host ""
|
|
|
|
if ($args[0] -eq "stop") {
|
|
Stop-Platform
|
|
} else {
|
|
Ensure-Database
|
|
Build-Project
|
|
Start-Platform
|
|
}
|