From 1dcba640957b14d02d97f54e9e1488ac25468b12 Mon Sep 17 00:00:00 2001 From: "Brian J. Tarricone" Date: Sat, 16 Sep 2023 00:06:13 -0700 Subject: [PATCH] Speed up docker rebuilds This should keep all the dependency build artifacts in a cached layer below the layer that builds our app and links the final binary. --- Dockerfile | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 94e5c89..76dfbc4 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,7 +2,15 @@ FROM rust:1.72-slim-bullseye AS builder WORKDIR /bebot-build -COPY . ./ +# Build and cache dependencies +COPY Cargo.toml Cargo.lock ./ +RUN mkdir -p src && echo 'fn main() {}' > src/main.rs +RUN cargo build --release + +# Build and link our app +RUN rm -rf src +COPY src ./src +RUN touch src/main.rs RUN cargo build --release FROM debian:bookworm-slim