Files
lucashahmann f98785b26a
Deploy Hugo Site / deploy (push) Canceled after 0s
Deploy Script Windows
2026-10-19 22:16:44 +02:00

64 lines
2.2 KiB
PowerShell

# Baut die Seite lokal und lädt sie auf den Webserver.
# Ersetzt den Gitea-Workflow (.gitea/workflows/deploy.yml) für manuelle Deploys.
#
# .\deploy.ps1 # bauen und hochladen
# .\deploy.ps1 -DryRun # nur bauen und packen, nichts hochladen
# .\deploy.ps1 -Key C:\pfad\zum\key # bestimmten SSH-Key verwenden
# # (Standard: ~\.ssh\deepwater_deploy, falls vorhanden)
param(
[string]$Server = "webserver.hahmann-trier.local",
[int]$Port = 8147,
[string]$User = "gitea-deploy",
[string]$Target = "/var/www/www-deepwatersurvival-de",
[string]$Key = "",
[switch]$DryRun
)
$ErrorActionPreference = "Stop"
Set-Location $PSScriptRoot
function Assert-Ok($step) {
if ($LASTEXITCODE -ne 0) { throw "$step fehlgeschlagen (Exit-Code $LASTEXITCODE)" }
}
$defaultKey = Join-Path $HOME ".ssh\deepwater_deploy"
if (-not $Key -and (Test-Path $defaultKey)) { $Key = $defaultKey }
$sshOpts = @("-o", "StrictHostKeyChecking=accept-new")
if ($Key) { $sshOpts += @("-i", $Key) }
Write-Host "1/4 Baue Seite mit Hugo ..."
hugo --minify --cleanDestinationDir
Assert-Ok "Hugo-Build"
Write-Host "2/4 Packe public/ ..."
$archive = Join-Path $env:TEMP "deepwatersurvival-site.tgz"
& "$env:SystemRoot\System32\tar.exe" -czf $archive -C public .
Assert-Ok "Packen"
Write-Host (" {0:N1} MB" -f ((Get-Item $archive).Length / 1MB))
if ($DryRun) {
Write-Host "DryRun: nichts hochgeladen. Archiv liegt unter $archive"
exit 0
}
$stamp = Get-Date -Format "yyyyMMddHHmmss"
$remoteDir = "/tmp/deepwatersurvival-$stamp"
$remote = "$User@$Server"
Write-Host "3/4 Lade hoch nach $remote ..."
scp -P $Port @sshOpts $archive "${remote}:$remoteDir.tgz"
Assert-Ok "Upload"
Write-Host "4/4 Entpacke und gleiche $Target ab ..."
# rsync --delete entfernt auf dem Server Dateien, die es lokal nicht mehr gibt (wie im Workflow).
$remoteCmd = "set -e; mkdir -p $remoteDir; tar -xzf $remoteDir.tgz -C $remoteDir; " +
"rsync -rt --delete --chmod=D755,F644 $remoteDir/ $Target/; " +
"rm -rf $remoteDir $remoteDir.tgz"
ssh -p $Port @sshOpts $remote $remoteCmd
Assert-Ok "Abgleich auf dem Server"
Remove-Item $archive
Write-Host "Fertig: https://www.deepwatersurvival.de/"