# Multi-stage build for Corrosion API # Stage 1: Build the Rust binary FROM rust:latest AS builder RUN apt-get update && apt-get install -y pkg-config libssl-dev && rm -rf /var/lib/apt/lists/* WORKDIR /build # Cache dependencies — copy manifests first COPY Cargo.toml ./ COPY Cargo.lock* ./ RUN mkdir src && echo "fn main() {}" > src/main.rs RUN cargo build --release 2>/dev/null || true # Now copy actual source and build COPY src/ src/ COPY migrations/ migrations/ RUN touch src/main.rs && cargo build --release # Stage 2: Runtime image FROM debian:bookworm-slim RUN apt-get update && apt-get install -y ca-certificates && rm -rf /var/lib/apt/lists/* WORKDIR /app COPY --from=builder /build/target/release/corrosion-api . COPY migrations/ migrations/ ENV RUST_LOG=corrosion_api=info,tower_http=info EXPOSE 3000 CMD ["./corrosion-api"]