From b3a888670cbe4cfdc14838dfc06dbfc62945aedd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20Rame=CC=81?= Date: Sat, 24 Feb 2024 02:10:34 +0100 Subject: [PATCH] fix: switch again because playwright does not manage proper install into alpine images, better to rely on official package even if version not aligned exactly --- Dockerfile | 27 +++++++++++++++++++-------- src/features/domain.ts | 4 +++- 2 files changed, 22 insertions(+), 9 deletions(-) diff --git a/Dockerfile b/Dockerfile index 51050c7..652c6a9 100644 --- a/Dockerfile +++ b/Dockerfile @@ -5,7 +5,6 @@ ARG NODE_VERSION=18.19.0 ARG RUBY_VERSION=3.2.2-r1 ARG PIP_VERSION=23.3.1-r0 ARG PRISMA_VERSION=4.16.2 -ARG PLAYWRIGHT_VERSION=1.39.0 ARG APP_HOST=172.17.0.2 ARG PORT=3000 @@ -14,18 +13,33 @@ FROM node:${NODE_VERSION}-alpine ARG RUBY_VERSION ARG PIP_VERSION ARG PRISMA_VERSION -ARG PLAYWRIGHT_VERSION ARG APP_HOST ARG PORT -RUN apk add --no-cache \ +USER root + +RUN apk add \ + # This is for the code we manage "build-base" \ "libffi-dev" \ "libcurl" \ "curl" \ "ruby-dev=${RUBY_VERSION}" \ - "py3-pip=${PIP_VERSION}" -RUN apk update + "py3-pip=${PIP_VERSION}" \ + # This is the dependencies needed by chromium + "chromium" \ + "libstdc++" \ + "harfbuzz" \ + "nss" \ + "freetype" \ + "ttf-freefont" \ + "font-noto-emoji" \ + "wqy-zenhei" + +ENV CHROME_BIN="/usr/bin/chromium-browser" +ENV CHROME_PATH="/usr/lib/chromium/" + +ENV PLAYWRIGHT_CHROMIUM_EXECUTABLE_PATH="${CHROME_BIN}" # Restrict the permissions @@ -60,9 +74,6 @@ RUN python3 -m venv ./venv \ ENV PATH="/app/venv/bin:$PATH" -# We use `npx` to install browsers needed to avoid using `npm run playwright install --with-deps chromium` since we build as standalone the entire application and we no longer want to rely application `node_modules` folder -RUN npx --yes playwright@${PLAYWRIGHT_VERSION} install --with-deps chromium - # Manage the final server build COPY --chown=nextjs:nodejs ".next/standalone" ./ diff --git a/src/features/domain.ts b/src/features/domain.ts index bf2b44c..63ec7a2 100644 --- a/src/features/domain.ts +++ b/src/features/domain.ts @@ -512,7 +512,9 @@ export async function updateWebsiteDataOnDomains() { }, }); - const browser = await chromium.launch(); + const browser = await chromium.launch({ + executablePath: process.env.PLAYWRIGHT_CHROMIUM_EXECUTABLE_PATH, + }); try { for (const [rawDomainIndex, rawDomain] of Object.entries(rawDomains)) { watchGracefulExitInLoop();