cuddle-rust-plan/templates/build_release.Dockerfile

40 lines
1.0 KiB
Docker
Raw Permalink Normal View History

FROM rust:1.70 AS chef
# We only pay the installation cost once,
# it will be cached from the second build onwards
RUN <<EOF
curl -L --proto '=https' --tlsv1.2 -sSf https://raw.githubusercontent.com/cargo-bins/cargo-binstall/main/install-from-binstall-release.sh | bash
EOF
2022-08-10 22:54:58 +02:00
ENV DOCKER_BUILD=true
ENV SQLX_OFFLINE true
2022-08-11 22:34:57 +02:00
RUN <<EOF
apt update -y && apt install -y libc6-dev libssl-dev libpq-dev
EOF
RUN cargo binstall --no-confirm --no-symlinks cargo-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
ARG BIN_NAME
2022-08-10 22:54:58 +02:00
COPY . .
RUN cargo build --release --bin $BIN_NAME
# We do not need the Rust toolchain to run the binary!
FROM debian:buster-slim as runtime
ARG BIN_NAME
WORKDIR app
2022-08-10 22:54:58 +02:00
COPY --from=builder /app/target/release/$BIN_NAME /usr/local/bin
CMD ["/usr/local/bin/$BIN_NAME"]
2022-08-11 01:16:13 +02:00