FROM docker.io/alpine:3.18.0 as alpine FROM docker.io/lukemathwalker/cargo-chef:latest-rust-1.69.0 as chef FROM codycraven/sassc:3.6.1 as css SHELL ["/bin/ash", "-eo", "pipefail", "-c"] ENV PYTHONUNBUFFERED=1 RUN apk add --update --no-cache python3=3.7.10-r0 WORKDIR /usr/src/scss COPY ./compile_css.py . RUN chmod +x ./compile_css.py COPY ./scss ./src RUN ./compile_css.py ./src ./dist FROM chef as planner WORKDIR /usr/src/frontend RUN mkdir src && touch src/main.rs COPY ./Cargo.toml ./Cargo.lock ./ RUN cargo chef prepare --recipe-path recipe.json FROM chef as builder SHELL ["/bin/bash", "-o", "pipefail", "-c"] WORKDIR /usr/local/bin ARG TRUNK_VERSION="v0.16.0" RUN wget -qO- https://github.com/thedodd/trunk/releases/download/${TRUNK_VERSION}/trunk-x86_64-unknown-linux-gnu.tar.gz | tar -xzf- RUN rustup target add wasm32-unknown-unknown WORKDIR /usr/src/frontend COPY ./.cargo ./.cargo COPY --from=planner /usr/src/frontend/recipe.json . RUN cargo chef cook --release --recipe-path recipe.json COPY ./build.rs . COPY ./schema.graphql ./query.graphql ./ RUN cargo build --release --frozen --offline COPY ./src ./src RUN cargo build --release --frozen --offline COPY --from=css /usr/src/scss/dist ./css COPY ./index.html ./index.html RUN trunk build --release FROM git.dergrimm.net/dergrimm/minify:2.12.5 as public WORKDIR /usr/src/public COPY --from=builder /usr/src/frontend/dist . RUN minify . -r -o . FROM alpine as binaryen SHELL ["/bin/ash", "-eo", "pipefail", "-c"] WORKDIR /tmp ARG BINARYEN_VERSION="110" RUN wget -qO- https://github.com/WebAssembly/binaryen/releases/download/version_${BINARYEN_VERSION}/binaryen-version_${BINARYEN_VERSION}-x86_64-linux.tar.gz | tar -xzf- RUN cp ./binaryen-version_${BINARYEN_VERSION}/bin/wasm-opt /usr/local/bin && \ rm -rf ./binaryen-version_${BINARYEN_VERSION} WORKDIR /usr/src/public COPY --from=public /usr/src/public . RUN find . -name "*.wasm" -type f -print0 | xargs -0 -I % wasm-opt % -o % -O --intrinsic-lowering -Oz FROM docker.io/openresty/openresty:1.21.4.1-0-alpine as runner COPY ./nginx.conf /usr/local/openresty/nginx/conf/nginx.conf COPY --from=binaryen /usr/src/public /var/www/html EXPOSE 80