From 42bfc2540bd8d77f25a4651935a36774e989dada Mon Sep 17 00:00:00 2001 From: uh wot Date: Mon, 5 Dec 2022 16:24:18 +0100 Subject: [PATCH] updated dockerfile https://github.com/fly-apps/hello-rust/pull/9 --- Dockerfile | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) diff --git a/Dockerfile b/Dockerfile index 1d4444d..1f52724 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,20 +1,11 @@ FROM rust:latest as builder -# Make a fake Rust app to keep a cached layer of compiled crates -RUN USER=root cargo new app WORKDIR /usr/src/app -COPY Cargo.toml Cargo.lock ./ -# Needs at least a main.rs file with a main function -RUN mkdir src && echo "fn main(){}" > src/main.rs -# Will build all dependent crates in release mode -RUN --mount=type=cache,target=/usr/local/cargo/registry \ - --mount=type=cache,target=/usr/src/app/target \ - cargo build --release - -# Copy the rest COPY . . -# Build (install) the actual binaries -RUN cargo install --path . +# 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 --release && mv ./target/release/dzmedia ./dzmedia # Runtime image FROM debian:bullseye-slim @@ -26,6 +17,6 @@ USER app WORKDIR /app # Get compiled binaries from builder's cargo install directory -COPY --from=builder /usr/local/cargo/bin/dzmedia /app/dzmedia +COPY --from=builder /usr/src/app/dzmedia /app/dzmedia # No CMD or ENTRYPOINT, see fly.toml with `cmd` override. \ No newline at end of file