57 lines
2.3 KiB
PowerShell
57 lines
2.3 KiB
PowerShell
[CmdletBinding()]
|
|
param(
|
|
[Parameter(Mandatory)]
|
|
[ValidatePattern('^[0-9a-f]{40}$')]
|
|
[string]$Revision,
|
|
[string]$DockerContext = 'docker-prod',
|
|
[string]$LocalManifestPath = "$env:LOCALAPPDATA\Domovoy\monitoring\deployment-manifest.json",
|
|
[string]$NasManifestPath = '\\nas\MST\codex\_monitoring\domovoy\deployment-manifest.json',
|
|
[string[]]$ExpectedContainers = @(
|
|
'assistant-postgres-1',
|
|
'assistant-notification-receiver-1',
|
|
'assistant-core-runtime-1',
|
|
'assistant-continuity-runtime-1',
|
|
'assistant-commit-runtime-1',
|
|
'assistant-cognitive-worker-1',
|
|
'assistant-creator-web-1'
|
|
)
|
|
)
|
|
|
|
$ErrorActionPreference = 'Stop'
|
|
Set-StrictMode -Version Latest
|
|
|
|
function Write-AtomicJson([string]$Path, [string]$Json) {
|
|
$directory = Split-Path -Parent $Path
|
|
New-Item -ItemType Directory -Force -Path $directory | Out-Null
|
|
$partial = Join-Path $directory ('.' + [IO.Path]::GetFileName($Path) + ".${PID}.partial")
|
|
try {
|
|
[IO.File]::WriteAllText($partial, $Json + "`n", [Text.UTF8Encoding]::new($false))
|
|
Move-Item -LiteralPath $partial -Destination $Path -Force
|
|
}
|
|
finally {
|
|
if (Test-Path -LiteralPath $partial) { Remove-Item -LiteralPath $partial -Force }
|
|
}
|
|
}
|
|
|
|
$artifacts = foreach ($container in $ExpectedContainers) {
|
|
$raw = ((& docker.exe --context $DockerContext inspect $container --format '{{json .}}') -join '').Trim()
|
|
if ($LASTEXITCODE -ne 0 -or [string]::IsNullOrWhiteSpace($raw)) { throw "Cannot inspect $container" }
|
|
$inspect = $raw | ConvertFrom-Json
|
|
$actual = [string]$inspect.Config.Labels.'org.opencontainers.image.revision'
|
|
if ($actual -ne $Revision) { throw "$container revision mismatch: expected=$Revision actual=$actual" }
|
|
if ($inspect.State.Status -ne 'running') { throw "$container is not running" }
|
|
[ordered]@{ container = $container; image_id = [string]$inspect.Image; revision = $actual }
|
|
}
|
|
|
|
$manifest = [ordered]@{
|
|
version = 1
|
|
project = 'domovoy'
|
|
revision = $Revision
|
|
promoted_at_utc = [DateTime]::UtcNow.ToString('o')
|
|
artifacts = @($artifacts)
|
|
}
|
|
$json = $manifest | ConvertTo-Json -Depth 5
|
|
Write-AtomicJson $LocalManifestPath $json
|
|
Write-AtomicJson $NasManifestPath $json
|
|
Write-Output "Production artifact confirmed: revision=$Revision containers=$($artifacts.Count)"
|