# 1. Build Stage FROM rust:1.78 as builder WORKDIR /usr/src/app # Pre-build dependencies to leverage Docker layer caching COPY ./services/config-service-rs/Cargo.toml ./services/config-service-rs/Cargo.lock* ./services/config-service-rs/ RUN mkdir -p ./services/config-service-rs/src && \ echo "fn main() {}" > ./services/config-service-rs/src/main.rs && \ cargo build --release --bin config-service-rs # Copy the full source code COPY ./services/config-service-rs /usr/src/app/services/config-service-rs COPY ./config /usr/src/app/config # Build the application RUN cargo build --release --bin config-service-rs # 2. Runtime Stage FROM debian:bookworm-slim WORKDIR /app # Set timezone ENV TZ=Asia/Shanghai RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone # Copy the built binary and the config directory from the builder stage COPY --from=builder /usr/src/app/target/release/config-service-rs /usr/local/bin/ COPY --from=builder /usr/src/app/config ./config # Set the binary as the entrypoint ENTRYPOINT ["/usr/local/bin/config-service-rs"]