From 09dbe7dedb8d518878294435390213336ffde0d7 Mon Sep 17 00:00:00 2001 From: Chiko Date: Wed, 20 Nov 2024 14:57:47 +0000 Subject: [PATCH] feat(docker): improve Dockerfile by caching cargo dependencies Enhance the Dockerfile by adding a step to cache cargo dependencies, which reduces build time. Separate the installation of diesel_cli to streamline the process. The changes ensure a more efficient build process by including only necessary steps and managing dependencies effectively. --- Dockerfile | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index 0fa3310..2d20e03 100644 --- a/Dockerfile +++ b/Dockerfile @@ -9,8 +9,17 @@ ARG DIESEL_CLI_VERSION=2.2.4 RUN apt-get update \ && apt-get install -y postgresql \ - && rm -rf /var/lib/apt/lists/* \ - && cargo install diesel_cli --version $DIESEL_CLI_VERSION --no-default-features --features postgres + && rm -rf /var/lib/apt/lists/* + +# Install diesel-cli +RUN cargo install diesel_cli --version $DIESEL_CLI_VERSION --no-default-features --features postgres + +# Cache cargo dependencies +COPY Cargo.toml Cargo.lock ./ +COPY build.rs ./ +RUN mkdir src && echo "fn main() {}" > src/main.rs \ + && cargo build --release \ + && rm -rf src COPY . .