# 1. Build Stage FROM rust:1.90 as builder WORKDIR /usr/src/app # Pre-build dependencies to leverage Docker layer caching COPY ./services/common-contracts /usr/src/app/services/common-contracts COPY ./services/api-gateway/Cargo.toml ./services/api-gateway/Cargo.lock* ./services/api-gateway/ WORKDIR /usr/src/app/services/api-gateway RUN mkdir -p src && \ echo "fn main() {}" > src/main.rs && \ cargo build --release --bin api-gateway # Copy the full source code COPY ./services/api-gateway /usr/src/app/services/api-gateway # Build the application WORKDIR /usr/src/app/services/api-gateway RUN cargo build --release --bin api-gateway # 2. Runtime Stage FROM debian:bookworm-slim # Set timezone ENV TZ=Asia/Shanghai RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone RUN apt-get update && apt-get install -y --no-install-recommends ca-certificates libssl3 && rm -rf /var/lib/apt/lists/* # Copy the built binary from the builder stage COPY --from=builder /usr/src/app/services/api-gateway/target/release/api-gateway /usr/local/bin/ # Set the binary as the entrypoint ENTRYPOINT ["/usr/local/bin/api-gateway"]