2023-04-17 15:27:15 +02:00
FROM rust:1.68-alpine3.17 AS bin-builder
2023-04-16 16:04:14 +02:00
2023-04-17 21:45:03 +02:00
# Install dependencies
2023-04-17 15:27:15 +02:00
RUN apk add --no-cache openssl-dev openssl-libs-static musl-dev
2023-04-17 21:45:03 +02:00
# This will build all dependencies and store them in docker's cache.
# This way, it won't be necessary to recompile everything everytime
2023-04-17 23:26:13 +02:00
# 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
2023-04-17 21:45:03 +02:00
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
RUN rm cache.rs && \
rm Cargo.toml
# Build wimple-wkd
COPY backend/Cargo.toml .
COPY backend/src src
2023-04-17 15:27:15 +02:00
RUN export OPENSSL_STATIC = 1 && \
export OPENSSL_LIB_DIR = /usr/lib && \
export OPENSSL_INCLUDE_DIR = /usr/include/openssl && \
cargo build --release
2023-04-16 16:04:14 +02:00
2023-04-17 15:27:15 +02:00
FROM node:19-alpine3.17 AS webpage-builder
2023-04-16 16:04:14 +02:00
2023-04-17 21:45:03 +02:00
# Build website
2023-04-16 16:04:14 +02:00
COPY website .
RUN npm install -g pnpm && \
pnpm install && \
pnpm run build
COPY assets assets
2023-04-17 21:45:03 +02:00
# Move website in templates folder
2023-04-16 16:04:14 +02:00
RUN mv dist assets/webpage
2023-04-17 15:27:15 +02:00
FROM alpine:3.17
2023-04-16 16:04:14 +02:00
2023-04-17 21:45:03 +02:00
# Put everything together
# It uses user `wkd` for added security
2023-04-16 18:28:16 +02:00
WORKDIR /wkd
2023-04-17 15:27:15 +02:00
RUN adduser --no-create-home --disabled-password wkd && \
chown -R wkd:wkd /wkd
2023-04-16 18:28:16 +02:00
USER wkd
2023-04-16 16:04:14 +02:00
COPY --from= webpage-builder assets assets
2023-04-16 18:28:16 +02:00
COPY --from= bin-builder target/release/simple-wkd wkd
ENTRYPOINT [ "/wkd/wkd" ]