# 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

# Copy everything
COPY Cargo.toml Cargo.lock* ./
COPY src/ src/
COPY migrations/ migrations/

# Build with sqlx offline mode to skip compile-time query verification
# Runtime validation still occurs - just no compile-time type checking
ENV SQLX_OFFLINE=true
RUN 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 --from=builder /build/migrations/ migrations/

ENV RUST_LOG=corrosion_api=info,tower_http=info

EXPOSE 3000

CMD ["./corrosion-api"]
