Skip to content

Commit

Permalink
Optimize Dockerfile
Browse files Browse the repository at this point in the history
  • Loading branch information
LostLuma committed Nov 16, 2024
1 parent 42678ba commit 1171d89
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions echo/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,15 @@ RUN mkdir bin && \
apt update -y && apt upgrade -y && apt install -y musl-tools && \
rustup target add x86_64-unknown-linux-musl

# Mounting src using bind mount is slower for some reason
COPY src src

# NOTE: Due to caching this is actually faster than using
# Two separate cargo builds (one without source present).
RUN --mount=type=cache,target=target \
--mount=type=cache,target=/usr/local/cargo/git \
--mount=type=cache,target=/usr/local/cargo/registry \
--mount=type=bind,source=src,target=src \
--mount=type=bind,source=openapi.json,target=openapi.json \
--mount=type=bind,source=Cargo.toml,target=Cargo.toml,readwrite \
--mount=type=bind,source=Cargo.lock,target=Cargo.lock,readwrite \
--mount=type=bind,source=openapi.json,target=openapi.json,readwrite \
# Use musl target as the binary is about 1MiB smaller
cargo build --profile $PROFILE --target x86_64-unknown-linux-musl && \
# The "dev" target directory is named "debug" instead
Expand Down

0 comments on commit 1171d89

Please sign in to comment.