Files
2026-09-14 16:55:29 +02:00

61 lines
2.1 KiB
PowerShell

# ICON CRM - Deployment auf icrm.icon-experts.de (31.70.144.60)
#
# Gebaut wird lokal, hochgeladen werden nur dist/ und die Backend-Quellen.
#
# Aufruf aus dem Projektverzeichnis:
# $env:ICON_CRM_SSH_PASSWORD = '...'
# powershell -File deploy/deploy.ps1
# powershell -File deploy/deploy.ps1 -SkipBuild
# powershell -File deploy/deploy.ps1 -Deps # bei neuen Backend-Paketen
param(
[string]$ServerHost = '31.70.144.60',
[int]$Port = 22,
[string]$User = 'root',
[string]$Password = $env:ICON_CRM_SSH_PASSWORD,
[string]$RemotePath = '/var/www/icon_CRM',
[switch]$SkipBuild,
[switch]$Deps
)
$ErrorActionPreference = 'Stop'
if (-not $Password) {
throw 'Kein Passwort. Setze $env:ICON_CRM_SSH_PASSWORD oder uebergib -Password.'
}
$plink = 'C:\Program Files\PuTTY\plink.exe'
$pscp = 'C:\Program Files\PuTTY\pscp.exe'
foreach ($tool in @($plink, $pscp)) {
if (-not (Test-Path $tool)) { throw "Nicht gefunden: $tool" }
}
$projectRoot = Split-Path -Parent $PSScriptRoot
Set-Location $projectRoot
if (-not $SkipBuild) {
Write-Host '==> Frontend bauen' -ForegroundColor Yellow
npm run build
if ($LASTEXITCODE -ne 0) { throw 'Build fehlgeschlagen - es wird nichts hochgeladen.' }
}
$target = "$User@$ServerHost"
Write-Host '==> dist/ hochladen' -ForegroundColor Yellow
& $pscp -r -batch -P $Port -pw $Password 'dist' "${target}:$RemotePath/"
Write-Host '==> Backend hochladen' -ForegroundColor Yellow
& $pscp -r -batch -P $Port -pw $Password 'server\src' "${target}:$RemotePath/server/"
& $pscp -batch -P $Port -pw $Password 'server\package.json' "${target}:$RemotePath/server/"
$remoteCommand = "systemctl restart icon-crm-backend; sleep 3; systemctl is-active icon-crm-backend; curl -s http://127.0.0.1:5007/api/health"
if ($Deps) {
$remoteCommand = "cd $RemotePath/server && npm install --omit=dev --no-audit --no-fund; $remoteCommand"
}
Write-Host '==> Backend neu starten und pruefen' -ForegroundColor Yellow
& $plink -ssh -batch -P $Port -pw $Password $target $remoteCommand
Write-Host ''
Write-Host 'Fertig.' -ForegroundColor Green