chore: docker add puppeteer support

This commit is contained in:
moonrailgun 2024-09-29 01:41:01 +08:00
parent bcc215ca5d
commit 23c691541d
4 changed files with 18 additions and 2 deletions

View File

@ -7,7 +7,7 @@ COPY ./reporter/ ./reporter/
RUN apt update
RUN cd reporter && go build .
# # Base ------------------------------
# Base ------------------------------
FROM node:20-alpine AS base
RUN npm install -g pnpm@9.7.1
@ -32,6 +32,15 @@ RUN pnpm build:static
FROM base AS app
WORKDIR /app/tianji
# We don't need the standalone Chromium
ENV PUPPETEER_SKIP_DOWNLOAD=true
ENV PUPPETEER_EXECUTABLE_PATH=/usr/bin/chromium-browser
RUN apk add --no-cache \
udev \
ttf-freefont \
chromium
COPY . .
RUN pnpm install --filter @tianji/server... --config.dedupe-peer-dependents=false

View File

@ -2,6 +2,9 @@ version: '3'
services:
tianji:
image: moonrailgun/tianji
build:
context: ./
dockerfile: ./Dockerfile
ports:
- "12345:12345"
environment:

View File

@ -52,6 +52,7 @@ export const env = {
sandboxMemoryLimit: process.env.SANDBOX_MEMORY_LIMIT
? Number(process.env.SANDBOX_MEMORY_LIMIT)
: 16, // unit: MB
puppeteerExecutablePath: process.env.PUPPETEER_EXECUTABLE_PATH,
dbDebug: checkEnvTrusty(process.env.DB_DEBUG),
amapToken: process.env.AMAP_TOKEN,
mapboxToken: process.env.MAPBOX_TOKEN,

View File

@ -10,7 +10,10 @@ export async function screenshotWebsiteDetailImage(
websiteId: string,
userId: string
) {
const browser = await puppeteer.launch({ headless: 'new' });
const browser = await puppeteer.launch({
executablePath: env.puppeteerExecutablePath,
headless: 'new',
});
const page = await browser.newPage();
try {
const jwt = jwtSign({