Skip to content

Commit a6d8c61

Browse files
committed
build(docker): 将国内镜像源从清华切换为阿里云并添加备选方案
将主Dockerfile中的APT镜像源从清华镜像站切换为阿里云镜像站以提高稳定性 同时新增一个备选Dockerfile使用网易镜像源作为替代方案
1 parent 358498f commit a6d8c61

3 files changed

Lines changed: 127 additions & 12 deletions

File tree

backend/Dockerfile.china

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
FROM rust:1.86.0-slim AS chef
33

44
# 配置国内镜像源加速
5-
RUN echo "deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm main contrib non-free non-free-firmware" > /etc/apt/sources.list && \
6-
echo "deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm-updates main contrib non-free non-free-firmware" >> /etc/apt/sources.list && \
7-
echo "deb https://mirrors.tuna.tsinghua.edu.cn/debian-security bookworm-security main contrib non-free non-free-firmware" >> /etc/apt/sources.list
5+
RUN echo "deb http://mirrors.aliyun.com/debian/ bookworm main contrib non-free non-free-firmware" > /etc/apt/sources.list && \
6+
echo "deb http://mirrors.aliyun.com/debian/ bookworm-updates main contrib non-free non-free-firmware" >> /etc/apt/sources.list && \
7+
echo "deb http://mirrors.aliyun.com/debian-security bookworm-security main contrib non-free non-free-firmware" >> /etc/apt/sources.list
88

99
# 配置Rust镜像源
1010
ENV RUSTUP_DIST_SERVER=https://mirrors.tuna.tsinghua.edu.cn/rustup
@@ -26,9 +26,9 @@ FROM chef AS builder
2626
COPY --from=planner /app/recipe.json recipe.json
2727

2828
# 配置国内镜像源
29-
RUN echo "deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm main contrib non-free non-free-firmware" > /etc/apt/sources.list && \
30-
echo "deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm-updates main contrib non-free non-free-firmware" >> /etc/apt/sources.list && \
31-
echo "deb https://mirrors.tuna.tsinghua.edu.cn/debian-security bookworm-security main contrib non-free non-free-firmware" >> /etc/apt/sources.list
29+
RUN echo "deb http://mirrors.aliyun.com/debian/ bookworm main contrib non-free non-free-firmware" > /etc/apt/sources.list && \
30+
echo "deb http://mirrors.aliyun.com/debian/ bookworm-updates main contrib non-free non-free-firmware" >> /etc/apt/sources.list && \
31+
echo "deb http://mirrors.aliyun.com/debian-security bookworm-security main contrib non-free non-free-firmware" >> /etc/apt/sources.list
3232

3333
# 配置Rust镜像源
3434
RUN mkdir -p ~/.cargo && \
@@ -55,9 +55,9 @@ RUN cargo build --release
5555
FROM debian:bookworm-slim AS runtime
5656

5757
# 配置国内镜像源
58-
RUN echo "deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm main contrib non-free non-free-firmware" > /etc/apt/sources.list && \
59-
echo "deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm-updates main contrib non-free non-free-firmware" >> /etc/apt/sources.list && \
60-
echo "deb https://mirrors.tuna.tsinghua.edu.cn/debian-security bookworm-security main contrib non-free non-free-firmware" >> /etc/apt/sources.list
58+
RUN echo "deb http://mirrors.aliyun.com/debian/ bookworm main contrib non-free non-free-firmware" > /etc/apt/sources.list && \
59+
echo "deb http://mirrors.aliyun.com/debian/ bookworm-updates main contrib non-free non-free-firmware" >> /etc/apt/sources.list && \
60+
echo "deb http://mirrors.aliyun.com/debian-security bookworm-security main contrib non-free non-free-firmware" >> /etc/apt/sources.list
6161

6262
# Install runtime dependencies
6363
RUN apt-get update && apt-get install -y \

