$ErrorActionPreference = "Stop" $repoRoot = "C:\Users\Administrator\.gemini\antigravity\scratch\ClassNotify" $sshKey = "C:\Users\Administrator\.ssh\id_rsa_tokyo" $vpsHost = "root@158.179.179.29" Write-Host "=== Step 1: Publishing ClassNotify.Server for linux-arm64 ===" -ForegroundColor Cyan $publishDir = Join-Path $repoRoot "bin\publish\Server-linux-arm64" if (Test-Path $publishDir) { Remove-Item -Recurse -Force $publishDir } dotnet publish (Join-Path $repoRoot "src\Server\ClassNotify.Server\ClassNotify.Server.csproj") ` -c Release -r linux-arm64 --self-contained false -o $publishDir Write-Host "=== Step 2: Creating tar.gz archive ===" -ForegroundColor Cyan $tarball = Join-Path $repoRoot "bin\publish\ClassNotify.Server-linux-arm64.tar.gz" if (Test-Path $tarball) { Remove-Item -Force $tarball } # Use tar to archive tar -czf $tarball -C $publishDir . $fileHash = (Get-FileHash -Path $tarball -Algorithm SHA256).Hash.ToLowerInvariant() Write-Host "Tarball SHA256: $fileHash" $timestamp = (Get-Date).ToString("yyyyMMdd-HHmmss") $shortHash = $fileHash.Substring(0, 8).ToUpperInvariant() $releaseId = "$timestamp-$shortHash" Write-Host "Target ReleaseId: $releaseId" Write-Host "=== Step 3: Copying deploy_server.sh and tarball to Tokyo VPS ===" -ForegroundColor Cyan scp -i $sshKey -o StrictHostKeyChecking=no (Join-Path $repoRoot "ops\deploy_server.sh") "${vpsHost}:/tmp/deploy_server.sh" ssh -i $sshKey -o StrictHostKeyChecking=no $vpsHost "chmod +x /tmp/deploy_server.sh" $remoteTarball = "/tmp/ClassNotify.Server-$releaseId.tar.gz" scp -i $sshKey -o StrictHostKeyChecking=no $tarball "${vpsHost}:${remoteTarball}" Write-Host "=== Step 4: Executing deploy_server.sh on Tokyo VPS ===" -ForegroundColor Cyan ssh -i $sshKey -o StrictHostKeyChecking=no $vpsHost "/tmp/deploy_server.sh '$releaseId' '$remoteTarball' '$fileHash'" Write-Host "=== Step 5: Checking Health Endpoint ===" -ForegroundColor Cyan Start-Sleep -Seconds 3 $health = Invoke-RestMethod -Uri "https://classnotify.paradise.eu.org/api/health" -TimeoutSec 10 Write-Host "Health check response: $($health | ConvertTo-Json -Compress)" if ($health.status -ne "Healthy" -or $health.database -ne "Connected") { throw "Health check failed: $($health | ConvertTo-Json)" } Write-Host "=== Deployment Succeeded! Release: $releaseId ===" -ForegroundColor Green