feat: add Windows-first deployment flow

This commit is contained in:
admin committed 2026-08-20 10:21:44 +08:00
1 parent 7353d140b8
commit da01967c2e
5 files changed
+176 -31

No files matched your search

+106 -10
View File
@@ -1,15 +1,111 @@
param(
[switch]$NoFrontend,
[switch]$NoMediaMTX,
[switch]$InstallDeps,
[string]$HostAddress = "0.0.0.0",
[int]$BackendPort = 8080,
[int]$FrontendPort = 5173
)
$ErrorActionPreference = "Stop"
$Base = Split-Path -Parent $MyInvocation.MyCommand.Path
$BackendDir = Join-Path $Base "backend"
$FrontendDir = Join-Path $Base "frontend"
$MediaDir = Join-Path $Base "mediamtx"
$RuntimeDir = Join-Path $Base "runtime"
$HlsDir = Join-Path $RuntimeDir "hls"
$ReplayDir = Join-Path $RuntimeDir "replay"
$LogDir = Join-Path $RuntimeDir "logs"
Write-Host "[StreamCore] Starting backend..."
$Python = Join-Path $Base "backend\.venv\Scripts\python.exe"
if (-not (Test-Path $Python)) {
$Python = Join-Path $Base "backend\venv\Scripts\python.exe"
}
if (-not (Test-Path $Python)) {
throw "Python virtual environment not found. Create backend\.venv and install backend\requirements.txt."
New-Item -ItemType Directory -Force -Path $RuntimeDir, $HlsDir, $ReplayDir, $LogDir | Out-Null
if (-not $env:LS_HLS_RUNTIME_DIR) { $env:LS_HLS_RUNTIME_DIR = $HlsDir }
if (-not $env:LS_REPLAY_MEDIA_DIR) { $env:LS_REPLAY_MEDIA_DIR = $ReplayDir }
function Resolve-Python {
$candidates = @(
(Join-Path $BackendDir ".venv\Scripts\python.exe"),
(Join-Path $BackendDir "venv\Scripts\python.exe"),
"python",
"py"
)
foreach ($candidate in $candidates) {
if (Test-Path $candidate) { return $candidate }
$cmd = Get-Command $candidate -ErrorAction SilentlyContinue
if ($cmd) { return $cmd.Source }
}
throw "Python not found. Install Python 3.11+ or create backend\.venv."
}
Start-Process -FilePath $Python -ArgumentList "run.py" -WorkingDirectory (Join-Path $Base "backend")
Write-Host "[StreamCore] Backend started on http://127.0.0.1:8080"
Write-Host "Run npm install and npm run dev in frontend for the development UI."
function Assert-Command($Name, $Hint) {
if (-not (Get-Command $Name -ErrorAction SilentlyContinue)) {
throw "$Name not found. $Hint"
}
}
$Python = Resolve-Python
Assert-Command "npm" "Install Node.js LTS and make npm available in PATH."
Assert-Command "ffmpeg" "Install FFmpeg and make ffmpeg.exe available in PATH."
if (-not $NoMediaMTX) {
Assert-Command "mediamtx" "Install MediaMTX and make mediamtx.exe available in PATH, or run with -NoMediaMTX."
}
if ($InstallDeps) {
Write-Host "[StreamCore] Installing backend dependencies..."
Push-Location $BackendDir
& $Python -m pip install -r requirements.txt
Pop-Location
if (-not $NoFrontend) {
Write-Host "[StreamCore] Installing frontend dependencies..."
Push-Location $FrontendDir
npm install
Pop-Location
}
}
$processes = @()
if (-not $NoMediaMTX) {
Write-Host "[StreamCore] Starting MediaMTX origin on RTMP :1935 and HLS :8888..."
$processes += Start-Process -FilePath "mediamtx" -ArgumentList "mediamtx.yml" -WorkingDirectory $MediaDir -PassThru -RedirectStandardOutput (Join-Path $LogDir "mediamtx.out.log") -RedirectStandardError (Join-Path $LogDir "mediamtx.err.log")
}
Write-Host "[StreamCore] Starting backend on ${HostAddress}:${BackendPort} ..."
$backendArgs = @("-m", "uvicorn", "main:app", "--host", $HostAddress, "--port", "$BackendPort")
$processes += Start-Process -FilePath $Python -ArgumentList $backendArgs -WorkingDirectory $BackendDir -PassThru -RedirectStandardOutput (Join-Path $LogDir "backend.out.log") -RedirectStandardError (Join-Path $LogDir "backend.err.log")
if (-not $NoFrontend) {
Write-Host "[StreamCore] Starting frontend on ${HostAddress}:${FrontendPort} ..."
$frontendArgs = @("run", "dev", "--", "--host", $HostAddress, "--port", "$FrontendPort")
$processes += Start-Process -FilePath "npm" -ArgumentList $frontendArgs -WorkingDirectory $FrontendDir -PassThru -RedirectStandardOutput (Join-Path $LogDir "frontend.out.log") -RedirectStandardError (Join-Path $LogDir "frontend.err.log")
}
Start-Sleep -Seconds 3
Write-Host ""
Write-Host "[StreamCore] Windows deployment started."
Write-Host " Backend: http://127.0.0.1:$BackendPort/docs"
if (-not $NoFrontend) { Write-Host " Frontend: http://127.0.0.1:$FrontendPort/" }
if (-not $NoMediaMTX) {
Write-Host " RTMP: rtmp://127.0.0.1:1935/live/<stream_key>"
Write-Host " HLS: http://127.0.0.1:8888/<stream_key>/index.m3u8"
}
Write-Host " Runtime: $RuntimeDir"
Write-Host " HLS dir: $env:LS_HLS_RUNTIME_DIR"
Write-Host " Logs: $LogDir"
Write-Host ""
Write-Host "Press Ctrl+C to stop child processes."
try {
while ($true) {
foreach ($proc in $processes) {
if ($proc.HasExited) {
throw "Process $($proc.Id) exited with code $($proc.ExitCode). Check logs in $LogDir."
}
}
Start-Sleep -Seconds 2
}
} finally {
Write-Host "[StreamCore] Stopping child processes..."
foreach ($proc in $processes) {
if (-not $proc.HasExited) { Stop-Process -Id $proc.Id -Force -ErrorAction SilentlyContinue }
}
}