Fix Gjallar deploy and command ownership

This commit is contained in:
Meta Vens 2026-06-17 15:55:13 +01:00
commit 89b48462fd
6 changed files with 342 additions and 57 deletions

View file

@ -1,5 +1,7 @@
param(
[string] $GjallarRoot = "E:\Projects\Gjallar",
[string] $CultLibRoot = "E:\Projects\CultLib",
[string] $CultMathRoot = "E:\Projects\CultMath",
[string] $SshTarget = "nwroot",
[string] $RemoteDir = "/opt/gamecult/gjallar",
[string] $CultCachePath = "/var/lib/gamecult/gjallar/cultcache/gjallar.service.cc",
@ -13,6 +15,45 @@ param(
$ErrorActionPreference = "Stop"
function Remove-ScratchPath {
param(
[string] $ScratchRoot,
[string] $TargetPath
)
if (-not (Test-Path -LiteralPath $TargetPath)) {
return
}
$resolvedScratch = (Resolve-Path -LiteralPath $ScratchRoot).Path
$resolvedTarget = (Resolve-Path -LiteralPath $TargetPath).Path
if (-not $resolvedTarget.StartsWith($resolvedScratch, [StringComparison]::OrdinalIgnoreCase)) {
throw "Refusing to remove scratch path outside scratch root: $resolvedTarget"
}
Remove-Item -LiteralPath $TargetPath -Recurse -Force
}
function Export-GitArchive {
param(
[string] $RepoRoot,
[string] $Ref,
[string] $Destination,
[string] $TarPath
)
Remove-ScratchPath -ScratchRoot (Split-Path -Parent $Destination) -TargetPath $Destination
New-Item -ItemType Directory -Force -Path $Destination | Out-Null
git -C $RepoRoot archive --format=tar --output=$TarPath $Ref
if ($LASTEXITCODE -ne 0) {
throw "git archive failed for $RepoRoot $Ref"
}
tar -xf $TarPath -C $Destination
if ($LASTEXITCODE -ne 0) {
throw "source extraction failed for $TarPath"
}
}
if ($env:IDUNN_ACTUATOR -ne "1") {
throw "This deployment script is an Idunn actuator. Agents must configure Idunn release targets and let Idunn run deployment; do not invoke deploy scripts manually."
}
@ -20,7 +61,11 @@ if ($env:IDUNN_ACTUATOR -ne "1") {
$sourceRef = "$UpstreamRemote/$UpstreamBranch"
$scratchRoot = Join-Path $GjallarRoot "scratch"
$releaseSource = Join-Path $scratchRoot "idunn-release-source"
$cultLibRelease = Join-Path $scratchRoot "CultLib"
$cultMathRelease = Join-Path $scratchRoot "CultMath"
$releaseTarPath = Join-Path $scratchRoot "gjallar-source-release.tar"
$cultLibTarPath = Join-Path $scratchRoot "cultlib-source-release.tar"
$cultMathTarPath = Join-Path $scratchRoot "cultmath-source-release.tar"
$publishDir = Join-Path $scratchRoot "publish\gjallar"
$tarPath = Join-Path $GjallarRoot "scratch\gjallar-publish.tar"
$projectPath = Join-Path $releaseSource "src\Gjallar\Gjallar.csproj"
@ -36,24 +81,21 @@ if ([string]::IsNullOrWhiteSpace($commit)) {
throw "Could not determine Gjallar git revision."
}
$cultLibCommit = (git -C $CultLibRoot rev-parse HEAD).Trim()
if ([string]::IsNullOrWhiteSpace($cultLibCommit)) {
throw "Could not determine CultLib git revision."
}
$cultMathCommit = (git -C $CultMathRoot rev-parse HEAD).Trim()
if ([string]::IsNullOrWhiteSpace($cultMathCommit)) {
throw "Could not determine CultMath git revision."
}
New-Item -ItemType Directory -Force -Path $scratchRoot | Out-Null
if (Test-Path -LiteralPath $releaseSource) {
$resolvedScratch = (Resolve-Path -LiteralPath $scratchRoot).Path
$resolvedRelease = (Resolve-Path -LiteralPath $releaseSource).Path
if (-not $resolvedRelease.StartsWith($resolvedScratch, [StringComparison]::OrdinalIgnoreCase)) {
throw "Refusing to remove release source outside scratch: $resolvedRelease"
}
Remove-Item -LiteralPath $releaseSource -Recurse -Force
}
New-Item -ItemType Directory -Force -Path $releaseSource | Out-Null
git -C $GjallarRoot archive --format=tar --output=$releaseTarPath $sourceRef
if ($LASTEXITCODE -ne 0) {
throw "git archive failed for $GjallarRoot $sourceRef"
}
tar -xf $releaseTarPath -C $releaseSource
if ($LASTEXITCODE -ne 0) {
throw "source extraction failed for $releaseTarPath"
}
Remove-ScratchPath -ScratchRoot $scratchRoot -TargetPath $publishDir
Export-GitArchive -RepoRoot $GjallarRoot -Ref $sourceRef -Destination $releaseSource -TarPath $releaseTarPath
Export-GitArchive -RepoRoot $CultLibRoot -Ref $cultLibCommit -Destination $cultLibRelease -TarPath $cultLibTarPath
Export-GitArchive -RepoRoot $CultMathRoot -Ref $cultMathCommit -Destination $cultMathRelease -TarPath $cultMathTarPath
dotnet publish $projectPath -c Release -r linux-x64 --self-contained true -o $publishDir
if ($LASTEXITCODE -ne 0) {
@ -69,6 +111,8 @@ $deployedAt = [DateTimeOffset]::UtcNow.ToString("O")
"upstreamBranch=$UpstreamBranch"
"sourceRef=$sourceRef"
"gitCommit=$commit"
"cultLibCommit=$cultLibCommit"
"cultMathCommit=$cultMathCommit"
"artifact=Gjallar.dll"
"sha256=$hash"
"deployedAtUtc=$deployedAt"

View file

@ -72,6 +72,22 @@ if ($null -eq $status.cultCacheWitness -or $status.cultCacheWitness.status -ne "
Fail-IdunnHealth -State "degraded" -Message "Nightwing Gjallar has not published the daemon-owned CultCache witness. $detail"
}
if ([string]::IsNullOrWhiteSpace([string]$status.receive.lastAttemptStatus)) {
Fail-IdunnHealth -State "failed" -Message "Nightwing Gjallar status witness is missing receive.lastAttemptStatus."
}
if ([string]::IsNullOrWhiteSpace([string]$status.receive.lastSuccessfulAtUtc)) {
Fail-IdunnHealth -State "failed" -Message "Nightwing Gjallar status witness is missing receive.lastSuccessfulAtUtc."
}
if ([int]$status.receive.staleAfterSeconds -le 0) {
Fail-IdunnHealth -State "failed" -Message "Nightwing Gjallar status witness has invalid receive.staleAfterSeconds=$($status.receive.staleAfterSeconds)."
}
if ($null -eq $status.receive.consecutiveFailures) {
Fail-IdunnHealth -State "failed" -Message "Nightwing Gjallar status witness is missing receive.consecutiveFailures."
}
if ($status.receive.status -ne "catalog-composed") {
$detail = $status.receive.error
if ([string]::IsNullOrWhiteSpace($detail)) {

View file

@ -32,9 +32,9 @@ $IdunnDeploymentTargets = @(
Host = "nightwing"
Service = "gjallar.service"
Status = "enforced"
Health = "$repoRoot\scripts\health-nightwing-gjallar.cmd"
Deploy = "$repoRoot\scripts\deploy-nightwing-gjallar.cmd"
Restart = "$repoRoot\scripts\restart-nightwing-gjallar.cmd"
Health = "$repoRoot\scripts\health-nightwing-gjallar.ps1"
Deploy = "$repoRoot\scripts\deploy-nightwing-gjallar.ps1"
Restart = "$repoRoot\scripts\restart-nightwing-gjallar.ps1"
UpstreamRemote = "origin"
UpstreamBranch = "main"
RolloutStrategy = "restart-after-verified-build"

View file

@ -1,2 +1,2 @@
@echo off
ssh.exe -o BatchMode=yes -o ConnectTimeout=5 nwroot systemctl restart gjallar.service
powershell.exe -NoProfile -ExecutionPolicy Bypass -File E:\Projects\Odin\scripts\restart-nightwing-gjallar.ps1

View file

@ -0,0 +1,13 @@
param(
[string] $SshTarget = "nwroot",
[string] $Service = "gjallar.service"
)
$ErrorActionPreference = "Stop"
ssh.exe -o BatchMode=yes -o ConnectTimeout=5 $SshTarget "systemctl restart $Service && systemctl is-active --quiet $Service"
if ($LASTEXITCODE -ne 0) {
throw "Remote restart failed for $Service on $SshTarget with exit code $LASTEXITCODE"
}
Write-Host "Restarted $Service on $SshTarget."