PushToZhaoShang/scripts/deploy.ps1
2025-12-09 13:59:03 +08:00

26 lines
1.1 KiB
PowerShell

param(
[string]$RepoUrl = "",
[string]$Branch = "main",
[string]$RepoDir = ".",
[string]$ComposeFile = "docker-compose.yml",
[string]$BaseUrl = "http://localhost:57778",
[string]$AdminToken = ""
)
if (!(Test-Path $RepoDir)) { New-Item -ItemType Directory -Path $RepoDir | Out-Null }
if (!(Test-Path (Join-Path $RepoDir ".git"))) {
if ($RepoUrl -eq "") { throw "RepoUrl is required for clone" }
git clone -b $Branch $RepoUrl $RepoDir
}
Set-Location $RepoDir
git remote set-url origin $RepoUrl
git fetch origin
git checkout $Branch
git pull origin $Branch
if (!(Test-Path $ComposeFile)) { throw "compose not found: $ComposeFile" }
docker compose -f $ComposeFile up -d --build
$headers = @{}
if ($AdminToken -ne "") { $headers["X-Admin-Token"] = $AdminToken }
try { Invoke-RestMethod -Method Post -Uri "$BaseUrl/api/admin/reload_cutoff" -Headers $headers | Out-Null } catch { }
try { Invoke-RestMethod -Method Get -Uri "$BaseUrl/api/metrics" | ConvertTo-Json -Depth 3 | Write-Output } catch { }
try { Invoke-RestMethod -Method Post -Uri "$BaseUrl/api/admin/test_push" -Headers $headers | ConvertTo-Json -Depth 3 | Write-Output } catch { }