0
0
Fork 0
mirror of https://git.verdigado.com/NB-Public/simple-wkd.git synced 2024-12-06 14:52:41 +01:00

Improve docker build speed

This commit is contained in:
Delta1925 2023-04-25 14:44:14 +02:00
parent ed6ade53d8
commit 692b5e6cd1
No known key found for this signature in database
GPG key ID: 1C21ACE44193CB25
3 changed files with 54 additions and 15 deletions

View file

@ -2,26 +2,29 @@ ARG base="alpine:3.17"
FROM ${base} AS bin-builder
# Disable static linking, see: https://users.rust-lang.org/t/sigsegv-with-program-linked-against-openssl-in-an-alpine-container/52172
# Enable cargo sparse index for faster update times, see: https://blog.rust-lang.org/inside-rust/2023/01/30/cargo-sparse-protocol.html
ENV RUSTFLAGS='-C target-feature=-crt-static' \
CARGO_REGISTRIES_CRATES_IO_PROTOCOL=sparse
RUN apk add --no-cache cargo openssl-dev musl-dev
# This will build all dependencies and store them in docker's cache.
# This way, it won't be necessary to recompile everything everytime
# It also disables static linking, see: https://users.rust-lang.org/t/sigsegv-with-program-linked-against-openssl-in-an-alpine-container/52172
COPY backend/Cargo.toml .
COPY backend/Cargo.lock .
RUN echo '[[bin]]' >> Cargo.toml && \
echo 'name = "cache"' >> Cargo.toml && \
echo 'path = "cache.rs"' >> Cargo.toml && \
echo 'fn main() {eprintln!("Caching crates...")}' > cache.rs && \
RUSTFLAGS='-C target-feature=-crt-static' cargo build --release
cargo build --release
RUN rm cache.rs && \
rm Cargo.toml
# Build wimple-wkd
COPY backend/Cargo.toml .
COPY backend/src src
RUN RUSTFLAGS='-C target-feature=-crt-static' cargo build --release
RUN cargo build --release
FROM ${base} AS webpage-builder
FROM --platform=$BUILDPLATFORM ${base} AS webpage-builder
RUN apk add --no-cache npm
COPY website .