Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
# install and optimize dependencies
FROM zenika/alpine-chrome:with-node AS base

WORKDIR /app

# copy package files
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
# install pnpm as root,
# then switch back to chrome user
USER root
RUN npm install -g pnpm@10

# install dependencies as normal user
USER chrome
RUN pnpm install --prod --frozen-lockfile && \
pnpm prune --prod && \
# remove unnecessary files to reduce image size
find /app/node_modules -name "*.md" -delete && \
find /app/node_modules -type d -name "test*" -exec rm -rf {} + 2>/dev/null || true && \
find /app/node_modules -type d -name "doc*" -exec rm -rf {} + 2>/dev/null || true && \
find /app/node_modules -name ".cache" -type d -exec rm -rf {} + 2>/dev/null || true && \
# clean up caches
rm -rf ~/.pnpm ~/.npm /tmp/* /var/cache/apk/*

# production stage
FROM zenika/alpine-chrome:with-node

# environment configuration
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 application files
COPY package.json ./
COPY --from=base /app/node_modules ./node_modules
COPY src/index.js ./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"]
# start the application
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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"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,6 +20,7 @@ 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!");

Expand All @@ -36,9 +37,10 @@ const defaultContext = {
const screenshotSchema = z.object({
url: z.string().url(),
theme: z.enum(["light", "dark"]).default("light"),
headers: z.record(z.string(), z.any()),
headers: z.record(z.string(), z.any()).default({}),
sleep: z.number().min(0).max(60000).default(3000),
});

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