-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
32 lines (29 loc) · 1.21 KB
/
Dockerfile
File metadata and controls
32 lines (29 loc) · 1.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# https://github.com/LukeMathWalker/cargo-chef
# https://www.lpalmieri.com/posts/fast-rust-docker-builds/#cargo-chef for an in-depth explanation
FROM lukemathwalker/cargo-chef:latest-rust-1 AS chef
WORKDIR /app
# Force rustup to sync the toolchain in the base layer, so it doesn't happen more than once.
COPY rust-toolchain.toml .
RUN cargo --version
# the checksum of recipe.json will only change if the dependency tree changes
FROM chef AS planner
ARG BIN_NAME
# does not invalidate cache in builder stage, only planner stage
COPY . .
RUN cargo chef prepare --bin ${BIN_NAME} --recipe-path recipe.json
FROM chef AS builder
ARG BIN_NAME
COPY --from=planner /app/recipe.json recipe.json
# Build dependencies - this is the caching Docker layer!
RUN cargo chef cook --release --bin ${BIN_NAME} --recipe-path recipe.json --target x86_64-unknown-linux-gnu
# Build application
COPY . .
RUN cargo build --release --bin ${BIN_NAME} --target x86_64-unknown-linux-gnu
# final image, as small as possible
# Rust runtime depends on libgcc
FROM gcr.io/distroless/cc:nonroot AS runtime
ARG BIN_NAME
WORKDIR /app
COPY --from=builder /app/target/x86_64-unknown-linux-gnu/release/${BIN_NAME} /app/bin
ENV PROXYAPP_PRODUCTION="true"
ENTRYPOINT ["/app/bin"]