0
0
Fork 0
mirror of https://git.verdigado.com/NB-Public/simple-wkd.git synced 2024-12-05 03:32:49 +01:00

Improve dockerfile

This commit is contained in:
Delta1925 2023-04-23 15:44:32 +02:00
parent 695f5b8559
commit 9b412b9f12
No known key found for this signature in database
GPG key ID: 1C21ACE44193CB25

View file

@ -1,31 +1,25 @@
FROM rust:1.68-alpine3.17 AS bin-builder
# Install dependencies
RUN apk add --no-cache openssl-dev openssl-libs-static musl-dev
RUN apk add --no-cache 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
# OPENSSL_STATIC is required, see: https://users.rust-lang.org/t/sigsegv-with-program-linked-against-openssl-in-an-alpine-container/52172 and https://users.rust-lang.org/t/how-to-link-openssl-statically/14912
# Disable 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 && \
export OPENSSL_STATIC=1 && \
export OPENSSL_LIB_DIR=/usr/lib && \
export OPENSSL_INCLUDE_DIR=/usr/include/openssl && \
cargo build --release
RUSTFLAGS='-C target-feature=-crt-static' cargo build --release
RUN rm cache.rs && \
rm Cargo.toml
# Build wimple-wkd
COPY backend/Cargo.toml .
COPY backend/src src
RUN export OPENSSL_STATIC=1 && \
export OPENSSL_LIB_DIR=/usr/lib &&\
export OPENSSL_INCLUDE_DIR=/usr/include/openssl && \
cargo build --release
RUN RUSTFLAGS='-C target-feature=-crt-static' cargo build --release
FROM node:19-alpine3.17 AS webpage-builder
@ -45,8 +39,10 @@ FROM alpine:3.17
# Put everything together
# It uses user `wkd` for added security
# Install libgcc, because the executable is dynamically linked to it
WORKDIR /wkd
RUN adduser --no-create-home --disabled-password wkd && \
RUN apk add --no-cache libgcc && \
adduser --no-create-home --disabled-password wkd && \
chown -R wkd:wkd /wkd
USER wkd
COPY --from=webpage-builder assets assets