updated dockerfile

https://github.com/fly-apps/hello-rust/pull/9
This commit is contained in:
uh wot 2022-12-05 16:24:18 +01:00
parent 16cf5dc79b
commit 42bfc2540b
Signed by: uhwot
GPG Key ID: CB2454984587B781
1 changed files with 5 additions and 14 deletions

View File

@ -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.