Skip to content

Commit c9b2f41

Browse files
committed
try cache mounts for cache
1 parent 0f4a9c3 commit c9b2f41

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

dockerfiles/Dockerfile

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
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-
5960
ARG 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/
7477
COPY .sqlx .sqlx/
7578
COPY 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

Comments
 (0)