From 9e3315e09f31ac87499f450e554e332a2fefa81b Mon Sep 17 00:00:00 2001 From: Valentin Tolmer Date: Fri, 24 Sep 2021 09:07:55 +0200 Subject: [PATCH] docker: add cargo chef to the dockerfile to cache dependencies --- Dockerfile | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/Dockerfile b/Dockerfile index 7b9e2c9..ea53838 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,5 @@ # Build image -FROM rust:alpine AS builder +FROM rust:alpine AS chef RUN set -x \ # Add user @@ -17,15 +17,27 @@ USER app WORKDIR /app RUN set -x \ # Install build tools - && RUSTFLAGS=-Ctarget-feature=-crt-static cargo install wasm-pack \ - && npm install rollup -# Build -COPY --chown=app:app . /app + && RUSTFLAGS=-Ctarget-feature=-crt-static cargo install wasm-pack cargo-chef \ + && npm install rollup \ + && rustup target add wasm32-unknown-unknown + +# Prepare the dependency list. +FROM chef AS planner +COPY . . +RUN cargo chef prepare --recipe-path recipe.json + +# Build dependencies +FROM chef AS builder +COPY --from=planner /app/recipe.json recipe.json +RUN cargo chef cook --release -p lldap --recipe-path recipe.json \ + && cargo chef cook --release -p lldap_app --target wasm32-unknown-unknown + +# Copy the source and build the app. +COPY --chown=app:app . . RUN cargo build --release -p lldap # TODO: release mode. RUN ./app/build.sh - # Final image FROM alpine