From 6ebf6d89703b0babadd4e6783629054f70cb0ab2 Mon Sep 17 00:00:00 2001 From: "mn.albeschenko" Date: Fri, 15 Dec 2023 15:01:40 +0300 Subject: [PATCH 1/2] build: add Dockerfile --- Dockerfile | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 Dockerfile diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 000000000..4a4c34265 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,27 @@ +# Improve build speed with cached deps +ARG RUST_VERSION=1.70.0 +FROM lukemathwalker/cargo-chef:latest-rust-${RUST_VERSION} AS chef +WORKDIR /app + +FROM chef AS planner +COPY . . +RUN cargo chef prepare --recipe-path recipe.json + +FROM chef AS builder +COPY --from=planner /app/recipe.json recipe.json +# Build dependencies - this is the caching Docker layer! +RUN cargo chef cook --release --recipe-path recipe.json +# Build application +COPY . . +RUN cargo build --release + +# why we dont use alpine for base image - https://andygrove.io/2020/05/why-musl-extremely-slow/ +FROM debian:bookworm as runtime + +COPY --from=builder /app/target/release/rustic /usr/local/bin + +# usually container will be used with --rm option +# so we ignore cache +ENV RUSTIC_NO_CACHE=true + +ENTRYPOINT ["/usr/local/bin/rustic"] \ No newline at end of file From c172da00a401a159483a91d56b22fb45f039a543 Mon Sep 17 00:00:00 2001 From: "mn.albeschenko" Date: Fri, 15 Dec 2023 17:56:01 +0300 Subject: [PATCH 2/2] build: migrate to slim image, delete RUSTIC_NO_CACHE --- Dockerfile | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/Dockerfile b/Dockerfile index 4a4c34265..b569e0801 100644 --- a/Dockerfile +++ b/Dockerfile @@ -16,12 +16,8 @@ COPY . . RUN cargo build --release # why we dont use alpine for base image - https://andygrove.io/2020/05/why-musl-extremely-slow/ -FROM debian:bookworm as runtime +FROM debian:bookworm-slim as runtime COPY --from=builder /app/target/release/rustic /usr/local/bin -# usually container will be used with --rm option -# so we ignore cache -ENV RUSTIC_NO_CACHE=true - ENTRYPOINT ["/usr/local/bin/rustic"] \ No newline at end of file