Files
jobboard/deploy/_common.ps1
T

33 lines
1.5 KiB
PowerShell

# Dot-sourced by 2-build-image.ps1 and 3-push-image.ps1. Reads deploy\release.env
# beside it (KEY=VALUE lines, # comments, never run as code) into $Settings,
# and works out where step 1 exported the release: release\<folder> beside the
# checkout, in the distro, seen from Windows through \\wsl.localhost.
$ErrorActionPreference = 'Stop'
$envFile = Join-Path $PSScriptRoot 'release.env'
if (-not (Test-Path $envFile)) { throw "no $envFile - copy release.env.example and fill it in" }
$Settings = @{}
foreach ($line in Get-Content $envFile) {
if ($line -match '^\s*(#|$)') { continue }
$key, $value = $line -split '=', 2
$Settings[$key.Trim()] = "$value".Trim().Trim('"')
}
foreach ($key in 'DISTRO', 'CHECKOUT', 'IMAGE') {
if (-not $Settings[$key]) { throw "set $key in $envFile" }
}
$Image = $Settings.IMAGE
$Checkout = $Settings.CHECKOUT.TrimEnd('/')
$Release = "\\wsl.localhost\$($Settings.DISTRO)" + ($Checkout -replace '/[^/]+$', '' -replace '/', '\') + '\release\' + ($Checkout -replace '^.*/', '')
function Assert-Wslc {
if (-not (Get-Command wslc -ErrorAction SilentlyContinue)) {
throw 'wslc is not on PATH - run wsl --update (WSL 2.9.3 or later), see https://learn.microsoft.com/windows/wsl/tutorials/wsl-containers'
}
}
# The tag step 1 exported, from release\<folder>\production.
function Get-ReleaseSha {
$file = Join-Path $Release 'production'
if (-not (Test-Path $file)) { throw "no $file - run step 1 first" }
(Get-Content $file -TotalCount 1).Trim()
}