#!/usr/bin/env bash # Run as the WSL Podman user; retain image layers and tool archives across runs. set -euo pipefail root="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" cache="${MOSHIRO_RUNNER_IMAGE_CACHE:-/home/justme/woodpecker/cache/runner-image}" builder_image=localhost/moshiro-dotnet10-nativeaot-aotanywhere:ci runner_image=localhost/moshiro-woodpecker-agent:ci mkdir -p "$cache/context/ci" exec 9> "$cache/.lock" flock -w 900 9 tr -d '\r' < "$root/global.json" > "$cache/context/global.json" install -m 0644 "$root/ci/fetch-quic-test-runtime.sh" "$root/ci/woodpecker-agent-entrypoint.sh" "$cache/context/ci/" source "$root/ci/nativeaot-toolchain.sh" moshiro_nativeaot_settings "$root" podman build --layers --pull=missing --isolation chroot --network host \ --build-arg "AOTANYWHERE_VERSION=$MOSHIRO_AOTANYWHERE_VERSION" --build-arg "ZIG_TOOLSET_VERSION=$MOSHIRO_ZIG_TOOLSET_VERSION" \ -f "$root/packaging/container/NativeAot.Builder.Containerfile" -t "$builder_image" "$cache/context" # Export once per image ID. Isolated Buildah stores import this local archive, # so parallel architecture builds never download their toolchain from NuGet. builder_id="$(podman image inspect --format '{{.Id}}' "$builder_image")" builder_id="${builder_id#sha256:}" archive="$cache/nativeaot-builder-$builder_id.oci" if [[ ! -f "$archive" ]]; then podman save --format oci-archive -o "$archive.tmp" "$builder_image" mv "$archive.tmp" "$archive" fi printf '%s\n' "$builder_id" > "$cache/nativeaot-builder.id.tmp" mv "$cache/nativeaot-builder.id.tmp" "$cache/nativeaot-builder.id" printf '%s\n' "$MOSHIRO_NATIVEAOT_BUILDER_KEY" > "$cache/nativeaot-builder.key.tmp" mv "$cache/nativeaot-builder.key.tmp" "$cache/nativeaot-builder.key" podman build --layers --pull=missing --isolation chroot --network host \ --build-arg "NATIVEAOT_BUILDER_IMAGE=$builder_image" \ -f "$root/packaging/container/Woodpecker.Agent.Containerfile" -t "$runner_image" "$cache/context" python3 - "$cache" "$archive" <<'PYCODE' from pathlib import Path import sys cache, active = Path(sys.argv[1]), Path(sys.argv[2]) archives = sorted(cache.glob('nativeaot-builder-*.oci'), key=lambda p: p.stat().st_mtime, reverse=True) previous = next((path for path in archives if path != active), None) keep = {active, previous} for path in archives: if path not in keep: path.unlink() for path in cache.glob('nativeaot-builder-*.oci.tmp'): path.unlink() PYCODE echo "built $runner_image; unchanged tool layers are reused"