Skip to content

Commit

Permalink
chore: Use cargo chef to build
Browse files Browse the repository at this point in the history
And get caching for docker builds

Which should speed things up
  • Loading branch information
philipcristiano committed Nov 23, 2024
1 parent fc04373 commit 5c35c59
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,15 +1,24 @@
FROM rust:1.82-bookworm as builder
WORKDIR /usr/src/app
FROM lukemathwalker/cargo-chef:latest-rust-1.82 AS chef
WORKDIR /app

FROM chef AS planner
COPY . .
RUN cargo chef prepare --recipe-path recipe.json

FROM chef AS builder
COPY --from=planner /app/recipe.json recipe.json
# Build dependencies - this is the caching Docker layer!
RUN cargo chef cook --release --recipe-path recipe.json
# Build application
COPY . .
COPY --from=d3fk/tailwindcss:stable /tailwindcss /usr/local/bin/tailwindcss
ENV SQLX_OFFLINE=true
RUN cargo install --path .
RUN cargo build --release

# We do not need the Rust toolchain to run the binary!
FROM debian:bookworm-slim
RUN apt-get update && apt-get install -y procps ca-certificates && rm -rf /var/lib/apt/lists/*
WORKDIR /app

COPY --from=builder /usr/local/cargo/bin/et-migrate /usr/local/bin/et-migrate
COPY --from=builder /usr/local/cargo/bin/et /usr/local/bin/et
COPY --from=builder /app/target/release/et-migrate /usr/local/bin/et-migrate
COPY --from=builder /app/target/release/et /usr/local/bin/et

ENTRYPOINT ["/usr/local/bin/et"]

0 comments on commit 5c35c59

Please sign in to comment.