<# .SYNOPSIS Builds the combined standalone server: one self-contained binary serving the WebUI (static SPA), the API, the /messaging WebSocket relay, and supervising a bundled nats-server sidecar. Produces a zip per platform. Quick start on the target machine: unzip, run `ExecuteR-Server setup`, then run the binary (or `ExecuteR-Server service install`); the first start records a one-time admin password in data/initial-admin-password.txt (administrators only). .EXAMPLE ./scripts/Package-Server.ps1 # win-x64 + linux-x64 ./scripts/Package-Server.ps1 -Runtimes win-x64 # single platform #> [CmdletBinding()] param( [string]$Version, [string[]]$Runtimes = @('win-x64', 'linux-x64'), [switch]$SkipNats, [switch]$SkipObjectStore, [switch]$SkipMsi ) $ErrorActionPreference = 'Stop' $repoRoot = Split-Path -Parent $PSScriptRoot $Version = & (Join-Path $PSScriptRoot 'Get-Version.ps1') -Version $Version # The MSI ProductVersion takes four fields: a release X.Y.Z is X.Y.Z.0. $fileVersion = & (Join-Path $PSScriptRoot 'Get-Version.ps1') -Version $Version -Format FileVersion $short = & (Join-Path $PSScriptRoot 'Get-Version.ps1') -Version $Version -Format Short $artifacts = Join-Path $repoRoot 'artifacts' $natsVersion = '2.14.4' Write-Host "Packaging standalone server $Version for: $($Runtimes -join ', ')" # ── WebUI static SPA build (shared by every platform) ─────────────────────── Push-Location (Join-Path $repoRoot 'src/WebUI') try { if (-not (Test-Path 'node_modules')) { npm ci } $env:PUBLIC_BUILD_VERSION = $Version npm run build if ($LASTEXITCODE -ne 0) { throw "WebUI static build failed ($LASTEXITCODE)." } } finally { Remove-Item Env:\PUBLIC_BUILD_VERSION -ErrorAction SilentlyContinue Pop-Location } $staticBuild = Join-Path $repoRoot 'src/WebUI/dist' if (-not (Test-Path (Join-Path $staticBuild 'index.html'))) { throw "Static WebUI build missing at $staticBuild" } foreach ($rid in $Runtimes) { $publishDir = Join-Path $artifacts "server/$Version/$rid" if (Test-Path $publishDir) { Remove-Item $publishDir -Recurse -Force } # ── Self-contained single-file server ─────────────────────────────────── dotnet publish (Join-Path $repoRoot 'src/Backend/Backend.csproj') ` -c Release -r $rid --self-contained ` -p:PublishSingleFile=true ` -p:DebugType=None ` -p:UnifiedVersion=$Version ` "-p:GitCommitShort=$short" ` -o $publishDir if ($LASTEXITCODE -ne 0) { throw "dotnet publish for $rid failed ($LASTEXITCODE)." } # Shipping bundles carry no debug symbols or build-time asset manifests. Get-ChildItem $publishDir -Filter '*.pdb' -Recurse | Remove-Item -Force Remove-Item (Join-Path $publishDir 'Backend.staticwebassets.endpoints.json') -ErrorAction SilentlyContinue # Single-file apphosts tolerate renames; ship a recognizable binary name. if ($rid -like 'win-*') { Rename-Item (Join-Path $publishDir 'Backend.exe') 'ExecuteR-Server.exe' } else { Rename-Item (Join-Path $publishDir 'Backend') 'ExecuteR-Server' } # ── Embed the WebUI ────────────────────────────────────────────────────── Copy-Item $staticBuild (Join-Path $publishDir 'wwwroot') -Recurse # ── Bundle the agent installers so URL install works out of the box ───── $agentStage = Join-Path $publishDir 'agent-package' New-Item -ItemType Directory -Force $agentStage | Out-Null $agentMsi = Join-Path $artifacts "ExecuteR-Agent-$Version.msi" $agentZip = Join-Path $artifacts "ExecuteR-Agent-$Version-win-x64.zip" $staged = $false if (Test-Path $agentMsi) { Copy-Item $agentMsi (Join-Path $agentStage 'Agent.msi'); $staged = $true } if (Test-Path $agentZip) { Copy-Item $agentZip (Join-Path $agentStage 'Agent.zip'); $staged = $true } foreach ($unixRid in 'linux-x64', 'linux-arm64', 'osx-x64', 'osx-arm64') { $unixZip = Join-Path $artifacts "ExecuteR-Agent-$Version-$unixRid.zip" if (Test-Path $unixZip) { Copy-Item $unixZip (Join-Path $agentStage "Agent-$unixRid.zip"); $staged = $true } } if ($staged) { $Version | Set-Content (Join-Path $agentStage 'VERSION') -NoNewline } else { Write-Warning "No agent artifacts for $Version found — run Package-Agent first for a complete bundle." } # ── Bundle nats-server for the sidecar ─────────────────────────────────── if (-not $SkipNats) { $natsDir = Join-Path $publishDir 'nats' New-Item -ItemType Directory -Force $natsDir | Out-Null $platform = if ($rid -eq 'win-x64') { 'windows-amd64' } elseif ($rid -eq 'linux-x64') { 'linux-amd64' } elseif ($rid -eq 'linux-arm64') { 'linux-arm64' } elseif ($rid -eq 'osx-x64') { 'darwin-amd64' } elseif ($rid -eq 'osx-arm64') { 'darwin-arm64' } else { throw "No nats-server mapping for RID $rid" } $archiveExt = if ($rid -like 'win-*') { 'zip' } else { 'tar.gz' } $cache = Join-Path $artifacts "cache/nats-server-v$natsVersion-$platform.$archiveExt" if (-not (Test-Path $cache)) { New-Item -ItemType Directory -Force (Split-Path $cache) | Out-Null $url = "https://github.com/nats-io/nats-server/releases/download/v$natsVersion/nats-server-v$natsVersion-$platform.$archiveExt" Write-Host "Downloading $url" Invoke-WebRequest -Uri $url -OutFile $cache -UseBasicParsing } $extract = Join-Path $artifacts "cache/nats-extract-$platform" if (Test-Path $extract) { Remove-Item $extract -Recurse -Force } New-Item -ItemType Directory -Force $extract | Out-Null if ($archiveExt -eq 'zip') { Expand-Archive -Path $cache -DestinationPath $extract -Force } else { tar -xzf $cache -C $extract } $binaryName = if ($rid -like 'win-*') { 'nats-server.exe' } else { 'nats-server' } $binary = Get-ChildItem $extract -Recurse -Filter $binaryName | Select-Object -First 1 if (-not $binary) { throw "nats-server binary not found in $cache" } Copy-Item $binary.FullName (Join-Path $natsDir $binaryName) } # ── Bundle the object store the server runs for built-in S3 ───────────── if (-not $SkipObjectStore) { & (Join-Path $PSScriptRoot 'Get-ObjectStore.ps1') -Runtime $rid -Destination (Join-Path $publishDir 'object-store') | Out-Null } # ── Quick-start note ───────────────────────────────────────────────────── $exeName = if ($rid -like 'win-*') { 'ExecuteR-Server.exe' } else { './ExecuteR-Server' } Set-Content (Join-Path $publishDir 'QUICKSTART.txt') @" ExecuteR standalone server $Version ($rid) 1. $exeName setup Generates NATS keys, the sidecar config and appsettings.json with the admin/admin sign-in (override with --admin-user/--admin-password; change the password after the first sign-in either way). For extra instances on the same box use one directory each with distinct ports (--http-port/--nats-port/--nats-ws-port/--nats-monitor-port) and `service install --name `. Self-Signed TLS is ON by default: the server serves HTTPS with a managed, auto-renewed chain so this hop is encrypted (--tls 0 opts out). Reverse proxies either skip verification (not insecure — the roots simply are not distributed, the traffic is still encrypted) or import the root and intermediate to establish trust, re-importing when they rotate at expiry. Follow your organization's security standards. The Add-Device modal offers a skip-verify checkbox for agents, pre-selected only while serving the self-signed chain directly. 2. $exeName Serves the UI + API on http://0.0.0.0:9080 with the NATS sidecar. ...or run in the background: $exeName service install (Windows service / systemd unit) $exeName service uninstall S3 works immediately too: the server runs a built-in store (./object-store) with its files beside the database. S3_EMBEDDED=0 turns it off. Agent installers ship in ./agent-package, so the URL install command works immediately. Put a TLS-terminating reverse proxy in front for production use; agents enroll against the same base URL. Configuration = flat keys in appsettings.json next to the binary, or environment variables (either works; env wins). Forwarded headers are trusted by default from private networks (loopback/RFC1918/CGNAT) — behind a typical proxy nothing needs setting. Optional keys generated for you: TLS_SELF_SIGNED (built-in hop encryption, on by default — 0 disables), TLS_CERT_DIR, PUBLIC_SERVER_URL (pin the public base URL), TRUSTED_NETWORKS (replace the default trust with an allow-list), TRUSTED_HOSTS, TRUST_PROXY=0 to disable. "@ # Licence terms and third-party notices travel with every package. Copy-Item (Join-Path $repoRoot 'LICENSE'), (Join-Path $repoRoot 'THIRD-PARTY-NOTICES.md') $publishDir # ── Zip it ─────────────────────────────────────────────────────────────── $zipPath = Join-Path $artifacts "ExecuteR-Server-$Version-$rid.zip" if (Test-Path $zipPath) { Remove-Item $zipPath -Force } Compress-Archive -Path (Join-Path $publishDir '*') -DestinationPath $zipPath Write-Host "Created $zipPath" } # ── Server MSI (win-x64): admin-account wizard + service install ──────────── $serverWix = Join-Path $repoRoot 'src/Installer.Server/Server.Installer.wixproj' $winPublish = Join-Path $artifacts "server/$Version/win-x64" if (-not $SkipMsi -and (Test-Path $serverWix) -and (Test-Path $winPublish)) { # ProductVersion is the four-field version, as for the agent MSI. Write-Host "Server MSI ProductVersion: $fileVersion" # The longest file path below the install folder: the MSI holds the install # folder to what still keeps every file within MAX_PATH (ServerChoices). $rootLength = (Resolve-Path $winPublish).Path.TrimEnd('\').Length + 1 $longest = (Get-ChildItem $winPublish -Recurse -File | ForEach-Object { $_.FullName.Length - $rootLength } | Measure-Object -Maximum).Maximum Write-Host "Longest path in the server bundle: $longest characters" dotnet build $serverWix -c Release --nologo ` "-p:UnifiedVersion=$Version" ` "-p:MsiProductVersion=$fileVersion" ` "-p:ServerPublishDir=$winPublish" ` "-p:ServerLongestRelativePath=$longest" if ($LASTEXITCODE -ne 0) { throw "Server MSI build failed ($LASTEXITCODE)." } $msi = Get-ChildItem (Join-Path $repoRoot 'src/Installer.Server/bin/Release') -Filter '*.msi' -Recurse | Sort-Object LastWriteTimeUtc -Descending | Select-Object -First 1 if ($msi) { $msiTarget = Join-Path $artifacts "ExecuteR-Server-$Version.msi" Copy-Item $msi.FullName $msiTarget -Force Write-Host "Created $msiTarget" } } # The built-in store's licence entitles everyone who receives it to its source. if (-not $SkipObjectStore) { $objectStoreSource = & (Join-Path $PSScriptRoot 'Get-ObjectStore.ps1') -Source Copy-Item $objectStoreSource (Join-Path $artifacts "ExecuteR-Server-$Version-object-store-source.tar.gz") -Force } # Checksums for release attachment. $checksums = Join-Path $artifacts "ExecuteR-Server-$Version-checksums.txt" # This version's files only: 1.4.0's pattern must not take 1.4.0.7's. $ownFile = '^ExecuteR-Server-' + [regex]::Escape($Version) + '(-.+\.zip|-object-store-source\.tar\.gz|\.msi)$' Get-ChildItem $artifacts -File | Where-Object { $_.Name -match $ownFile } | ForEach-Object { "{0} {1}" -f (Get-FileHash $_.FullName -Algorithm SHA256).Hash.ToLowerInvariant(), $_.Name } | Set-Content $checksums -Encoding utf8NoBOM Write-Host "Created $checksums" Get-ChildItem $artifacts -Filter "ExecuteR-Server-$Version-*.zip" | Select-Object Name, Length