backend/Dockerfile.china-alt

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
# Multi-stage build for Rust backend with multiple China mirror options
2+
FROM rust:1.86.0-slim AS chef
3+
4+
# 配置多个国内镜像源选择 - 使用最稳定的镜像源
5+
RUN echo "deb http://mirrors.163.com/debian/ bookworm main contrib non-free non-free-firmware" > /etc/apt/sources.list && \
6+
echo "deb http://mirrors.163.com/debian/ bookworm-updates main contrib non-free non-free-firmware" >> /etc/apt/sources.list && \
7+
echo "deb http://mirrors.163.com/debian-security bookworm-security main contrib non-free non-free-firmware" >> /etc/apt/sources.list
8+
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+
RUN mkdir -p ~/.cargo && \
13+
echo '[source.crates-io]' > ~/.cargo/config.toml && \
14+
echo 'replace-with = "ustc"' >> ~/.cargo/config.toml && \
15+
echo '[source.ustc]' >> ~/.cargo/config.toml && \
16+
echo 'registry = "git://mirrors.ustc.edu.cn/crates.io-index"' >> ~/.cargo/config.toml
17+
18+
# 设置apt选项以避免交互和证书问题
19+
ENV DEBIAN_FRONTEND=noninteractive
20+
RUN echo 'Acquire::Check-Valid-Until "false";' > /etc/apt/apt.conf.d/99no-check-valid-until && \
21+
echo 'Acquire::http::Pipeline-Depth "0";' >> /etc/apt/apt.conf.d/99no-check-valid-until && \
22+
echo 'Acquire::http::No-Cache "true";' >> /etc/apt/apt.conf.d/99no-check-valid-until && \
23+
echo 'Acquire::BrokenProxy "true";' >> /etc/apt/apt.conf.d/99no-check-valid-until
24+
25+
RUN cargo install cargo-chef
26+
WORKDIR /app
27+
28+
FROM chef AS planner
29+
COPY . .
30+
RUN cargo chef prepare --recipe-path recipe.json
31+
32+
FROM chef AS builder
33+
COPY --from=planner /app/recipe.json recipe.json
34+
35+
# 配置网易镜像源
36+
RUN echo "deb http://mirrors.163.com/debian/ bookworm main contrib non-free non-free-firmware" > /etc/apt/sources.list && \
37+
echo "deb http://mirrors.163.com/debian/ bookworm-updates main contrib non-free non-free-firmware" >> /etc/apt/sources.list && \
38+
echo "deb http://mirrors.163.com/debian-security bookworm-security main contrib non-free non-free-firmware" >> /etc/apt/sources.list
39+
40+
# 配置Rust镜像源
41+
RUN mkdir -p ~/.cargo && \
42+
echo '[source.crates-io]' > ~/.cargo/config.toml && \
43+
echo 'replace-with = "ustc"' >> ~/.cargo/config.toml && \
44+
echo '[source.ustc]' >> ~/.cargo/config.toml && \
45+
echo 'registry = "git://mirrors.ustc.edu.cn/crates.io-index"' >> ~/.cargo/config.toml
46+
47+
# Install system dependencies with retry mechanism
48+
RUN apt-get clean && \
49+
rm -rf /var/lib/apt/lists/* && \
50+
apt-get update --fix-missing -o Acquire::CompressionTypes::Order::=gz && \
51+
apt-get install -y --no-install-recommends \
52+
pkg-config \
53+
libssl-dev \
54+
ca-certificates \
55+
build-essential \
56+
&& rm -rf /var/lib/apt/lists/* \
57+
&& apt-get clean
58+
59+
# Build dependencies - this layer is cached
60+
RUN cargo chef cook --release --recipe-path recipe.json
61+
62+
# Copy source code and build application
63+
COPY . .
64+
RUN cargo build --release
65+
66+
# Runtime stage
67+
FROM debian:bookworm-slim AS runtime
68+
69+
# 配置网易镜像源(运行时)
70+
RUN echo "deb http://mirrors.163.com/debian/ bookworm main contrib non-free non-free-firmware" > /etc/apt/sources.list && \
71+
echo "deb http://mirrors.163.com/debian/ bookworm-updates main contrib non-free non-free-firmware" >> /etc/apt/sources.list && \
72+
echo "deb http://mirrors.163.com/debian-security bookworm-security main contrib non-free non-free-firmware" >> /etc/apt/sources.list
73+
74+
# 设置apt选项
75+
ENV DEBIAN_FRONTEND=noninteractive
76+
RUN echo 'Acquire::Check-Valid-Until "false";' > /etc/apt/apt.conf.d/99no-check-valid-until && \
77+
echo 'Acquire::http::Pipeline-Depth "0";' >> /etc/apt/apt.conf.d/99no-check-valid-until && \
78+
echo 'Acquire::http::No-Cache "true";' >> /etc/apt/apt.conf.d/99no-check-valid-until
79+
80+
# Install runtime dependencies
81+
RUN apt-get clean && \
82+
rm -rf /var/lib/apt/lists/* && \
83+
apt-get update --fix-missing && \
84+
apt-get install -y --no-install-recommends \
85+
ca-certificates \
86+
libssl3 \
87+
curl \
88+
&& rm -rf /var/lib/apt/lists/* \
89+
&& apt-get clean
90+
91+
# Create non-root user
92+
RUN groupadd -r bloguser && useradd -r -g bloguser bloguser
93+
94+
WORKDIR /app
95+
96+
# Copy binary and config
97+
COPY --from=builder /app/target/release/backend /app/backend
98+
COPY --from=builder /app/config.docker.toml /app/config.toml
99+
100+
# Set ownership
101+
RUN chown -R bloguser:bloguser /app
102+
USER bloguser
103+
104+
EXPOSE 8080
105+
106+
# Health check
107+
HEALTHCHECK --interval=30s --timeout=10s --start-period=60s --retries=3 \
108+
CMD curl -f http://localhost:8080/health || exit 1
109+
110+
CMD ["./backend"]
111+
112+
# Production optimized stage
113+
FROM runtime AS production
114+
ENV RUST_LOG=info
115+
ENV RUST_BACKTRACE=0

blog-web/Dockerfile.china

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
FROM rust:1.86.0-slim AS wasm-builder
55

66
# 配置国内镜像源加速
7-
RUN echo "deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm main contrib non-free non-free-firmware" > /etc/apt/sources.list && \
8-
echo "deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm-updates main contrib non-free non-free-firmware" >> /etc/apt/sources.list && \
9-
echo "deb https://mirrors.tuna.tsinghua.edu.cn/debian-security bookworm-security main contrib non-free non-free-firmware" >> /etc/apt/sources.list
7+
RUN echo "deb http://mirrors.aliyun.com/debian/ bookworm main contrib non-free non-free-firmware" > /etc/apt/sources.list && \
8+
echo "deb http://mirrors.aliyun.com/debian/ bookworm-updates main contrib non-free non-free-firmware" >> /etc/apt/sources.list && \
9+
echo "deb http://mirrors.aliyun.com/debian-security bookworm-security main contrib non-free non-free-firmware" >> /etc/apt/sources.list
1010

1111
# 配置Rust镜像源
1212
ENV RUSTUP_DIST_SERVER=https://mirrors.tuna.tsinghua.edu.cn/rustup

0 commit comments

Comments
 (0)