Files
MoShiro/ci/fetch-quic-test-runtime.sh
justme a867c9f7f6
ci/woodpecker/push/web-build Pipeline was successful
ci/woodpecker/push/dev-image Pipeline failed
ci/woodpecker/push/verify Pipeline failed
ci: pin Linux build RIDs across stages and retry runtime fetches [CI]
2026-10-21 13:40:21 +08:00

83 lines
3.1 KiB
Bash

#!/usr/bin/env bash
# Prepare the glibc MsQuic sidecars for Agent packages and in-process tests.
# Debian packages are extracted locally (no root install); downloads live in
# the persistent backend test cache so fast and slow workflows reuse them.
set -euo pipefail
cache="${1:?usage: fetch-quic-test-runtime.sh <cache-directory>}"
runtime="$cache/runtime"
downloads="$cache/downloads"
mkdir -p "$runtime" "$downloads"
if [[ -z "${2:-}" ]] && command -v apk >/dev/null 2>&1; then
# The Alpine test image installs runtime libraries into the normal loader path.
apk add --no-cache libmsquic numactl lttng-ust zlib >/dev/null
exit 0
fi
case "${2:-$(uname -m)}" in
x86_64|amd64) deb_arch=amd64 ;;
aarch64|arm64) deb_arch=arm64 ;;
*) echo "unsupported architecture for QUIC runtime: ${2:-$(uname -m)}" >&2; exit 2 ;;
esac
download() {
local url="$1" destination="$2"
if [[ ! -s "$destination" ]]; then
curl --fail --silent --show-error --retry 3 --retry-all-errors "$url" -o "$destination"
fi
}
extract_library_sonames() {
local package="$1" unpack="$2" data entry normalized name soname
mkdir -p "$unpack"
if [[ ! -f "$unpack/.extracted" ]]; then
(cd "$unpack" && ar x "$package")
data="$(find "$unpack" -maxdepth 1 -type f -name 'data.tar.*' -print -quit)"
[[ -n "$data" ]] || { echo "package has no data archive: $package" >&2; exit 1; }
while IFS= read -r entry; do
normalized="${entry#./}"
case "$normalized" in
usr/lib/*|lib/*) ;;
*) continue ;;
esac
name="${normalized##*/}"
[[ "$name" =~ \.so\.[0-9]+(\.[0-9]+)+$ ]] || continue
[[ "$name" =~ ^libmsquic\.lttng\.so\. ]] && continue
soname="$(sed -E 's/^(.+\.so\.[0-9]+).*/\1/' <<<"$name")"
tar -xf "$data" -C "$unpack" "$entry"
install -m 0644 "$unpack/$normalized" "$runtime/$soname"
done < <(tar -tf "$data")
touch "$unpack/.extracted"
fi
}
package_cache="$downloads/packages"
unpack_cache="$downloads/unpacked"
mkdir -p "$package_cache" "$unpack_cache"
msquic_index='https://packages.microsoft.com/debian/12/prod/pool/main/libm/libmsquic/'
msquic_file="$(curl --fail --silent --show-error --retry 3 --retry-all-errors "$msquic_index" \
| grep -oE "libmsquic_[0-9]+(\.[0-9]+){1,3}_${deb_arch}\.deb" \
| sort -Vu | tail -n 1)"
[[ -n "$msquic_file" ]] || { echo "could not find a stable MsQuic package for $deb_arch" >&2; exit 1; }
packages=(
"$msquic_index$msquic_file"
"https://deb.debian.org/debian/pool/main/n/numactl/libnuma1_2.0.16-1_${deb_arch}.deb"
"https://deb.debian.org/debian/pool/main/libz/libzstd/libzstd1_1.5.4+dfsg2-5_${deb_arch}.deb"
"https://deb.debian.org/debian/pool/main/z/zlib/zlib1g_1.2.13.dfsg-1_${deb_arch}.deb"
)
for url in "${packages[@]}"; do
file="${url##*/}"
package="$package_cache/$file"
download "$url" "$package"
extract_library_sonames "$package" "$unpack_cache/${file%.deb}"
done
for library in libmsquic.so.2 libnuma.so.1 libz.so.1 libzstd.so.1; do
[[ -f "$runtime/$library" ]] || { echo "missing QUIC test library: $library" >&2; exit 1; }
done
echo "prepared MsQuic test runtime ($deb_arch) in $runtime"