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.
This commit is contained in:
Brian Tarricone 2023-09-16 00:06:13 -07:00
parent bddff51ab3
commit 1dcba64095

View File

@ -2,7 +2,15 @@ FROM rust:1.72-slim-bullseye AS builder
WORKDIR /bebot-build 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 RUN cargo build --release
FROM debian:bookworm-slim FROM debian:bookworm-slim