From 0413ade74223f8e6c1ae16df5c598149d40bbdc6 Mon Sep 17 00:00:00 2001 From: moonrailgun Date: Mon, 30 Sep 2024 17:21:11 +0800 Subject: [PATCH] chore: downgrade alpine version to 3.19 to avoid issue --- Dockerfile | 12 ++++++++---- src/server/utils/screenshot/lighthouse.ts | 7 ++++--- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/Dockerfile b/Dockerfile index 4c37b72..c6fb51c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -8,7 +8,8 @@ RUN apt update RUN cd reporter && go build . # Base ------------------------------ -FROM node:20-alpine AS base +# The current Chromium version in Alpine 3.20 is causing timeout issues with Puppeteer. Downgrading to Alpine 3.19 fixes the issue. See #11640, #12637, #12189 +FROM node:20-alpine3.19 AS base RUN npm install -g pnpm@9.7.1 RUN apk add --update --no-cache python3 py3-pip g++ make @@ -38,9 +39,12 @@ ENV PUPPETEER_EXECUTABLE_PATH=/usr/bin/chromium-browser ENV DEBUG=puppeteer:* RUN apk add --no-cache \ - udev \ - ttf-freefont \ - chromium + chromium \ + nss \ + freetype \ + harfbuzz \ + ca-certificates \ + ttf-freefont COPY . . diff --git a/src/server/utils/screenshot/lighthouse.ts b/src/server/utils/screenshot/lighthouse.ts index 2bce40b..5a44b5f 100644 --- a/src/server/utils/screenshot/lighthouse.ts +++ b/src/server/utils/screenshot/lighthouse.ts @@ -8,10 +8,9 @@ export async function generateLighthouse(url: string): Promise { const browser = await puppeteer.launch({ // Set to false if you want to see the script in action. headless: 'new', - args: ['--no-sandbox', '--single-process'], + args: ['--no-sandbox', '--single-process', '--disable-dev-shm-usage'], defaultViewport: null, ignoreDefaultArgs: ['--enable-automation'], - dumpio: true, }); try { @@ -31,11 +30,13 @@ export async function generateLighthouse(url: string): Promise { throw new Error('Lighthouse failed to generate report'); } - page.close({ runBeforeUnload: false }); + await page.close({ runBeforeUnload: false }); const { lhr } = res; return lhr; + } catch (err) { + throw err; } finally { await browser.close(); }