Files
MijnBesluit/tools/SocketServer-publiceren.ps1
T

73 lines
2.6 KiB
PowerShell

<#
.SYNOPSIS
Publiceert MijnBesluit.SocketServer en pakt het in als één zip-bestand.
.DESCRIPTION
Draai dit op je ontwikkelmachine. Het resultaat is D:\MijnBesluit VS\MijnBesluitpublish\mijnbesluit-socketserver.zip.
Dat bestand kopieer je naar de server en pak je daar uit; installeren gaat daarna met het
schermpje van de exe zelf (rechtermuis -> Als administrator uitvoeren -> Install).
Zie docs\SocketServer-installeren.md voor de stappen op de server.
.EXAMPLE
.\tools\SocketServer-publiceren.ps1
#>
[CmdletBinding()]
param(
[string] $Uitvoer = 'D:\MijnBesluit VS\MijnBesluitpublish',
[ValidateSet('Release', 'Debug')]
[string] $Configuratie = 'Release',
[switch] $GeenZip
)
$ErrorActionPreference = 'Stop'
$Project = Join-Path (Split-Path $PSScriptRoot -Parent) 'src\MijnBesluit.SocketServer'
$DoelMap = Join-Path $Uitvoer 'mijnbesluit-socketserver'
$ZipPad = Join-Path $Uitvoer 'mijnbesluit-socketserver.zip'
if (-not (Test-Path $Project)) {
throw "Projectmap niet gevonden: $Project."
}
Write-Host ''
Write-Host 'SocketServer publiceren' -ForegroundColor Cyan
Write-Host " Uitvoer : $DoelMap"
Write-Host ''
if (Test-Path $DoelMap) {
Write-Host 'Vorige publicatie opruimen...'
Remove-Item $DoelMap -Recurse -Force
}
# 64 bits, en niet self-contained: op de server staat .NET 8 al vanwege het Hosting Bundle.
dotnet publish $Project -c $Configuratie -r win-x64 --self-contained false -o $DoelMap --nologo
if ($LASTEXITCODE -ne 0) { throw 'Publiceren is mislukt. Zie de fouten hierboven.' }
foreach ($nodig in @('MijnBesluit.SocketServer.exe', 'appsettings.json')) {
if (-not (Test-Path (Join-Path $DoelMap $nodig))) {
throw "Er ontbreekt iets in de publicatie: $nodig"
}
}
# Controle die je anders pas op de server ontdekt: staat het wachtwoord er nog als voorbeeld in,
# dan is ExtraConfigFile de plek waar het echte wachtwoord vandaan moet komen.
$instellingen = Get-Content (Join-Path $DoelMap 'appsettings.json') -Raw | ConvertFrom-Json
if ($instellingen.ConnectionStrings.MijnBesluit -match 'VERVANG_DIT' -and
[string]::IsNullOrWhiteSpace($instellingen.ExtraConfigFile)) {
throw 'Er staat geen wachtwoord in appsettings.json en ook geen ExtraConfigFile. Zo start de service niet.'
}
if (-not $GeenZip) {
if (Test-Path $ZipPad) { Remove-Item $ZipPad -Force }
Compress-Archive -Path (Join-Path $DoelMap '*') -DestinationPath $ZipPad
Write-Host ''
Write-Host "Klaar: $ZipPad" -ForegroundColor Green
Write-Host 'Kopieer dit naar de server, pak het uit, en start de exe als administrator.'
} else {
Write-Host ''
Write-Host "Klaar: $DoelMap" -ForegroundColor Green
}