From 40d84246c2f49b04a5dc975440bbc858fc86f4cd Mon Sep 17 00:00:00 2001 From: benthecarman Date: Sun, 1 Oct 2023 01:36:55 -0500 Subject: [PATCH] Staged dockerfile --- Dockerfile | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/Dockerfile b/Dockerfile index 22f741f..b4f6969 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,12 +1,26 @@ -FROM rust:1.70-slim +FROM rust:1.67-slim as builder -RUN apt-get update && \ - apt-get install -y clang cmake build-essential +WORKDIR /usr/src/app +COPY . . -WORKDIR /app +# Will build and cache the binary and dependent crates in release mode +RUN --mount=type=cache,target=/usr/local/cargo,from=rust:latest,source=/usr/local/cargo \ + --mount=type=cache,target=target \ + cargo build --target --release && mv ./targe/release/mutinynet-faucet-rs ./mutinynet-faucet-rs -COPY . . +# Runtime image +FROM debian:bookworm-slim + +RUN apt update && apt install -y openssl libpq-dev pkg-config libc6 clang cmake build-essential + +# Run as "app" user +RUN useradd -ms /bin/bash app + +USER app +WORKDIR /app -RUN cargo build --release +# Get compiled binaries from builder's cargo install directory +COPY --from=builder /usr/src/app/mutinynet-faucet-rs /app/mutinynet-faucet-rs -ENTRYPOINT ["/bin/bash", "-c", "./target/release/mutinynet-faucet-rs ${FLAGS}"] +# Run the app +CMD ./mutinynet-faucet-rs