1+ # syntax=docker/dockerfile:1
2+
13# To produce a smaller image this Dockerfile contains two separate stages: in
24# the first one all the build dependencies are installed and docs.rs is built,
35# while in the second one just the runtime dependencies are installed, with the
46# binary built in the previous stage copied there.
57#
68# As of 2019-10-29 this reduces the image from 2.8GB to 500 MB.
79
10+
811# ################
912# Build stage #
1013# ################
@@ -54,10 +57,10 @@ RUN mkdir -p src/bin && \
5457 echo "fn main() {}" > src/bin/cratesfyi.rs && \
5558 echo "fn main() {}" > build.rs
5659
57- RUN cargo fetch
58-
5960ARG PROFILE=release
60- RUN cargo build --profile=$PROFILE
61+ RUN --mount=type=cache,target=/usr/local/cargo/registry,id=cargo-registry,sharing=locked \
62+ --mount=type=cache,target=/build/target,id=cargo-target,sharing=locked \
63+ cargo build --profile=$PROFILE
6164
6265# Dependencies are now cached, copy the actual source code and do another full
6366# build. The touch on all the .rs files is needed, otherwise cargo assumes the
@@ -74,7 +77,9 @@ COPY assets assets/
7477COPY .sqlx .sqlx/
7578COPY migrations migrations/
7679
77- RUN cargo build --profile=$PROFILE
80+ RUN --mount=type=cache,target=/usr/local/cargo/registry,id=cargo-registry,sharing=locked \
81+ --mount=type=cache,target=/build/target,id=cargo-target,sharing=locked \
82+ cargo build --profile=$PROFILE
7883
7984# #####################
8085# Web server stage #
0 commit comments