feat: add cross-platform release pipeline [CI SKIP]
This commit is contained in:
1 parent
26620707a0
commit
deceeb19f3
27 files changed
+1036
-18
No files matched your search
@@ -0,0 +1,8 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net10.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
</Project>
|
||||
@@ -0,0 +1,38 @@
|
||||
using System.Formats.Tar;
|
||||
using System.IO.Compression;
|
||||
|
||||
if (args.Length < 3)
|
||||
{
|
||||
Console.Error.WriteLine("usage: Monitor.Tar <source-directory> <archive-path> <executable-relative-path>...");
|
||||
return 2;
|
||||
}
|
||||
|
||||
string sourceDirectory = Path.GetFullPath(args[0]);
|
||||
string archivePath = Path.GetFullPath(args[1]);
|
||||
HashSet<string> executables = args.Skip(2).Select(path => path.Replace('\\', '/')).ToHashSet(StringComparer.Ordinal);
|
||||
UnixFileMode executableMode = UnixFileMode.UserRead | UnixFileMode.UserWrite | UnixFileMode.UserExecute |
|
||||
UnixFileMode.GroupRead | UnixFileMode.GroupExecute |
|
||||
UnixFileMode.OtherRead | UnixFileMode.OtherExecute;
|
||||
UnixFileMode regularMode = UnixFileMode.UserRead | UnixFileMode.UserWrite |
|
||||
UnixFileMode.GroupRead | UnixFileMode.OtherRead;
|
||||
|
||||
Directory.CreateDirectory(Path.GetDirectoryName(archivePath)!);
|
||||
using FileStream fileStream = File.Create(archivePath);
|
||||
using GZipStream gzipStream = new(fileStream, CompressionLevel.Optimal, leaveOpen: true);
|
||||
using TarWriter writer = new(gzipStream, TarEntryFormat.Pax, leaveOpen: true);
|
||||
|
||||
foreach (string filePath in Directory.EnumerateFiles(sourceDirectory, "*", SearchOption.AllDirectories))
|
||||
{
|
||||
string relativePath = Path.GetRelativePath(sourceDirectory, filePath).Replace('\\', '/');
|
||||
PaxTarEntry entry = new(TarEntryType.RegularFile, relativePath)
|
||||
{
|
||||
Mode = executables.Contains(relativePath) ? executableMode : regularMode,
|
||||
DataStream = File.OpenRead(filePath)
|
||||
};
|
||||
using (entry.DataStream)
|
||||
{
|
||||
writer.WriteEntry(entry);
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
@@ -0,0 +1,55 @@
|
||||
#!/usr/bin/env bash
|
||||
# Publish a multi-architecture OCI index for the two architecture-specific
|
||||
# Backend images already pushed by release-linux.sh.
|
||||
set -euo pipefail
|
||||
|
||||
version="${CI_COMMIT_TAG#v}"
|
||||
[[ "${CI_COMMIT_TAG:-}" =~ ^v[0-9]+\.[0-9]+\.[0-9]+(-[0-9A-Za-z.-]+)?$ ]] || {
|
||||
echo "release must run from a vMAJOR.MINOR.PATCH tag" >&2
|
||||
exit 2
|
||||
}
|
||||
|
||||
registry="${ZOT_REGISTRY:-192.168.2.162:5000}"
|
||||
scheme="${ZOT_SCHEME:-http}"
|
||||
image="monitor/monitor-backend"
|
||||
auth_file="$(mktemp)"
|
||||
chmod 600 "$auth_file"
|
||||
trap 'rm -f "$auth_file"' EXIT
|
||||
printf 'machine %s login %s password %s\n' "${registry%%:*}" "$ZOT_USERNAME" "$ZOT_PASSWORD" > "$auth_file"
|
||||
|
||||
accept='application/vnd.oci.image.manifest.v1+json, application/vnd.docker.distribution.manifest.v2+json, application/vnd.oci.image.index.v1+json, application/vnd.docker.distribution.manifest.list.v2+json'
|
||||
|
||||
manifest_head() {
|
||||
local tag="$1"
|
||||
curl --silent --show-error --fail --head --netrc-file "$auth_file" \
|
||||
-H "Accept: $accept" "$scheme://$registry/v2/$image/manifests/$tag" \
|
||||
| tr -d '\r' | awk '
|
||||
tolower($1)=="docker-content-digest:" { digest=$2 }
|
||||
tolower($1)=="content-length:" { size=$2 }
|
||||
tolower($1)=="content-type:" { media=$2 }
|
||||
END { if (digest && size && media) print digest, size, media; else exit 1 }'
|
||||
}
|
||||
|
||||
amd="$(manifest_head "$version-amd64")"
|
||||
arm="$(manifest_head "$version-arm64")"
|
||||
read -r amd_digest amd_size amd_media <<< "$amd"
|
||||
read -r arm_digest arm_size arm_media <<< "$arm"
|
||||
index_media='application/vnd.oci.image.index.v1+json'
|
||||
body="$(printf '{"schemaVersion":2,"mediaType":"%s","manifests":[{"mediaType":"%s","digest":"%s","size":%s,"platform":{"architecture":"amd64","os":"linux"}},{"mediaType":"%s","digest":"%s","size":%s,"platform":{"architecture":"arm64","os":"linux"}}]}' \
|
||||
"$index_media" "$amd_media" "$amd_digest" "$amd_size" "$arm_media" "$arm_digest" "$arm_size")"
|
||||
|
||||
put_tag() {
|
||||
local tag="$1" code
|
||||
code="$(curl --silent --show-error --netrc-file "$auth_file" -o /dev/null -w '%{http_code}' \
|
||||
-H "Content-Type: $index_media" -X PUT --data-binary "$body" \
|
||||
"$scheme://$registry/v2/$image/manifests/$tag")"
|
||||
case "$code" in
|
||||
200|201) echo "published $image:$tag" ;;
|
||||
*) echo "failed to publish $image:$tag (HTTP $code)" >&2; return 1 ;;
|
||||
esac
|
||||
}
|
||||
|
||||
put_tag "$version"
|
||||
if [[ "$version" != *-* ]]; then
|
||||
put_tag latest
|
||||
fi
|
||||
@@ -0,0 +1,172 @@
|
||||
$ErrorActionPreference = 'Stop'
|
||||
Set-StrictMode -Version Latest
|
||||
|
||||
if (-not $env:CI_COMMIT_TAG -or $env:CI_COMMIT_TAG -notmatch '^v(\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?)$') {
|
||||
throw 'Release must run from a vMAJOR.MINOR.PATCH tag.'
|
||||
}
|
||||
if (-not $env:GITEA_TOKEN) {
|
||||
throw 'GITEA_TOKEN is required.'
|
||||
}
|
||||
$version = $Matches[1]
|
||||
$root = Split-Path -Parent $PSScriptRoot
|
||||
$backend = Join-Path $root 'backend'
|
||||
$projectVersion = [regex]::Match((Get-Content (Join-Path $backend 'Directory.Build.props') -Raw), '<Version>([^<]+)</Version>').Groups[1].Value
|
||||
if ($version -ne $projectVersion) {
|
||||
throw "Tag version $version does not match project version $projectVersion."
|
||||
}
|
||||
|
||||
$tarProject = Join-Path $PSScriptRoot 'Monitor.Tar\Monitor.Tar.csproj'
|
||||
$tarTool = Join-Path $PSScriptRoot 'Monitor.Tar\bin\Release\net10.0\Monitor.Tar.dll'
|
||||
& dotnet build $tarProject -c Release --nologo
|
||||
if ($LASTEXITCODE -ne 0) {
|
||||
throw 'Could not build the cross-platform tar helper.'
|
||||
}
|
||||
$giteaBase = if ($env:GITEA_BASE) { $env:GITEA_BASE.TrimEnd('/') } else { 'http://localhost:3100' }
|
||||
$netrc = Join-Path $env:TEMP ("monitor-gitea-$([guid]::NewGuid().ToString('N')).netrc")
|
||||
$giteaHost = ([Uri]$giteaBase).Host
|
||||
Set-Content -LiteralPath $netrc -Value "machine $giteaHost login justme password $($env:GITEA_TOKEN)" -Encoding ascii -NoNewline
|
||||
|
||||
function New-TarGzArchive([string]$SourceDirectory, [string]$ArchivePath, [string[]]$Executables) {
|
||||
& dotnet $tarTool $SourceDirectory $ArchivePath @Executables
|
||||
if ($LASTEXITCODE -ne 0) {
|
||||
throw "Could not create tar archive $ArchivePath."
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
$targets = @(
|
||||
@{ Rid = 'linux-x64'; Os = 'linux'; Arch = 'amd64'; Windows = $false },
|
||||
@{ Rid = 'linux-arm64'; Os = 'linux'; Arch = 'arm64'; Windows = $false },
|
||||
@{ Rid = 'linux-musl-x64'; Os = 'linux'; Arch = 'musl-amd64'; Windows = $false },
|
||||
@{ Rid = 'linux-musl-arm64'; Os = 'linux'; Arch = 'musl-arm64'; Windows = $false },
|
||||
@{ Rid = 'osx-x64'; Os = 'macos'; Arch = 'x64'; Windows = $false },
|
||||
@{ Rid = 'osx-arm64'; Os = 'macos'; Arch = 'arm64'; Windows = $false },
|
||||
@{ Rid = 'win-x64'; Os = 'windows'; Arch = 'amd64'; Windows = $true },
|
||||
@{ Rid = 'win-arm64'; Os = 'windows'; Arch = 'arm64'; Windows = $true }
|
||||
)
|
||||
$packageRoot = Join-Path $root '.release\packages'
|
||||
$null = New-Item -ItemType Directory -Force -Path $packageRoot
|
||||
$uploadFiles = [System.Collections.Generic.List[string]]::new()
|
||||
foreach ($target in $targets) {
|
||||
$agentDirectory = Join-Path $root ".release\publish\$($target.Rid)\agent"
|
||||
$probeDirectory = Join-Path $root ".release\publish\$($target.Rid)\probe"
|
||||
$enrollDirectory = Join-Path $root ".release\publish\$($target.Rid)\fleet-enroll"
|
||||
foreach ($path in @($agentDirectory, $probeDirectory, $enrollDirectory)) {
|
||||
if (-not (Test-Path -LiteralPath $path -PathType Container)) {
|
||||
throw "Build output is missing: $path"
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($role in @('agent', 'probe')) {
|
||||
$stage = Join-Path $root ".release\stage\$($target.Rid)\$role"
|
||||
$null = New-Item -ItemType Directory -Force -Path $stage
|
||||
$extension = if ($target.Windows) { '.exe' } else { '' }
|
||||
Copy-Item -LiteralPath (Join-Path (Join-Path $root ".release\publish\$($target.Rid)\$role") "monitor-$role$extension") -Destination $stage
|
||||
Copy-Item -LiteralPath (Join-Path $root 'LICENSE') -Destination $stage
|
||||
Copy-Item -LiteralPath (Join-Path $root "backend\$role\README.md") -Destination $stage
|
||||
|
||||
$executables = @("monitor-$role$extension")
|
||||
if ($role -eq 'agent') {
|
||||
$enrollName = if ($target.Windows) { 'fleet-enroll.exe' } else { 'fleet-enroll' }
|
||||
Copy-Item -LiteralPath (Join-Path $enrollDirectory $enrollName) -Destination $stage
|
||||
$executables += $enrollName
|
||||
}
|
||||
if ($target.Os -eq 'linux') {
|
||||
Copy-Item -LiteralPath (Join-Path $root 'packaging/install.sh') -Destination $stage
|
||||
$executables += 'install.sh'
|
||||
$systemd = Join-Path $stage 'systemd'
|
||||
$null = New-Item -ItemType Directory -Force -Path $systemd
|
||||
Copy-Item -LiteralPath (Join-Path $root "packaging/systemd/monitor-$role.service") -Destination $systemd
|
||||
if ($role -eq 'probe') {
|
||||
$openwrt = Join-Path $stage 'openwrt'
|
||||
$null = New-Item -ItemType Directory -Force -Path $openwrt
|
||||
Copy-Item -LiteralPath (Join-Path $root 'packaging/openwrt/monitor-probe.init') -Destination $openwrt
|
||||
Copy-Item -LiteralPath (Join-Path $root 'packaging/openwrt/monitor.keep') -Destination $openwrt
|
||||
}
|
||||
}
|
||||
elseif ($target.Os -eq 'macos') {
|
||||
@'
|
||||
This macOS NativeAOT binary is not signed with a Developer ID certificate and
|
||||
has not been notarized by Apple. Apple Silicon builds receive an ad-hoc code
|
||||
signature; Intel builds are unsigned. Gatekeeper may block browser-downloaded
|
||||
files. A Developer ID signature and notarization are required for a seamless
|
||||
consumer install.
|
||||
'@ | Set-Content -LiteralPath (Join-Path $stage 'MACOS-SECURITY.txt') -Encoding utf8
|
||||
}
|
||||
|
||||
$archiveName = if ($target.Windows) { "monitor-$role-v$version-windows-$($target.Arch).zip" } else { "monitor-$role-v$version-$($target.Os)-$($target.Arch).tar.gz" }
|
||||
$archive = Join-Path $packageRoot $archiveName
|
||||
if ($target.Windows) {
|
||||
Compress-Archive -Path (Join-Path $stage '*') -DestinationPath $archive -CompressionLevel Optimal -Force
|
||||
}
|
||||
else {
|
||||
New-TarGzArchive $stage $archive $executables
|
||||
}
|
||||
$hash = (Get-FileHash -LiteralPath $archive -Algorithm SHA256).Hash.ToLowerInvariant()
|
||||
$checksum = "$hash $archiveName`n"
|
||||
$checksumPath = "$archive.sha256"
|
||||
[IO.File]::WriteAllText($checksumPath, $checksum, [Text.UTF8Encoding]::new($false))
|
||||
[void]$uploadFiles.Add($archive)
|
||||
[void]$uploadFiles.Add($checksumPath)
|
||||
}
|
||||
}
|
||||
|
||||
$uploadScript = @'
|
||||
param([string]$File, [string]$Base, [string]$PackageVersion, [string]$Netrc)
|
||||
$ErrorActionPreference = 'Stop'
|
||||
$name = [IO.Path]::GetFileName($File)
|
||||
$url = "$Base/api/packages/justme/generic/monitor-node/$PackageVersion/$name"
|
||||
$status = & curl.exe --silent --show-error --retry 3 --netrc-file $Netrc --upload-file $File --output NUL --write-out '%{http_code}' $url
|
||||
if ($LASTEXITCODE -ne 0) {
|
||||
throw "Gitea package upload failed for $name (curl exit $LASTEXITCODE)."
|
||||
}
|
||||
if ($status -match '^2') {
|
||||
"uploaded Gitea package $name"
|
||||
}
|
||||
elseif ($status -eq '409') {
|
||||
"Gitea package $name already exists; reusing the existing release file"
|
||||
}
|
||||
else {
|
||||
throw "Gitea package upload failed for $name (HTTP $status)."
|
||||
}
|
||||
'@
|
||||
$runspacePool = [RunspaceFactory]::CreateRunspacePool(1, 8)
|
||||
$runspacePool.Open()
|
||||
$pendingUploads = [System.Collections.Generic.List[object]]::new()
|
||||
try {
|
||||
foreach ($file in $uploadFiles) {
|
||||
$powerShell = [PowerShell]::Create()
|
||||
$powerShell.RunspacePool = $runspacePool
|
||||
[void]$powerShell.AddScript($uploadScript).AddArgument($file).AddArgument($giteaBase).AddArgument($version).AddArgument($netrc)
|
||||
$pendingUploads.Add([pscustomobject]@{ PowerShell = $powerShell; Handle = $powerShell.BeginInvoke() })
|
||||
}
|
||||
|
||||
$uploadErrors = [System.Collections.Generic.List[string]]::new()
|
||||
foreach ($pending in $pendingUploads) {
|
||||
try {
|
||||
foreach ($message in $pending.PowerShell.EndInvoke($pending.Handle)) {
|
||||
Write-Output $message
|
||||
}
|
||||
foreach ($errorRecord in $pending.PowerShell.Streams.Error) {
|
||||
$uploadErrors.Add($errorRecord.ToString())
|
||||
}
|
||||
}
|
||||
catch {
|
||||
$uploadErrors.Add($_.Exception.Message)
|
||||
}
|
||||
}
|
||||
if ($uploadErrors.Count -gt 0) {
|
||||
throw "One or more Gitea package uploads failed:`n$($uploadErrors -join "`n")"
|
||||
}
|
||||
}
|
||||
finally {
|
||||
foreach ($pending in $pendingUploads) {
|
||||
$pending.PowerShell.Dispose()
|
||||
}
|
||||
$runspacePool.Close()
|
||||
$runspacePool.Dispose()
|
||||
}
|
||||
}
|
||||
finally {
|
||||
Remove-Item -LiteralPath $netrc -Force -ErrorAction SilentlyContinue
|
||||
}
|
||||
@@ -0,0 +1,114 @@
|
||||
#!/usr/bin/env bash
|
||||
# Create/update the Gitea Release after all platform package workflows succeed.
|
||||
set -euo pipefail
|
||||
|
||||
tag="${CI_COMMIT_TAG:-}"
|
||||
[[ "$tag" =~ ^v[0-9]+\.[0-9]+\.[0-9]+(-[0-9A-Za-z.-]+)?$ ]] || {
|
||||
echo "release must run from a vMAJOR.MINOR.PATCH tag" >&2
|
||||
exit 2
|
||||
}
|
||||
[[ -n "${GITEA_TOKEN:-}" ]] || { echo "GITEA_TOKEN is required" >&2; exit 2; }
|
||||
|
||||
version="${tag#v}"
|
||||
gitea_base="${GITEA_BASE:-http://192.168.2.162:3100}"
|
||||
gitea_base="${gitea_base%/}"
|
||||
gitea_host="${gitea_base#https://}"
|
||||
gitea_host="${gitea_host#http://}"
|
||||
gitea_host="${gitea_host%%/*}"
|
||||
gitea_host="${gitea_host%%:*}"
|
||||
api="$gitea_base/api/v1/repos/justme/MyMonitor"
|
||||
tmp="$(mktemp -d)"
|
||||
netrc="$tmp/netrc"
|
||||
release_json="$tmp/release.json"
|
||||
assets_json="$tmp/assets.json"
|
||||
chmod 700 "$tmp"
|
||||
printf 'machine %s login justme password %s\n' "$gitea_host" "$GITEA_TOKEN" > "$netrc"
|
||||
chmod 600 "$netrc"
|
||||
trap 'rm -rf "$tmp"' EXIT
|
||||
|
||||
release_body="Agent and Probe builds: Linux glibc and musl (x64, arm64), macOS (x64, arm64), and Windows (x64, arm64). macOS binaries are not Developer ID signed or notarized. Backend OCI images: registry.oeo.one/monitor/monitor-backend:$version (linux/amd64 and linux/arm64)."
|
||||
payload="$(printf '{"tag_name":"%s","target_commitish":"%s","name":"MyMonitor %s","body":"%s","draft":false,"prerelease":false}' \
|
||||
"$tag" "${CI_COMMIT_SHA:-}" "$tag" "$release_body")"
|
||||
release_status="$(curl --silent --show-error --retry 3 --netrc-file "$netrc" \
|
||||
--output "$release_json" --write-out '%{http_code}' "$api/releases/tags/$tag")"
|
||||
release_created=false
|
||||
if [[ "$release_status" == 404 ]]; then
|
||||
release_status="$(curl --silent --show-error --retry 3 --netrc-file "$netrc" \
|
||||
--header 'Content-Type: application/json' --data "$payload" \
|
||||
--output "$release_json" --write-out '%{http_code}' "$api/releases")"
|
||||
release_created=true
|
||||
fi
|
||||
[[ "$release_status" =~ ^2 ]] || {
|
||||
echo "Gitea Release lookup/create failed (HTTP $release_status)" >&2
|
||||
cat "$release_json" >&2
|
||||
exit 1
|
||||
}
|
||||
release_id="$(grep -o '"id":[[:space:]]*[0-9][0-9]*' "$release_json" | head -1 | tr -cd '0-9')"
|
||||
[[ -n "$release_id" ]] || { echo "Could not read Gitea Release ID" >&2; exit 1; }
|
||||
if [[ "$release_created" == false ]]; then
|
||||
update_response="$tmp/release-update.json"
|
||||
update_status="$(curl --silent --show-error --retry 3 --netrc-file "$netrc" \
|
||||
--request PATCH --header 'Content-Type: application/json' --data "$payload" \
|
||||
--output "$update_response" --write-out '%{http_code}' "$api/releases/$release_id")"
|
||||
[[ "$update_status" =~ ^2 ]] || {
|
||||
echo "Gitea Release update failed (HTTP $update_status)" >&2
|
||||
cat "$update_response" >&2
|
||||
exit 1
|
||||
}
|
||||
fi
|
||||
curl --fail-with-body --silent --show-error --retry 3 --netrc-file "$netrc" \
|
||||
"$api/releases/$release_id/assets" -o "$assets_json"
|
||||
|
||||
assets=(
|
||||
"monitor-agent-v$version-linux-amd64.tar.gz"
|
||||
"monitor-agent-v$version-linux-arm64.tar.gz"
|
||||
"monitor-probe-v$version-linux-amd64.tar.gz"
|
||||
"monitor-probe-v$version-linux-arm64.tar.gz"
|
||||
"monitor-agent-v$version-linux-musl-amd64.tar.gz"
|
||||
"monitor-probe-v$version-linux-musl-amd64.tar.gz"
|
||||
"monitor-agent-v$version-linux-musl-arm64.tar.gz"
|
||||
"monitor-probe-v$version-linux-musl-arm64.tar.gz"
|
||||
"monitor-agent-v$version-macos-x64.tar.gz"
|
||||
"monitor-probe-v$version-macos-x64.tar.gz"
|
||||
"monitor-agent-v$version-macos-arm64.tar.gz"
|
||||
"monitor-probe-v$version-macos-arm64.tar.gz"
|
||||
"monitor-agent-v$version-windows-amd64.zip"
|
||||
"monitor-agent-v$version-windows-arm64.zip"
|
||||
"monitor-probe-v$version-windows-amd64.zip"
|
||||
"monitor-probe-v$version-windows-arm64.zip"
|
||||
)
|
||||
|
||||
upload_release_asset() {
|
||||
local name="$1" file="$tmp/$1" upload_response="$tmp/$1.upload.json" status
|
||||
curl --fail-with-body --silent --show-error --retry 3 --netrc-file "$netrc" \
|
||||
"$gitea_base/api/packages/justme/generic/monitor-node/$version/$name" -o "$file"
|
||||
status="$(curl --silent --show-error --retry 3 --netrc-file "$netrc" \
|
||||
--request POST --header 'Content-Type: application/octet-stream' --data-binary "@$file" \
|
||||
--output "$upload_response" --write-out '%{http_code}' \
|
||||
"$api/releases/$release_id/assets?name=$name")"
|
||||
case "$status" in
|
||||
2*) echo "attached $name" ;;
|
||||
*) echo "Gitea Release asset upload failed for $name (HTTP $status)" >&2; cat "$upload_response" >&2; return 1 ;;
|
||||
esac
|
||||
}
|
||||
|
||||
pids=()
|
||||
for archive in "${assets[@]}"; do
|
||||
for name in "$archive" "$archive.sha256"; do
|
||||
if grep -Eq "\"name\"[[:space:]]*:[[:space:]]*\"$name\"" "$assets_json"; then
|
||||
echo "release asset $name already exists; keeping the existing asset"
|
||||
continue
|
||||
fi
|
||||
upload_release_asset "$name" &
|
||||
pids+=("$!")
|
||||
if ((${#pids[@]} >= 8)); then
|
||||
wait "${pids[0]}"
|
||||
pids=("${pids[@]:1}")
|
||||
fi
|
||||
done
|
||||
done
|
||||
for pid in "${pids[@]}"; do
|
||||
wait "$pid"
|
||||
done
|
||||
|
||||
echo "published Gitea Release $tag: https://git.oeo.one/justme/MyMonitor/releases/tag/$tag"
|
||||
@@ -0,0 +1,75 @@
|
||||
param(
|
||||
[Parameter(Mandatory)]
|
||||
[ValidateSet(
|
||||
'linux-x64', 'linux-arm64',
|
||||
'linux-musl-x64', 'linux-musl-arm64',
|
||||
'osx-x64', 'osx-arm64', 'win-x64', 'win-arm64'
|
||||
)]
|
||||
[string]$RuntimeIdentifier,
|
||||
[Parameter(Mandatory)]
|
||||
[ValidateSet('agent', 'probe', 'fleet-enroll')]
|
||||
[string]$Component
|
||||
)
|
||||
|
||||
$ErrorActionPreference = 'Stop'
|
||||
Set-StrictMode -Version Latest
|
||||
|
||||
if (-not $env:CI_COMMIT_TAG -or $env:CI_COMMIT_TAG -notmatch '^v(\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?)$') {
|
||||
throw 'Release must run from a vMAJOR.MINOR.PATCH tag.'
|
||||
}
|
||||
$version = $Matches[1]
|
||||
$root = Split-Path -Parent $PSScriptRoot
|
||||
$backend = Join-Path $root 'backend'
|
||||
$projectVersion = [regex]::Match((Get-Content (Join-Path $backend 'Directory.Build.props') -Raw), '<Version>([^<]+)</Version>').Groups[1].Value
|
||||
if ($version -ne $projectVersion) {
|
||||
throw "Tag version $version does not match project version $projectVersion."
|
||||
}
|
||||
|
||||
if ($RuntimeIdentifier -in @('win-x64', 'win-arm64')) {
|
||||
$vcArchitecture = if ($RuntimeIdentifier -eq 'win-x64') { 'x64' } else { 'arm64' }
|
||||
$vsWhere = Join-Path ${env:ProgramFiles(x86)} 'Microsoft Visual Studio\Installer\vswhere.exe'
|
||||
$vsPath = & $vsWhere -latest -products * -requires Microsoft.VisualStudio.Component.VC.Tools.x86.x64 -property installationPath
|
||||
if (-not $vsPath) {
|
||||
throw 'Visual Studio C++ Build Tools were not found.'
|
||||
}
|
||||
$devCmd = Join-Path $vsPath 'Common7\Tools\VsDevCmd.bat'
|
||||
$environmentLines = & cmd.exe /d /s /c "call `"$devCmd`" -no_logo -arch=$vcArchitecture -host_arch=x64 && set"
|
||||
foreach ($line in $environmentLines) {
|
||||
$separator = $line.IndexOf('=')
|
||||
if ($separator -gt 0) {
|
||||
[Environment]::SetEnvironmentVariable($line.Substring(0, $separator), $line.Substring($separator + 1), 'Process')
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$project = switch ($Component) {
|
||||
'agent' { 'agent/src/Monitor.Agent' }
|
||||
'probe' { 'probe/src/Monitor.Probe' }
|
||||
'fleet-enroll' { 'fleet/tools/fleet-enroll' }
|
||||
}
|
||||
$output = Join-Path $root ".release\publish\$RuntimeIdentifier\$Component"
|
||||
$buildRoot = Join-Path $root ".release\build\$RuntimeIdentifier-$Component"
|
||||
$null = New-Item -ItemType Directory -Force -Path $output
|
||||
|
||||
Push-Location $backend
|
||||
try {
|
||||
& dotnet publish $project `
|
||||
-m:1 `
|
||||
-c Release `
|
||||
-r $RuntimeIdentifier `
|
||||
--self-contained true `
|
||||
-p:PublishAot=true `
|
||||
-p:StripSymbols=true `
|
||||
-p:DebugType=none `
|
||||
-p:DebugSymbols=false `
|
||||
--artifacts-path $buildRoot `
|
||||
-o $output
|
||||
if ($LASTEXITCODE -ne 0) {
|
||||
throw "NativeAOT publish failed for $project ($RuntimeIdentifier)."
|
||||
}
|
||||
}
|
||||
finally {
|
||||
Pop-Location
|
||||
}
|
||||
|
||||
Write-Output "built $Component for $RuntimeIdentifier"
|
||||
@@ -0,0 +1,74 @@
|
||||
#!/usr/bin/env bash
|
||||
# Publish one framework-dependent Backend OCI image for the requested arch.
|
||||
set -euo pipefail
|
||||
|
||||
arch="${1:?usage: release-linux.sh <amd64|arm64>}"
|
||||
root="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
|
||||
tag="${CI_COMMIT_TAG:-}"
|
||||
[[ "$tag" =~ ^v[0-9]+\.[0-9]+\.[0-9]+(-[0-9A-Za-z.-]+)?$ ]] || {
|
||||
echo "release must run from a vMAJOR.MINOR.PATCH tag" >&2
|
||||
exit 2
|
||||
}
|
||||
[[ -n "${ZOT_USERNAME:-}" && -n "${ZOT_PASSWORD:-}" ]] || {
|
||||
echo "Zot credentials are required" >&2; exit 2;
|
||||
}
|
||||
case "$arch" in
|
||||
amd64|arm64) ;;
|
||||
*) echo "unsupported architecture: $arch" >&2; exit 2 ;;
|
||||
esac
|
||||
|
||||
version="${tag#v}"
|
||||
project_version="$(sed -n 's#.*<Version>\(.*\)</Version>.*#\1#p' "$root/backend/Directory.Build.props" | head -1)"
|
||||
if [[ "$version" != "$project_version" ]]; then
|
||||
echo "tag version $version does not match project version $project_version" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
registry="${ZOT_REGISTRY:-192.168.2.162:5000}"
|
||||
image="$registry/monitor/monitor-backend"
|
||||
output="$root/.release/linux-$arch/backend"
|
||||
build_root="$root/.release/build/linux-$arch-backend"
|
||||
container_context="$root/.release/container/linux-$arch"
|
||||
mkdir -p "$output" "$build_root" "$container_context/app" "$container_context/data"
|
||||
|
||||
(cd "$root/backend" && dotnet publish src/Monitor.Backend \
|
||||
-m:3 -c Release --no-self-contained \
|
||||
-p:DebugType=none -p:DebugSymbols=false \
|
||||
-p:UseAppHost=false -p:OpenApiGenerateDocuments=false \
|
||||
--artifacts-path "$build_root" -o "$output")
|
||||
find "$output" -type f -name '*.pdb' -delete
|
||||
cp -a "$output/." "$container_context/app/"
|
||||
: > "$container_context/data/.keep"
|
||||
|
||||
export REGISTRY_AUTH_FILE="$root/.release/auth/zot-linux-$arch.json"
|
||||
mkdir -p "$(dirname "$REGISTRY_AUTH_FILE")"
|
||||
logged_in=false
|
||||
for attempt in 1 2 3 4; do
|
||||
if buildah login --tls-verify=false --username "$ZOT_USERNAME" --password-stdin "$registry" <<< "$ZOT_PASSWORD" >/dev/null; then
|
||||
logged_in=true
|
||||
break
|
||||
fi
|
||||
if [[ "$attempt" -lt 4 ]]; then
|
||||
echo "Zot login attempt $attempt failed; retrying in 3 seconds" >&2
|
||||
sleep 3
|
||||
fi
|
||||
done
|
||||
[[ "$logged_in" == true ]] || { echo "could not authenticate to Zot after 4 attempts" >&2; exit 1; }
|
||||
local_image="localhost/monitor-backend:$version-$arch"
|
||||
buildah bud --tls-verify=false --arch "$arch" \
|
||||
--build-arg "APP_VERSION=$version" \
|
||||
-f "$root/packaging/container/Backend.Containerfile" \
|
||||
-t "$local_image" "$container_context" >/dev/null
|
||||
pushed=false
|
||||
for attempt in 1 2 3; do
|
||||
if buildah push --tls-verify=false "$local_image" "docker://$image:$version-$arch" >/dev/null; then
|
||||
pushed=true
|
||||
break
|
||||
fi
|
||||
if [[ "$attempt" -lt 3 ]]; then
|
||||
echo "Zot push attempt $attempt failed; retrying in 5 seconds" >&2
|
||||
sleep 5
|
||||
fi
|
||||
done
|
||||
[[ "$pushed" == true ]] || { echo "could not push image to Zot after 3 attempts" >&2; exit 1; }
|
||||
echo "pushed Zot image $image:$version-$arch"
|
||||
Reference in new issue
Block a user