diff --git a/build/Dockerfile.runtime b/build/Dockerfile.runtime index e3154901..e57f2140 100644 --- a/build/Dockerfile.runtime +++ b/build/Dockerfile.runtime @@ -8,11 +8,16 @@ ARG TARGETPLATFORM=linux/amd64 FROM debian:12-slim ARG TARGETPLATFORM +ARG APT_MIRROR= # Install runtime dependencies in a single layer # All codec libraries (libx264, libx265, libopus) are now statically linked # Only hardware acceleration drivers and core system libraries remain dynamic -RUN sed -i 's/^Components: main$/Components: main contrib non-free non-free-firmware/' /etc/apt/sources.list.d/debian.sources && \ +# Set APT_MIRROR=mirrors.tuna.tsinghua.edu.cn to speed up builds in China +RUN if [ -n "$APT_MIRROR" ]; then \ + sed -i "s@deb.debian.org@${APT_MIRROR}@g" /etc/apt/sources.list.d/debian.sources; \ + fi \ + && sed -i 's/^Components: main$/Components: main contrib non-free non-free-firmware/' /etc/apt/sources.list.d/debian.sources && \ apt-get update && \ apt-get install -y --no-install-recommends \ # Core runtime (all platforms) - no codec libs needed diff --git a/build/Dockerfile.runtime-full b/build/Dockerfile.runtime-full index 3e5b3100..3c320a03 100644 --- a/build/Dockerfile.runtime-full +++ b/build/Dockerfile.runtime-full @@ -8,11 +8,16 @@ ARG TARGETPLATFORM=linux/amd64 FROM debian:12-slim ARG TARGETPLATFORM +ARG APT_MIRROR= # Install runtime dependencies in a single layer # All codec libraries (libx264, libx265, libopus) are now statically linked # Only hardware acceleration drivers and core system libraries remain dynamic -RUN sed -i 's/^Components: main$/Components: main contrib non-free non-free-firmware/' /etc/apt/sources.list.d/debian.sources && \ +# Set APT_MIRROR=mirrors.tuna.tsinghua.edu.cn to speed up builds in China +RUN if [ -n "$APT_MIRROR" ]; then \ + sed -i "s@deb.debian.org@${APT_MIRROR}@g" /etc/apt/sources.list.d/debian.sources; \ + fi \ + && sed -i 's/^Components: main$/Components: main contrib non-free non-free-firmware/' /etc/apt/sources.list.d/debian.sources && \ apt-get update && \ apt-get install -y --no-install-recommends \ # Core runtime (all platforms) - no codec libs needed diff --git a/build/build-images.sh b/build/build-images.sh index 6398ea62..2c1a9d85 100755 --- a/build/build-images.sh +++ b/build/build-images.sh @@ -21,21 +21,25 @@ build_arch() { case "${CHINAMIRRO:-}" in 1|true|TRUE|yes|YES|on|ON) - local cross_build_opts="${CROSS_BUILD_OPTS:+$CROSS_BUILD_OPTS }--progress=plain --build-arg CHINAMIRRO=1 --build-arg GH_PROXY=${GH_PROXY:-https://gh-proxy.com/} --build-arg DEBIAN_IMAGE=${DEBIAN_IMAGE:-docker.1ms.run/library/debian:12}" + # Default Rust toolchain mirror is USTC (rsproxy.cn is unreachable via the + # Docker bridge on some networks because its CDN blocks the SNAT source IP). + local rust_dist="${RUSTUP_DIST_SERVER_MIRROR:-https://mirrors.ustc.edu.cn/rust-static}" + local rust_root="${RUSTUP_UPDATE_ROOT_MIRROR:-https://mirrors.ustc.edu.cn/rust-static/rustup}" + local crates_sparse="${CARGO_SPARSE_MIRROR:-sparse+https://mirrors.ustc.edu.cn/crates.io-index/}" + local crates_git="${CARGO_GIT_MIRROR:-https://mirrors.ustc.edu.cn/crates.io-index}" + local cross_build_opts="${CROSS_BUILD_OPTS:+$CROSS_BUILD_OPTS }--progress=plain --build-arg CHINAMIRRO=1 --build-arg GH_PROXY=${GH_PROXY:-https://ghfast.top/} --build-arg DEBIAN_IMAGE=${DEBIAN_IMAGE:-dockerproxy.net/library/debian:12}" cross_build_opts="$cross_build_opts --build-arg HTTP_PROXY= --build-arg HTTPS_PROXY= --build-arg ALL_PROXY= --build-arg NO_PROXY=" cross_build_opts="$cross_build_opts --build-arg http_proxy= --build-arg https_proxy= --build-arg all_proxy= --build-arg no_proxy=" echo "=== China mirror acceleration: enabled ===" echo "=== Building: $rust_target (via cross with custom Dockerfile) ===" env \ CROSS_BUILD_OPTS="$cross_build_opts" \ - CARGO_SOURCE_CRATES_IO_REPLACE_WITH=rsproxy-sparse \ - CARGO_SOURCE_RSPROXY_REGISTRY=https://rsproxy.cn/crates.io-index \ - CARGO_SOURCE_RSPROXY_SPARSE_REGISTRY=sparse+https://rsproxy.cn/index/ \ - CARGO_REGISTRIES_RSPROXY_INDEX=https://rsproxy.cn/crates.io-index \ + CARGO_SOURCE_CRATES_IO_REPLACE_WITH=cn-mirror \ + CARGO_SOURCE_CN-MIRROR_REGISTRY="$crates_sparse" \ CARGO_REGISTRIES_CRATES_IO_PROTOCOL=sparse \ CARGO_NET_GIT_FETCH_WITH_CLI=true \ - RUSTUP_DIST_SERVER=https://rsproxy.cn \ - RUSTUP_UPDATE_ROOT=https://rsproxy.cn/rustup \ + RUSTUP_DIST_SERVER="$rust_dist" \ + RUSTUP_UPDATE_ROOT="$rust_root" \ cross build --release --target "$rust_target" return ;; diff --git a/build/cross/Dockerfile.arm64 b/build/cross/Dockerfile.arm64 index 2716976c..dbf059b7 100644 --- a/build/cross/Dockerfile.arm64 +++ b/build/cross/Dockerfile.arm64 @@ -6,10 +6,10 @@ FROM ${DEBIAN_IMAGE} ARG CHINAMIRRO=0 ARG GH_PROXY=https://gh-proxy.com/ -ARG RUSTUP_DIST_SERVER_CN=https://rsproxy.cn -ARG RUSTUP_UPDATE_ROOT_CN=https://rsproxy.cn/rustup -ARG CARGO_INDEX_CN=https://rsproxy.cn/crates.io-index -ARG CARGO_REGISTRY_CN=sparse+https://rsproxy.cn/index/ +ARG RUSTUP_DIST_SERVER_CN=https://mirrors.ustc.edu.cn/rust-static +ARG RUSTUP_UPDATE_ROOT_CN=https://mirrors.ustc.edu.cn/rust-static/rustup +ARG CARGO_INDEX_CN=https://mirrors.ustc.edu.cn/crates.io-index +ARG CARGO_REGISTRY_CN=sparse+https://mirrors.ustc.edu.cn/crates.io-index/ ARG LIBJPEG_TURBO_VERSION=3.1.4.1 ARG LIBYUV_REV=957f295ea946cbbd13fcfc46e7066f2efa801233 ARG LIBVPX_VERSION=1.16.0 @@ -39,12 +39,12 @@ RUN apt-get update && apt-get install -y --no-install-recommends \ mkdir -p /root/.cargo; \ printf '%s\n' \ '[source.crates-io]' \ - "replace-with = 'rsproxy-sparse'" \ - '[source.rsproxy]' \ + "replace-with = 'cn-mirror-sparse'" \ + '[source.cn-mirror]' \ "registry = '${CARGO_INDEX_CN}'" \ - '[source.rsproxy-sparse]' \ + '[source.cn-mirror-sparse]' \ "registry = '${CARGO_REGISTRY_CN}'" \ - '[registries.rsproxy]' \ + '[registries.cn-mirror]' \ "index = '${CARGO_INDEX_CN}'" \ '[net]' \ 'git-fetch-with-cli = true' \ diff --git a/build/cross/Dockerfile.armv7 b/build/cross/Dockerfile.armv7 index 32e9eca4..b1c52ef5 100644 --- a/build/cross/Dockerfile.armv7 +++ b/build/cross/Dockerfile.armv7 @@ -6,10 +6,10 @@ FROM ${DEBIAN_IMAGE} ARG CHINAMIRRO=0 ARG GH_PROXY=https://gh-proxy.com/ -ARG RUSTUP_DIST_SERVER_CN=https://rsproxy.cn -ARG RUSTUP_UPDATE_ROOT_CN=https://rsproxy.cn/rustup -ARG CARGO_INDEX_CN=https://rsproxy.cn/crates.io-index -ARG CARGO_REGISTRY_CN=sparse+https://rsproxy.cn/index/ +ARG RUSTUP_DIST_SERVER_CN=https://mirrors.ustc.edu.cn/rust-static +ARG RUSTUP_UPDATE_ROOT_CN=https://mirrors.ustc.edu.cn/rust-static/rustup +ARG CARGO_INDEX_CN=https://mirrors.ustc.edu.cn/crates.io-index +ARG CARGO_REGISTRY_CN=sparse+https://mirrors.ustc.edu.cn/crates.io-index/ ARG LIBJPEG_TURBO_VERSION=3.1.4.1 ARG LIBYUV_REV=957f295ea946cbbd13fcfc46e7066f2efa801233 ARG LIBVPX_VERSION=1.16.0 @@ -39,12 +39,12 @@ RUN apt-get update && apt-get install -y --no-install-recommends \ mkdir -p /root/.cargo; \ printf '%s\n' \ '[source.crates-io]' \ - "replace-with = 'rsproxy-sparse'" \ - '[source.rsproxy]' \ + "replace-with = 'cn-mirror-sparse'" \ + '[source.cn-mirror]' \ "registry = '${CARGO_INDEX_CN}'" \ - '[source.rsproxy-sparse]' \ + '[source.cn-mirror-sparse]' \ "registry = '${CARGO_REGISTRY_CN}'" \ - '[registries.rsproxy]' \ + '[registries.cn-mirror]' \ "index = '${CARGO_INDEX_CN}'" \ '[net]' \ 'git-fetch-with-cli = true' \ diff --git a/build/cross/Dockerfile.x86_64 b/build/cross/Dockerfile.x86_64 index 406b98b9..bd44def0 100644 --- a/build/cross/Dockerfile.x86_64 +++ b/build/cross/Dockerfile.x86_64 @@ -6,10 +6,10 @@ FROM ${DEBIAN_IMAGE} ARG CHINAMIRRO=0 ARG GH_PROXY=https://gh-proxy.com/ -ARG RUSTUP_DIST_SERVER_CN=https://rsproxy.cn -ARG RUSTUP_UPDATE_ROOT_CN=https://rsproxy.cn/rustup -ARG CARGO_INDEX_CN=https://rsproxy.cn/crates.io-index -ARG CARGO_REGISTRY_CN=sparse+https://rsproxy.cn/index/ +ARG RUSTUP_DIST_SERVER_CN=https://mirrors.ustc.edu.cn/rust-static +ARG RUSTUP_UPDATE_ROOT_CN=https://mirrors.ustc.edu.cn/rust-static/rustup +ARG CARGO_INDEX_CN=https://mirrors.ustc.edu.cn/crates.io-index +ARG CARGO_REGISTRY_CN=sparse+https://mirrors.ustc.edu.cn/crates.io-index/ ARG LIBJPEG_TURBO_VERSION=3.1.4.1 ARG LIBYUV_REV=957f295ea946cbbd13fcfc46e7066f2efa801233 ARG LIBVPX_VERSION=1.16.0 @@ -37,12 +37,12 @@ RUN apt-get update && apt-get install -y --no-install-recommends \ mkdir -p /root/.cargo; \ printf '%s\n' \ '[source.crates-io]' \ - "replace-with = 'rsproxy-sparse'" \ - '[source.rsproxy]' \ + "replace-with = 'cn-mirror-sparse'" \ + '[source.cn-mirror]' \ "registry = '${CARGO_INDEX_CN}'" \ - '[source.rsproxy-sparse]' \ + '[source.cn-mirror-sparse]' \ "registry = '${CARGO_REGISTRY_CN}'" \ - '[registries.rsproxy]' \ + '[registries.cn-mirror]' \ "index = '${CARGO_INDEX_CN}'" \ '[net]' \ 'git-fetch-with-cli = true' \ diff --git a/build/package-docker.sh b/build/package-docker.sh index 76bfae45..ae113245 100755 --- a/build/package-docker.sh +++ b/build/package-docker.sh @@ -204,9 +204,21 @@ get_tool_urls() { } # Download tools for a platform +# Set CURL_PROXY=http://host:port to route GitHub downloads through an HTTP proxy +# Set GHPROXY_PREFIX=https://ghfast.top/ to prefix GitHub URLs instead download_tools() { local platform="$1" local staging="$2" + local curl_proxy=() + if [ -n "${CURL_PROXY:-}" ]; then + curl_proxy=(-x "$CURL_PROXY") + fi + dl() { + # dl + local url="$1" + [ -n "${GHPROXY_PREFIX:-}" ] && url="${GHPROXY_PREFIX%/}/$url" + curl -fsSL "${curl_proxy[@]}" "$url" -o "$2" + } get_tool_urls "$platform" @@ -214,14 +226,14 @@ download_tools() { # ttyd if [ ! -f "$staging/ttyd" ]; then - curl -fsSL "$TTYD_URL" -o "$staging/ttyd" + dl "$TTYD_URL" "$staging/ttyd" chmod +x "$staging/ttyd" fi if [ "$INCLUDE_THIRD_PARTY" = true ]; then # gostc if [ ! -f "$staging/gostc" ]; then - curl -fsSL "$GOSTC_URL" -o /tmp/gostc.tar.gz + dl "$GOSTC_URL" /tmp/gostc.tar.gz tar -xzf /tmp/gostc.tar.gz -C "$staging" chmod +x "$staging/gostc" rm /tmp/gostc.tar.gz @@ -229,7 +241,7 @@ download_tools() { # easytier if [ ! -f "$staging/easytier-core" ]; then - curl -fsSL "$EASYTIER_URL" -o /tmp/easytier.zip + dl "$EASYTIER_URL" /tmp/easytier.zip unzip -o /tmp/easytier.zip -d /tmp/easytier cp "/tmp/easytier/$EASYTIER_DIR/easytier-core" "$staging/easytier-core" chmod +x "$staging/easytier-core" @@ -311,6 +323,9 @@ build_for_platform() { local build_cmd="docker buildx build --platform $platform" build_cmd="$build_cmd --build-arg TARGETPLATFORM=$platform" + if [ -n "${APT_MIRROR:-}" ]; then + build_cmd="$build_cmd --build-arg APT_MIRROR=$APT_MIRROR" + fi if [ "$PUSH" = true ]; then build_cmd="$build_cmd --push"