diff --git a/.dockerignore b/.dockerignore index 14223596..d8615035 100644 --- a/.dockerignore +++ b/.dockerignore @@ -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 diff --git a/example_app/Dockerfile b/example_app/Dockerfile index a302f308..aa4c5f20 100644 --- a/example_app/Dockerfile +++ b/example_app/Dockerfile @@ -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 \ @@ -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 \ @@ -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