Skip to content
# My custom dockerfile

# Build stage
FROM rust:1.75-slim-bookworm AS builder

WORKDIR /app

# Install cargo-chef to cache dependencies
RUN cargo install cargo-chef

# Plan stage - generate recipe.json for dependencies
FROM builder AS planner
COPY . .
RUN cargo chef prepare --recipe-path recipe.json

# Build stage with caching
FROM builder AS build

# Copy recipe.json first to cache dependency compilation
COPY --from=planner /app/recipe.json recipe.json

# Build dependencies (cached if recipe.json hasn't changed)
RUN cargo chef cook --release --recipe-path recipe.json

# Copy source code (this invalidates cache only when source changes)
COPY . .

# Build the actual application (dependencies are already cached)
RUN cargo build --release

# Runtime stage
FROM debian:bookworm-slim

# Install runtime dependencies
RUN apt-get update && apt-get install -y \
    ca-certificates \
    libssl3 \
    && rm -rf /var/lib/apt/lists/*

WORKDIR /app

COPY --from=build /app/target/release/spruce /app/

CMD ["./spruce"]