# Base image with all dependencies pre-compiled
# Build once, use for all services

FROM ci.nxtgauge.com/admin/rust:alpine AS chef
RUN apk add --no-cache musl-dev pkgconfig openssl-dev && \
    rustup target add x86_64-unknown-linux-musl && \
    cargo install cargo-chef

WORKDIR /app

# Copy all manifests
COPY Cargo.toml Cargo.lock ./
COPY crates/ ./crates/
COPY apps/ ./apps/

# Prepare and cook all dependencies
RUN cargo chef prepare --recipe-path recipe.json && \
    cargo chef cook --release --target x86_64-unknown-linux-musl --recipe-path recipe.json

# Keep this layer as the base
FROM chef

# The target directory now has all dependencies compiled!
# Services can copy just their source and build instantly
