@@ -6,16 +6,33 @@ RUN echo "deb http://mirrors.aliyun.com/debian/ bookworm main contrib non-free n
66 echo "deb http://mirrors.aliyun.com/debian/ bookworm-updates main contrib non-free non-free-firmware" >> /etc/apt/sources.list && \
77 echo "deb http://mirrors.aliyun.com/debian-security bookworm-security main contrib non-free non-free-firmware" >> /etc/apt/sources.list
88
9- # 配置Rust镜像源
10- ENV RUSTUP_DIST_SERVER=https://mirrors.tuna.tsinghua.edu.cn/rustup
11- ENV RUSTUP_UPDATE_ROOT=https://mirrors.tuna.tsinghua.edu.cn/rustup/rustup
9+ # 配置Rust镜像源和网络超时设置
10+ ENV RUSTUP_DIST_SERVER=https://mirrors.ustc.edu.cn/rust-static
11+ ENV RUSTUP_UPDATE_ROOT=https://mirrors.ustc.edu.cn/rust-static/rustup
12+ ENV CARGO_NET_RETRY=10
13+ ENV CARGO_NET_TIMEOUT=300
14+ ENV CARGO_HTTP_TIMEOUT=300
15+ ENV CARGO_NET_GIT_FETCH_WITH_CLI=true
16+
1217RUN mkdir -p ~/.cargo && \
1318 echo '[source.crates-io]' > ~/.cargo/config.toml && \
14- echo 'replace-with = "tuna"' >> ~/.cargo/config.toml && \
15- echo '[source.tuna]' >> ~/.cargo/config.toml && \
16- echo 'registry = "https://mirrors.tuna.tsinghua.edu.cn/git/crates.io-index.git"' >> ~/.cargo/config.toml
17-
18- RUN cargo install cargo-chef
19+ echo 'replace-with = "ustc"' >> ~/.cargo/config.toml && \
20+ echo '' >> ~/.cargo/config.toml && \
21+ echo '[source.ustc]' >> ~/.cargo/config.toml && \
22+ echo 'registry = "https://mirrors.ustc.edu.cn/crates.io-index"' >> ~/.cargo/config.toml && \
23+ echo '' >> ~/.cargo/config.toml && \
24+ echo '[net]' >> ~/.cargo/config.toml && \
25+ echo 'retry = 10' >> ~/.cargo/config.toml && \
26+ echo 'timeout = 300' >> ~/.cargo/config.toml && \
27+ echo '' >> ~/.cargo/config.toml && \
28+ echo '[http]' >> ~/.cargo/config.toml && \
29+ echo 'timeout = 300' >> ~/.cargo/config.toml
30+
31+ # 预先拉取 cargo-chef 源码以避免网络问题
32+ RUN git clone --depth 1 https://mirrors.ustc.edu.cn/crates.io-index.git /tmp/crates-index || \
33+ git clone --depth 1 https://github.com/rust-lang/crates.io-index.git /tmp/crates-index || true
34+
35+ RUN cargo install cargo-chef --timeout 600
1936WORKDIR /app
2037
2138FROM chef AS planner
@@ -30,12 +47,25 @@ RUN echo "deb http://mirrors.aliyun.com/debian/ bookworm main contrib non-free n
3047 echo "deb http://mirrors.aliyun.com/debian/ bookworm-updates main contrib non-free non-free-firmware" >> /etc/apt/sources.list && \
3148 echo "deb http://mirrors.aliyun.com/debian-security bookworm-security main contrib non-free non-free-firmware" >> /etc/apt/sources.list
3249
33- # 配置Rust镜像源
50+ # 配置Rust镜像源和网络超时设置
51+ ENV CARGO_NET_RETRY=10
52+ ENV CARGO_NET_TIMEOUT=300
53+ ENV CARGO_HTTP_TIMEOUT=300
54+ ENV CARGO_NET_GIT_FETCH_WITH_CLI=true
55+
3456RUN mkdir -p ~/.cargo && \
3557 echo '[source.crates-io]' > ~/.cargo/config.toml && \
36- echo 'replace-with = "tuna"' >> ~/.cargo/config.toml && \
37- echo '[source.tuna]' >> ~/.cargo/config.toml && \
38- echo 'registry = "https://mirrors.tuna.tsinghua.edu.cn/git/crates.io-index.git"' >> ~/.cargo/config.toml
58+ echo 'replace-with = "ustc"' >> ~/.cargo/config.toml && \
59+ echo '' >> ~/.cargo/config.toml && \
60+ echo '[source.ustc]' >> ~/.cargo/config.toml && \
61+ echo 'registry = "https://mirrors.ustc.edu.cn/crates.io-index"' >> ~/.cargo/config.toml && \
62+ echo '' >> ~/.cargo/config.toml && \
63+ echo '[net]' >> ~/.cargo/config.toml && \
64+ echo 'retry = 10' >> ~/.cargo/config.toml && \
65+ echo 'timeout = 300' >> ~/.cargo/config.toml && \
66+ echo '' >> ~/.cargo/config.toml && \
67+ echo '[http]' >> ~/.cargo/config.toml && \
68+ echo 'timeout = 300' >> ~/.cargo/config.toml
3969
4070# Install system dependencies
4171RUN apt-get update && apt-get install -y \
@@ -45,11 +75,11 @@ RUN apt-get update && apt-get install -y \
4575 && rm -rf /var/lib/apt/lists/*
4676
4777# Build dependencies - this layer is cached
48- RUN cargo chef cook --release --recipe-path recipe.json
78+ RUN cargo chef cook --release --recipe-path recipe.json --timeout 600
4979
5080# Copy source code and build application
5181COPY . .
52- RUN cargo build --release
82+ RUN CARGO_NET_RETRY=10 CARGO_NET_TIMEOUT=300 cargo build --release --timeout 600
5383
5484# Runtime stage
5585FROM debian:bookworm-slim AS runtime
0 commit comments