Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 38 additions & 14 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,19 +1,43 @@
FROM node:22-slim AS base
ENV PNPM_HOME="/pnpm"
ENV PATH="$PNPM_HOME:$PATH"
RUN corepack enable
FROM node:22.13.1-alpine3.20 AS base

WORKDIR /app

COPY package.json pnpm-lock.yaml ./
RUN corepack prepare

FROM base AS prod-deps
RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm install --prod --frozen-lockfile
RUN npm install -g [email protected]

RUN pnpm install --prod --frozen-lockfile && \
rm -rf ~/.pnpm ~/.npm /tmp/* /var/cache/apk/*

FROM node:22.13.1-alpine3.20 AS final

RUN apk upgrade --no-cache --available && \
apk add --no-cache \
chromium \
ttf-freefont \
font-noto-emoji \
tini && \
apk add --no-cache font-wqy-zenhei --repository=http://dl-cdn.alpinelinux.org/alpine/edge/community && \
# remove unnecessary chromium files to save space
rm -rf /usr/lib/chromium/chrome_crashpad_handler \
/usr/lib/chromium/chrome_200_percent.pak \
/usr/lib/chromium/chrome_100_percent.pak \
/usr/lib/chromium/xdg-mime \
/usr/lib/chromium/xdg-settings \
/usr/lib/chromium/chrome-sandbox

RUN addgroup -S chrome && adduser -S -G chrome chrome

ENV PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD=1 \
PLAYWRIGHT_CHROMIUM_EXECUTABLE_PATH=/usr/bin/chromium-browser \
NODE_ENV=production

WORKDIR /app
USER chrome

FROM base AS build
COPY . .
COPY package.json ./
COPY --from=base /app/node_modules ./node_modules
COPY src/ ./src/

FROM base
COPY --from=prod-deps /app/node_modules /app/node_modules
RUN pnpm playwright install --with-deps chromium
COPY --from=build /app/src/index.js /app/src/index.js
CMD ["pnpm", "start"]
ENTRYPOINT ["tini", "--"]
CMD ["node", "src/index.js"]
10 changes: 10 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
services:
appwrite-browser:
build:
context: .
dockerfile: Dockerfile
image: appwrite/browser:local
ports:
- "3000:3000"
environment:
- PORT=3000
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@
"keywords": [],
"author": "",
"license": "ISC",
"packageManager": "pnpm@9.12.1+sha512.e5a7e52a4183a02d5931057f7a0dbff9d5e9ce3161e33fa68ae392125b79282a8a8a470a51dfc8a0ed86221442eb2fb57019b0990ed24fab519bf0e1bc5ccfc4",
"packageManager": "pnpm@10.20.0",
"dependencies": {
"h3": "^1.13.0",
"lighthouse": "^12.2.1",
"playwright": "^1.52.0",
"playwright-core": "^1.52.0",
"playwright-lighthouse": "^4.0.0",
"zod": "^3.23.8"
},
Expand Down
35 changes: 8 additions & 27 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
import { readValidatedBody } from "h3";
import lighthouseDesktopConfig from "lighthouse/core/config/lr-desktop-config.js";
import lighthouseMobileConfig from "lighthouse/core/config/lr-mobile-config.js";
import { chromium } from "playwright";
import { chromium } from "playwright-core";
import { playAudit } from "playwright-lighthouse";
import { z } from "zod";

Expand All @@ -20,12 +20,13 @@ const router = createRouter();
console.log("Chromium starting...");
const browser = await chromium.launch({
args: ["--remote-debugging-port=9222"],
executablePath: process.env.PLAYWRIGHT_CHROMIUM_EXECUTABLE_PATH,
});
console.log("Chromium started!");

app.use(router);

/** @type {Partial<import('playwright').BrowserContext>} defaultContext */
/** @type {Partial<import('playwright-core').BrowserContext>} defaultContext */
const defaultContext = {
viewport: {
width: 1280,
Expand Down Expand Up @@ -121,6 +122,7 @@ const screenshotSchema = z.object({
hasTouch: z.boolean().default(false),
isMobile: z.boolean().default(false),
});

router.post(
"/v1/screenshots",
defineEventHandler(async (event) => {
Expand Down