Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 14 additions & 5 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
.git
.mypy_cache
.pytest_cache
.ruff_cache
target
**/*
!rust-toolchain.toml
!Cargo.toml
!Cargo.lock
!.cargo
!crates
!proto
!python
!core-python
!scripts
!README.md

!example_app

**/__pycache__
*.pyc
*.pyo
Expand Down
56 changes: 16 additions & 40 deletions example_app/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,22 +1,19 @@
# syntax=docker/dockerfile:1.7

# =============================================================================
# Stage 1: cargo-chef planner - analyze dependencies
# =============================================================================
FROM rust:1.88-bookworm AS planner
FROM rust:1.88-bookworm AS rust-base
WORKDIR /repo
COPY rust-toolchain.toml .
RUN rustup toolchain install

FROM rust-base AS rust-base-chef
RUN cargo install cargo-chef --locked

FROM rust-base-chef AS rust-planner
WORKDIR /repo
COPY Cargo.toml Cargo.lock build.rs /repo/
COPY src /repo/src
COPY proto /repo/proto
COPY waymark-observability-macros /repo/waymark-observability-macros
COPY . .
RUN cargo chef prepare --recipe-path recipe.json

# =============================================================================
# Stage 2: cargo-chef cook - build dependencies (cached layer)
# =============================================================================
FROM rust:1.88-bookworm AS cacher

FROM rust-base-chef AS rust-builder
ENV DEBIAN_FRONTEND=noninteractive
RUN apt-get update && apt-get install -y --no-install-recommends \
pkg-config \
Expand All @@ -26,48 +23,27 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
protobuf-compiler \
&& rm -rf /var/lib/apt/lists/*

RUN cargo install cargo-chef --locked
WORKDIR /repo
COPY --from=planner /repo/recipe.json recipe.json
# Build dependencies - this layer is cached unless Cargo.toml/Cargo.lock change
FROM rust-builder AS rust-cacher
COPY --from=rust-planner /repo/recipe.json recipe.json
RUN --mount=type=cache,target=/root/.cargo/registry \
--mount=type=cache,target=/root/.cargo/git \
cargo chef cook --release --recipe-path recipe.json

# =============================================================================
# Stage 3: Build the actual binaries (fast - deps already compiled)
# =============================================================================
FROM rust:1.88-bookworm AS wheel-builder

ENV DEBIAN_FRONTEND=noninteractive
FROM rust-builder AS wheel-builder
RUN apt-get update && apt-get install -y --no-install-recommends \
python3 \
python3-venv \
python3-pip \
curl \
pkg-config \
libssl-dev \
build-essential \
libprotobuf-dev \
protobuf-compiler \
&& rm -rf /var/lib/apt/lists/*
RUN curl -LsSf https://astral.sh/uv/install.sh | sh
ENV PATH="/root/.local/bin:${PATH}"

WORKDIR /repo

# Copy cached dependencies from cacher stage
COPY --from=cacher /repo/target target
COPY --from=rust-cacher /repo/target target

# Copy source files
COPY Cargo.toml Cargo.lock build.rs README.md /repo/
COPY src /repo/src
COPY proto /repo/proto
COPY waymark-observability-macros /repo/waymark-observability-macros
COPY python /repo/python
COPY scripts /repo/scripts
COPY templates /repo/templates
COPY migrations /repo/migrations
COPY . .

# Build - only recompiles your code, not dependencies
RUN --mount=type=cache,target=/root/.cargo/registry \
Expand All @@ -92,7 +68,7 @@ WORKDIR /app
COPY example_app /app

# Copy templates for the webapp dashboard
COPY templates /app/templates
COPY crates/waymark/templates /app/templates

RUN uv venv /opt/venv
ENV VIRTUAL_ENV=/opt/venv
Expand Down
Loading