d84347f5d6
Silo is pinned by SHA-256 in build/object-store.json and goes into the standalone packages, the MSI and the backend image, with its licence. Releases carry its source. The Swarm and Kubernetes stacks run one store as an internal service. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
99 lines
4.2 KiB
PowerShell
99 lines
4.2 KiB
PowerShell
<#
|
|
.SYNOPSIS
|
|
Puts the pinned object store program for a runtime into a folder, with its licence, notice and where its source is; or, with
|
|
-Source, returns the path of the program's source archive that releases carry beside the packages.
|
|
|
|
.DESCRIPTION
|
|
build/object-store.json pins the release and the SHA-256 of each runtime's archive and of the source archive. Archives are
|
|
downloaded once into artifacts/cache/object-store and checked against the pin every time they are used; a mismatch is an error.
|
|
The program is copied as published: it is never modified, and the server only ever runs it as a separate process.
|
|
|
|
.EXAMPLE
|
|
./scripts/Get-ObjectStore.ps1 -Runtime win-x64 -Destination artifacts/object-store
|
|
./scripts/Get-ObjectStore.ps1 -Source
|
|
#>
|
|
[CmdletBinding(DefaultParameterSetName = 'Program')]
|
|
param(
|
|
[Parameter(Mandatory, ParameterSetName = 'Program')][string]$Runtime,
|
|
[Parameter(Mandatory, ParameterSetName = 'Program')][string]$Destination,
|
|
[Parameter(Mandatory, ParameterSetName = 'Source')][switch]$Source
|
|
)
|
|
|
|
$ErrorActionPreference = 'Stop'
|
|
$ProgressPreference = 'SilentlyContinue'
|
|
$repoRoot = Split-Path -Parent $PSScriptRoot
|
|
$pin = Get-Content (Join-Path $repoRoot 'build/object-store.json') -Raw | ConvertFrom-Json
|
|
$sourceFile = "object-store-source-$($pin.version).tar.gz"
|
|
$cache = Join-Path $repoRoot 'artifacts/cache/object-store'
|
|
New-Item -ItemType Directory -Force $cache | Out-Null
|
|
|
|
function Get-Pinned([string]$Url, [string]$File, [string]$Sha256) {
|
|
$path = Join-Path $cache $File
|
|
$valid = { (Test-Path $path) -and (Get-FileHash $path -Algorithm SHA256).Hash -ieq $Sha256 }
|
|
if (-not (& $valid)) {
|
|
$partial = "$path.$PID.part"
|
|
try {
|
|
Invoke-WebRequest $Url -OutFile $partial -TimeoutSec 600
|
|
Move-Item $partial $path -Force
|
|
}
|
|
finally { Remove-Item $partial -Force -ErrorAction SilentlyContinue }
|
|
if (-not (& $valid)) {
|
|
$actual = (Get-FileHash $path -Algorithm SHA256).Hash.ToLowerInvariant()
|
|
Remove-Item $path -Force
|
|
throw "$File has SHA-256 $actual, not the pinned $Sha256."
|
|
}
|
|
}
|
|
$path
|
|
}
|
|
|
|
if ($Source) {
|
|
return Get-Pinned $pin.sourceArchive $sourceFile $pin.sourceSha256
|
|
}
|
|
|
|
$asset = $pin.assets.$Runtime
|
|
if (-not $asset) { throw "No object store program is pinned for $Runtime." }
|
|
|
|
$archive = Get-Pinned "$($pin.downloads)/$($asset.file)" $asset.file $asset.sha256
|
|
$program = if ($Runtime -like 'win-*') { 'silo.exe' } else { 'silo' }
|
|
$staging = Join-Path $cache "extract-$PID-$Runtime"
|
|
Remove-Item $staging -Recurse -Force -ErrorAction SilentlyContinue
|
|
New-Item -ItemType Directory -Force $staging, $Destination | Out-Null
|
|
try {
|
|
if ($archive -like '*.zip') {
|
|
Expand-Archive -Path $archive -DestinationPath $staging -Force
|
|
}
|
|
else {
|
|
tar -xzf $archive -C $staging
|
|
if ($LASTEXITCODE -ne 0) { throw "Could not unpack $archive." }
|
|
}
|
|
|
|
foreach ($file in $program, 'LICENSE', 'NOTICE') {
|
|
$found = Get-ChildItem $staging -Recurse -File -Filter $file | Select-Object -First 1
|
|
if (-not $found) { throw "$($asset.file) has no $file." }
|
|
Copy-Item $found.FullName (Join-Path $Destination $file) -Force
|
|
}
|
|
}
|
|
finally { Remove-Item $staging -Recurse -Force -ErrorAction SilentlyContinue }
|
|
|
|
$notice = @"
|
|
$($pin.name) $($pin.version)
|
|
$($pin.description).
|
|
|
|
This folder holds an unmodified copy of the program as its project published it, licensed under the GNU Affero General
|
|
Public License version 3 (see LICENSE and NOTICE). It is a separate program: the server starts it as its own process and
|
|
talks to it over its S3 API, and no part of it is linked into the server.
|
|
|
|
Source code for exactly this build, commit $($pin.commit):
|
|
ExecuteR-Server-<version>-object-store-source.tar.gz, attached to the same release as this package
|
|
$($pin.sourceArchive)
|
|
$($pin.source)
|
|
SHA-256 of the source archive: $($pin.sourceSha256)
|
|
|
|
Published archive: $($pin.downloads)/$($asset.file)
|
|
SHA-256: $($asset.sha256)
|
|
|
|
You may replace this program with your own build; name it in S3_EMBEDDED_PROGRAM.
|
|
"@
|
|
[IO.File]::WriteAllText((Join-Path $Destination 'SOURCE.txt'), $notice.Replace("`r`n", "`n") + "`n", [Text.UTF8Encoding]::new($false))
|
|
Join-Path $Destination $program
|