FROM rust:1.75-slim-bullseye as builder # Install build dependencies RUN apt-get update && \ apt-get install -y \ pkg-config \ libssl-dev \ libpq-dev \ gcc \ g++ \ make \ clang \ lld \ libomp-dev \ libopenblas-dev \ && rm -rf /var/lib/apt/lists/* # Create a new empty project WORKDIR /app # Create a dummy project to cache dependencies COPY Cargo.toml Cargo.lock ./ RUN mkdir src && \ echo "fn main() {println!(\"dummy\")}" > src/main.rs && \ cargo build --release && \ rm -rf src # Now copy the real source code COPY . . # Build the application in release mode with cargo cache RUN --mount=type=cache,target=/usr/local/cargo/registry \ --mount=type=cache,target=/app/target \ cargo build --release && \ cp target/release/fit_model /app/fit_model # Create the runtime image FROM debian:bullseye-slim # Install runtime dependencies RUN apt-get update && \ apt-get install -y \ libpq5 \ ca-certificates \ libomp5 \ libopenblas0 \ libgomp1 \ && rm -rf /var/lib/apt/lists/* # Copy the binary from builder COPY --from=builder /app/fit_model /usr/local/bin/ COPY --from=builder /app/.env.example /app/.env WORKDIR /app # Set environment variables ENV RUST_LOG=info ENTRYPOINT ["/usr/local/bin/fit_model"]