fix: restore multi-arch api builds

This commit is contained in:
2026-09-19 13:21:42 +08:00
parent 8960b68ac8
commit 746979bdd5
3 changed files with 48 additions and 31 deletions
+21 -16
View File
@@ -16,10 +16,10 @@
#
# 1. ARM64 QEMU emulation is registered via binfmt_misc with the `F`
# (fix-binary) flag so the kernel-held fd works inside build containers.
# 2. Base images are pre-pulled into the local cache (resumable retries),
# then the build runs with `--pull=false`.
# 2. The SDK is pulled for the builder platform while runtime images are
# pulled for ARM64, then the build runs with `--pull=false`.
# 3. `dotnet restore` goes through the host proxy; apt uses the in-Dockerfile
# Tsinghua mirror directly (NO_PROXY).
# Huawei Cloud mirror directly (NO_PROXY).
#
# Usage:
# scripts/build-arm64-image.sh
@@ -46,6 +46,7 @@ DOTNET_SDK_IMAGE="${DOTNET_SDK_IMAGE:-mcr.m.daocloud.io/dotnet/sdk:8.0-bookworm-
DOTNET_RUNTIME_IMAGE="${DOTNET_RUNTIME_IMAGE:-mcr.m.daocloud.io/dotnet/aspnet:8.0-bookworm-slim}"
NGINX_IMAGE="${NGINX_IMAGE:-docker.m.daocloud.io/library/nginx:1.27-alpine}"
NO_PROXY_HOSTS="mirrors.tuna.tsinghua.edu.cn,.tsinghua.edu.cn,mirrors.huaweicloud.com,.huaweicloud.com,mcr.m.daocloud.io,docker.m.daocloud.io,.m.daocloud.io,localhost,127.0.0.1"
BUILD_PLATFORM="${BUILD_PLATFORM:-$(docker version --format '{{.Server.Os}}/{{.Server.Arch}}')}"
log() { printf '\n\033[1;36m[%s] %s\033[0m\n' "$(date +%H:%M:%S)" "$*"; }
die() { printf '\n\033[1;31mERROR: %s\033[0m\n' "$*" >&2; exit 1; }
@@ -64,10 +65,10 @@ ensure_arm64_emulation() {
for source_file in /etc/apt/sources.list /etc/apt/sources.list.d/*.sources; do
[ -f "$source_file" ] || continue
sed -i \
-e "s|deb.debian.org|mirrors.tuna.tsinghua.edu.cn|g" \
-e "s|security.debian.org/debian-security|mirrors.tuna.tsinghua.edu.cn/debian-security|g" \
-e "s|archive.ubuntu.com|mirrors.tuna.tsinghua.edu.cn|g" \
-e "s|security.ubuntu.com|mirrors.tuna.tsinghua.edu.cn|g" \
-e "s|deb.debian.org|mirrors.huaweicloud.com|g" \
-e "s|security.debian.org/debian-security|mirrors.huaweicloud.com/debian-security|g" \
-e "s|archive.ubuntu.com|mirrors.huaweicloud.com|g" \
-e "s|security.ubuntu.com|mirrors.huaweicloud.com|g" \
"$source_file"
done
apt-get update -qq
@@ -87,15 +88,19 @@ ensure_arm64_emulation() {
# --- 2. Pre-pull base images (resumable retries) -----------------------------
pull_with_retry() {
local img="$1" i
local platform="$1" img="$2" i
for i in $(seq 1 8); do
if docker image inspect "$img" >/dev/null 2>&1; then return 0; fi
log "Pulling $img (attempt $i/8) ..."
docker pull --platform linux/arm64 "$img" >/dev/null 2>&1 || true
docker image inspect "$img" >/dev/null 2>&1 && return 0
if [ "$(docker image inspect --format '{{.Os}}/{{.Architecture}}' "$img" 2>/dev/null || true)" = "$platform" ]; then
return 0
fi
log "Pulling $img for $platform (attempt $i/8) ..."
docker pull --platform "$platform" "$img" >/dev/null 2>&1 || true
if [ "$(docker image inspect --format '{{.Os}}/{{.Architecture}}' "$img" 2>/dev/null || true)" = "$platform" ]; then
return 0
fi
sleep 3
done
docker image inspect "$img" >/dev/null 2>&1 || die "Could not pull $img (network)."
die "Could not pull $img for $platform (network)."
}
# --- 3. Build API image ------------------------------------------------------
@@ -142,9 +147,9 @@ export_images() {
}
ensure_arm64_emulation
pull_with_retry "$DOTNET_SDK_IMAGE"
pull_with_retry "$DOTNET_RUNTIME_IMAGE"
pull_with_retry "$NGINX_IMAGE"
pull_with_retry "$BUILD_PLATFORM" "$DOTNET_SDK_IMAGE"
pull_with_retry linux/arm64 "$DOTNET_RUNTIME_IMAGE"
pull_with_retry linux/arm64 "$NGINX_IMAGE"
build_api_image
build_frontend_image
export_images