From 012caab60699b5643d6ccd02aa2d35259ae5a1e4 Mon Sep 17 00:00:00 2001 From: Trenton Holmes <797416+stumpylog@users.noreply.github.com> Date: Sun, 4 Aug 2024 14:17:18 -0700 Subject: [PATCH 1/2] Use multi-stage building for the monolith binary --- Dockerfile | 40 +++++++++++++++++++++------------------- 1 file changed, 21 insertions(+), 19 deletions(-) diff --git a/Dockerfile b/Dockerfile index d51b65d..e6e8f05 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,16 @@ -FROM node:18.18-bullseye-slim +# Stage: monolith-builder +# Purpose: Uses the Rust image to build monolith +# Notes: +# - Fine to leave extra here, as only the resulting binary is copied out +FROM docker.io/rust:1.80-bullseye AS monolith-builder + +RUN set -eux && cargo install --locked monolith + +# Stage: main-app +# Purpose: Compiles the frontend and +# Notes: +# - Nothing extra should be left here. All commands should cleanup +FROM node:18.18-bullseye-slim AS main-app ARG DEBIAN_FRONTEND=noninteractive @@ -8,25 +20,15 @@ WORKDIR /data COPY ./package.json ./yarn.lock ./playwright.config.ts ./ -RUN --mount=type=cache,sharing=locked,target=/usr/local/share/.cache/yarn yarn install --network-timeout 10000000 +RUN --mount=type=cache,sharing=locked,target=/usr/local/share/.cache/yarn \ + set -eux && \ + yarn install --network-timeout 10000000 -RUN apt-get update +# Copy the compiled monolith binary from the builder stage +COPY --from=monolith-builder /usr/local/cargo/bin/monolith /usr/local/bin/monolith -RUN apt-get install -y \ - build-essential \ - curl \ - libssl-dev \ - pkg-config - -RUN apt-get update - -RUN curl https://sh.rustup.rs -sSf | bash -s -- -y - -ENV PATH="/root/.cargo/bin:${PATH}" - -RUN cargo install monolith - -RUN npx playwright install-deps && \ +RUN set -eux && \ + npx playwright install-deps && \ apt-get clean && \ yarn cache clean @@ -37,4 +39,4 @@ COPY . . RUN yarn prisma generate && \ yarn build -CMD yarn prisma migrate deploy && yarn start \ No newline at end of file +CMD yarn prisma migrate deploy && yarn start From cc1c17363bef568c6d6211eda29b6dd3b9f7664b Mon Sep 17 00:00:00 2001 From: Trenton Holmes <797416+stumpylog@users.noreply.github.com> Date: Wed, 14 Aug 2024 19:48:16 -0700 Subject: [PATCH 2/2] Also install a single browser (Chromium) through Playwright --- Dockerfile | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/Dockerfile b/Dockerfile index e6e8f05..3f222a0 100644 --- a/Dockerfile +++ b/Dockerfile @@ -28,12 +28,10 @@ RUN --mount=type=cache,sharing=locked,target=/usr/local/share/.cache/yarn \ COPY --from=monolith-builder /usr/local/cargo/bin/monolith /usr/local/bin/monolith RUN set -eux && \ - npx playwright install-deps && \ + npx playwright install --with-deps chromium && \ apt-get clean && \ yarn cache clean -RUN yarn playwright install - COPY . . RUN yarn prisma generate && \