현재 작업 상태 저장
This commit is contained in:
parent
07cc67761e
commit
6bd91b0d5e
674 changed files with 8726 additions and 298 deletions
|
|
@ -1,21 +1,28 @@
|
|||
param(
|
||||
param(
|
||||
[string]$Workspace = "D:\workspace\vignette",
|
||||
[int]$ApiPort = 8001,
|
||||
[int]$WebPort = 5174,
|
||||
[int]$EnginePort = 9099,
|
||||
[string]$Python = "$env:LOCALAPPDATA\Programs\Python\Python311\python.exe",
|
||||
[string]$Cloudflared = "$env:LOCALAPPDATA\Microsoft\WinGet\Links\cloudflared.exe",
|
||||
[string]$CloudflaredConfig = "$env:USERPROFILE\.cloudflared\vignette-config.yml",
|
||||
[switch]$SkipEngineRestart,
|
||||
[switch]$SkipWebRestart,
|
||||
[switch]$RouteCloudflareDns,
|
||||
[string]$CloudflareTunnelName = "vignette",
|
||||
[switch]$SkipCloudflaredRestart
|
||||
)
|
||||
|
||||
$ErrorActionPreference = "Stop"
|
||||
|
||||
$ApiDir = Join-Path $Workspace "apps\api"
|
||||
$WebDir = Join-Path $Workspace "apps\web"
|
||||
$OutLog = Join-Path $ApiDir "api.public.out.log"
|
||||
$ErrLog = Join-Path $ApiDir "api.public.err.log"
|
||||
$EngineOutLog = Join-Path $ApiDir "engine.public.out.log"
|
||||
$EngineErrLog = Join-Path $ApiDir "engine.public.err.log"
|
||||
$WebOutLog = Join-Path $Workspace "web.public.out.log"
|
||||
$WebErrLog = Join-Path $Workspace "web.public.err.log"
|
||||
|
||||
function Get-JsonHealth {
|
||||
param(
|
||||
|
|
@ -49,6 +56,27 @@ function Wait-JsonHealth {
|
|||
throw "Timed out waiting for healthy response from $Uri"
|
||||
}
|
||||
|
||||
function Wait-HttpStatus {
|
||||
param(
|
||||
[string]$Uri,
|
||||
[int]$TimeoutSec = 30
|
||||
)
|
||||
|
||||
$deadline = (Get-Date).AddSeconds($TimeoutSec)
|
||||
do {
|
||||
try {
|
||||
$response = Invoke-WebRequest -UseBasicParsing -Uri $Uri -TimeoutSec 5
|
||||
if ($response.StatusCode -ge 200 -and $response.StatusCode -lt 500) {
|
||||
return $response
|
||||
}
|
||||
} catch {
|
||||
Start-Sleep -Seconds 1
|
||||
}
|
||||
} while ((Get-Date) -lt $deadline)
|
||||
|
||||
throw "Timed out waiting for HTTP response from $Uri"
|
||||
}
|
||||
|
||||
function Stop-UvicornByPort {
|
||||
param(
|
||||
[string]$AppImport,
|
||||
|
|
@ -64,12 +92,72 @@ function Stop-UvicornByPort {
|
|||
ForEach-Object { Stop-Process -Id $_.ProcessId -Force }
|
||||
}
|
||||
|
||||
function Stop-NodeByPortHint {
|
||||
param([int]$Port)
|
||||
|
||||
Get-CimInstance Win32_Process |
|
||||
Where-Object {
|
||||
$_.Name -eq "node.exe" -and
|
||||
$_.CommandLine -and
|
||||
$_.CommandLine -like "*vite*preview*" -and
|
||||
$_.CommandLine -like "*$Port*"
|
||||
} |
|
||||
ForEach-Object { Stop-Process -Id $_.ProcessId -Force }
|
||||
}
|
||||
|
||||
function ConvertTo-CompactJson {
|
||||
param([object]$Value)
|
||||
ConvertTo-Json -InputObject $Value -Compress
|
||||
}
|
||||
|
||||
function Set-CloudflaredIngress {
|
||||
param(
|
||||
[string]$ConfigPath,
|
||||
[string[]]$ApiHostnames,
|
||||
[string[]]$WebHostnames,
|
||||
[int]$ApiPortValue,
|
||||
[int]$WebPortValue
|
||||
)
|
||||
|
||||
$lines = Get-Content -Encoding UTF8 -Path $ConfigPath
|
||||
$ingressIndex = -1
|
||||
for ($i = 0; $i -lt $lines.Count; $i++) {
|
||||
if ($lines[$i] -match "^\s*ingress:\s*$") {
|
||||
$ingressIndex = $i
|
||||
break
|
||||
}
|
||||
}
|
||||
if ($ingressIndex -lt 0) {
|
||||
throw "Could not find ingress: in $ConfigPath"
|
||||
}
|
||||
|
||||
$nextLines = @()
|
||||
if ($ingressIndex -gt 0) {
|
||||
$nextLines += $lines[0..($ingressIndex - 1)]
|
||||
}
|
||||
$nextLines += "ingress:"
|
||||
foreach ($hostname in $WebHostnames) {
|
||||
$nextLines += " - hostname: $hostname"
|
||||
$nextLines += " service: http://127.0.0.1:$WebPortValue"
|
||||
}
|
||||
foreach ($hostname in $ApiHostnames) {
|
||||
$nextLines += " - hostname: $hostname"
|
||||
$nextLines += " service: http://127.0.0.1:$ApiPortValue"
|
||||
}
|
||||
$nextLines += " - service: http_status:404"
|
||||
|
||||
Set-Content -Encoding UTF8 -Path $ConfigPath -Value $nextLines
|
||||
}
|
||||
|
||||
if (!(Test-Path $Python)) {
|
||||
throw "Python 3.11 not found at $Python"
|
||||
}
|
||||
if (!(Test-Path $ApiDir)) {
|
||||
throw "API directory not found at $ApiDir"
|
||||
}
|
||||
if (!(Test-Path $WebDir)) {
|
||||
throw "Web directory not found at $WebDir"
|
||||
}
|
||||
|
||||
$engineHealth = Get-JsonHealth -Uri "http://127.0.0.1:$EnginePort/health"
|
||||
if ($SkipEngineRestart) {
|
||||
|
|
@ -101,7 +189,17 @@ $env:AUTH_DEV_LOGIN_ENABLED = "false"
|
|||
$env:AUTO_SEED_PERSONAS = "false"
|
||||
$env:ALLOW_SEED_PERSONA_FALLBACK = "false"
|
||||
$env:FRONTEND_BASE_URL = "https://vignette.chanpaca.net"
|
||||
$env:CORS_ORIGINS = '["https://vignette.chanpaca.net","https://vignette-b1q.pages.dev","http://localhost:5170","http://localhost:5171","http://localhost:5172","http://localhost:5173","http://localhost:5174","http://localhost:5175","http://localhost:5176","http://localhost:5177","http://localhost:5178","http://localhost:5179","http://localhost:5180","http://127.0.0.1:5170","http://127.0.0.1:5171","http://127.0.0.1:5172","http://127.0.0.1:5173","http://127.0.0.1:5174","http://127.0.0.1:5175","http://127.0.0.1:5176","http://127.0.0.1:5177","http://127.0.0.1:5178","http://127.0.0.1:5179","http://127.0.0.1:5180"]'
|
||||
$frontendOrigins = @("https://vignette.chanpaca.net", "https://vnet.18ka.net", "https://vignette-b1q.pages.dev")
|
||||
$localViteOrigins = @()
|
||||
foreach ($port in 5170..5180) {
|
||||
$localViteOrigins += "http://localhost:$port"
|
||||
$localViteOrigins += "http://127.0.0.1:$port"
|
||||
}
|
||||
$env:CORS_ORIGINS = ConvertTo-CompactJson -Value ($frontendOrigins + $localViteOrigins)
|
||||
$env:FRONTEND_ORIGIN_MAP = ConvertTo-CompactJson -Value ([ordered]@{
|
||||
"api-vignette.chanpaca.net" = "https://vignette.chanpaca.net"
|
||||
"api-vnet.18ka.net" = "https://vnet.18ka.net"
|
||||
})
|
||||
|
||||
$proc = Start-Process -WindowStyle Hidden -FilePath $Python `
|
||||
-ArgumentList @("-m", "uvicorn", "app.main:app", "--host", "127.0.0.1", "--port", "$ApiPort") `
|
||||
|
|
@ -119,6 +217,29 @@ if ($health.environment -ne "prod" -or -not $health.db -or -not $health.engine)
|
|||
throw "Public API health is not production-safe: $($health | ConvertTo-Json -Compress)"
|
||||
}
|
||||
|
||||
if (!$SkipWebRestart) {
|
||||
Stop-NodeByPortHint -Port $WebPort
|
||||
|
||||
$build = Start-Process -FilePath "cmd.exe" `
|
||||
-ArgumentList @("/c", "npm run build") `
|
||||
-WorkingDirectory $WebDir `
|
||||
-NoNewWindow `
|
||||
-Wait `
|
||||
-PassThru
|
||||
if ($build.ExitCode -ne 0) {
|
||||
throw "Web build failed with exit code $($build.ExitCode)"
|
||||
}
|
||||
|
||||
Start-Process -WindowStyle Hidden -FilePath "cmd.exe" `
|
||||
-ArgumentList @("/c", "npm run preview -- --host 127.0.0.1 --port $WebPort") `
|
||||
-WorkingDirectory $WebDir `
|
||||
-RedirectStandardOutput $WebOutLog `
|
||||
-RedirectStandardError $WebErrLog `
|
||||
-PassThru | Out-Null
|
||||
|
||||
Wait-HttpStatus -Uri "http://127.0.0.1:$WebPort/" -TimeoutSec 30 | Out-Null
|
||||
}
|
||||
|
||||
if (!$SkipCloudflaredRestart) {
|
||||
if (!(Test-Path $Cloudflared)) {
|
||||
throw "cloudflared not found at $Cloudflared"
|
||||
|
|
@ -127,30 +248,24 @@ if (!$SkipCloudflaredRestart) {
|
|||
throw "cloudflared config not found at $CloudflaredConfig"
|
||||
}
|
||||
|
||||
$lines = Get-Content $CloudflaredConfig
|
||||
$insideApiIngress = $false
|
||||
$updated = $false
|
||||
$nextLines = foreach ($line in $lines) {
|
||||
if ($line -match "hostname:\s*api-vignette\.chanpaca\.net") {
|
||||
$insideApiIngress = $true
|
||||
$line
|
||||
continue
|
||||
$apiHostnames = @("api-vignette.chanpaca.net", "api-vnet.18ka.net")
|
||||
$webHostnames = @("vnet.18ka.net")
|
||||
|
||||
if ($RouteCloudflareDns) {
|
||||
foreach ($hostname in ($webHostnames + $apiHostnames)) {
|
||||
& $Cloudflared tunnel route dns $CloudflareTunnelName $hostname
|
||||
if ($LASTEXITCODE -ne 0) {
|
||||
Write-Warning "cloudflared DNS route failed for $hostname"
|
||||
}
|
||||
}
|
||||
if ($insideApiIngress -and $line -match "^\s*service:\s*http://127\.0\.0\.1:\d+\s*$") {
|
||||
$updated = $true
|
||||
$insideApiIngress = $false
|
||||
" service: http://127.0.0.1:$ApiPort"
|
||||
continue
|
||||
}
|
||||
if ($insideApiIngress -and $line -match "^\s*-\s+") {
|
||||
$insideApiIngress = $false
|
||||
}
|
||||
$line
|
||||
}
|
||||
if (!$updated) {
|
||||
throw "Could not find api-vignette.chanpaca.net localhost service in $CloudflaredConfig"
|
||||
}
|
||||
Set-Content -Encoding UTF8 -Path $CloudflaredConfig -Value $nextLines
|
||||
|
||||
Set-CloudflaredIngress `
|
||||
-ConfigPath $CloudflaredConfig `
|
||||
-ApiHostnames $apiHostnames `
|
||||
-WebHostnames $webHostnames `
|
||||
-ApiPortValue $ApiPort `
|
||||
-WebPortValue $WebPort
|
||||
|
||||
Get-CimInstance Win32_Process |
|
||||
Where-Object { $_.Name -eq "cloudflared.exe" -and $_.CommandLine -like "*vignette-config.yml*" } |
|
||||
|
|
@ -166,4 +281,7 @@ if (!$SkipCloudflaredRestart) {
|
|||
|
||||
Write-Output "Engine gateway healthy on http://127.0.0.1:$EnginePort"
|
||||
Write-Output "Public API running on http://127.0.0.1:$ApiPort with PID $($proc.Id)"
|
||||
if (!$SkipWebRestart) {
|
||||
Write-Output "Public vnet web preview running on http://127.0.0.1:$WebPort"
|
||||
}
|
||||
Write-Output "Health: $($health | ConvertTo-Json -Compress)"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue