Skip to content
Open
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
30 changes: 20 additions & 10 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,33 +1,43 @@
FROM --platform=$BUILDPLATFORM rust:latest AS base

# for build tools
FROM --platform=$BUILDPLATFORM rust:1.85-bookworm AS tools
RUN apt-get update && apt-get install -y \
build-essential \
&& rm -rf /var/lib/apt/lists/*
RUN rustup toolchain install nightly-2024-09-17 \
&& rustup default nightly

RUN --mount=type=cache,target=/usr/local/cargo/registry \
--mount=type=cache,target=/usr/local/cargo/git \
cargo install cargo-chef --version ^0.1

# for build base
FROM --platform=$BUILDPLATFORM rust:1.85-bookworm AS base
RUN apt-get update && apt-get install -y \
build-essential \
&& rm -rf /var/lib/apt/lists/*
RUN rustup toolchain install nightly-2024-09-17 \
&& rustup default nightly

RUN cargo install sccache --version ^0.7
RUN cargo install cargo-chef --version ^0.1
ENV RUSTC_WRAPPER=sccache SCCACHE_DIR=/sccache
COPY --from=tools /usr/local/cargo/bin/cargo-chef /usr/local/cargo/bin/

FROM base AS planner
WORKDIR /usr/src/app
COPY . .
RUN --mount=type=cache,target=/usr/local/cargo/registry \
--mount=type=cache,target=$SCCACHE_DIR,sharing=locked \
--mount=type=cache,target=/usr/local/cargo/git \
--mount=type=cache,target=/usr/src/app/target \
cargo chef prepare --recipe-path recipe.json

FROM base AS builder
ENV SQLX_OFFLINE=true
WORKDIR /usr/src/app
COPY --from=planner /usr/src/app/recipe.json recipe.json
RUN --mount=type=cache,target=/usr/local/cargo/registry \
--mount=type=cache,target=$SCCACHE_DIR,sharing=locked \
--mount=type=cache,target=/usr/local/cargo/git \
--mount=type=cache,target=/usr/src/app/target \
cargo chef cook --release --recipe-path recipe.json
COPY . .
ENV SQLX_OFFLINE=true
RUN --mount=type=cache,target=/usr/local/cargo/registry \
--mount=type=cache,target=$SCCACHE_DIR,sharing=locked \
cargo build -r

FROM debian:bookworm-slim
Expand All @@ -52,4 +62,4 @@ ARG PORT
ENV PORT=${PORT}
EXPOSE ${PORT}

ENTRYPOINT ["/bin/sh", "-c"]
ENTRYPOINT ["/bin/sh", "-c"]
Loading