Skip to content

Commit e2a3f38

Browse files
authored
Merge pull request #6 from appwrite/smaller-size
2 parents de2f7df + fb7c215 commit e2a3f38

File tree

5 files changed

+62
-45
lines changed

5 files changed

+62
-45
lines changed

Dockerfile

Lines changed: 38 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,43 @@
1-
FROM node:22-slim AS base
2-
ENV PNPM_HOME="/pnpm"
3-
ENV PATH="$PNPM_HOME:$PATH"
4-
RUN corepack enable
1+
FROM node:22.13.1-alpine3.20 AS base
2+
53
WORKDIR /app
4+
65
COPY package.json pnpm-lock.yaml ./
7-
RUN corepack prepare
86

9-
FROM base AS prod-deps
10-
RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm install --prod --frozen-lockfile
7+
RUN npm install -g [email protected]
8+
9+
RUN pnpm install --prod --frozen-lockfile && \
10+
rm -rf ~/.pnpm ~/.npm /tmp/* /var/cache/apk/*
11+
12+
FROM node:22.13.1-alpine3.20 AS final
13+
14+
RUN apk upgrade --no-cache --available && \
15+
apk add --no-cache \
16+
chromium \
17+
ttf-freefont \
18+
font-noto-emoji \
19+
tini && \
20+
apk add --no-cache font-wqy-zenhei --repository=http://dl-cdn.alpinelinux.org/alpine/edge/community && \
21+
# remove unnecessary chromium files to save space
22+
rm -rf /usr/lib/chromium/chrome_crashpad_handler \
23+
/usr/lib/chromium/chrome_200_percent.pak \
24+
/usr/lib/chromium/chrome_100_percent.pak \
25+
/usr/lib/chromium/xdg-mime \
26+
/usr/lib/chromium/xdg-settings \
27+
/usr/lib/chromium/chrome-sandbox
28+
29+
RUN addgroup -S chrome && adduser -S -G chrome chrome
30+
31+
ENV PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD=1 \
32+
PLAYWRIGHT_CHROMIUM_EXECUTABLE_PATH=/usr/bin/chromium-browser \
33+
NODE_ENV=production
34+
35+
WORKDIR /app
36+
USER chrome
1137

12-
FROM base AS build
13-
COPY . .
38+
COPY package.json ./
39+
COPY --from=base /app/node_modules ./node_modules
40+
COPY src/ ./src/
1441

15-
FROM base
16-
COPY --from=prod-deps /app/node_modules /app/node_modules
17-
RUN pnpm playwright install --with-deps chromium
18-
COPY --from=build /app/src/index.js /app/src/index.js
19-
CMD ["pnpm", "start"]
42+
ENTRYPOINT ["tini", "--"]
43+
CMD ["node", "src/index.js"]

docker-compose.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
services:
2+
appwrite-browser:
3+
build:
4+
context: .
5+
dockerfile: Dockerfile
6+
image: appwrite/browser:local
7+
ports:
8+
- "3000:3000"
9+
environment:
10+
- PORT=3000

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@
1414
"keywords": [],
1515
"author": "",
1616
"license": "ISC",
17-
"packageManager": "pnpm@9.12.1+sha512.e5a7e52a4183a02d5931057f7a0dbff9d5e9ce3161e33fa68ae392125b79282a8a8a470a51dfc8a0ed86221442eb2fb57019b0990ed24fab519bf0e1bc5ccfc4",
17+
"packageManager": "pnpm@10.20.0",
1818
"dependencies": {
1919
"h3": "^1.13.0",
2020
"lighthouse": "^12.2.1",
21-
"playwright": "^1.52.0",
21+
"playwright-core": "^1.52.0",
2222
"playwright-lighthouse": "^4.0.0",
2323
"zod": "^3.23.8"
2424
},

pnpm-lock.yaml

Lines changed: 8 additions & 27 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/index.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
import { readValidatedBody } from "h3";
99
import lighthouseDesktopConfig from "lighthouse/core/config/lr-desktop-config.js";
1010
import lighthouseMobileConfig from "lighthouse/core/config/lr-mobile-config.js";
11-
import { chromium } from "playwright";
11+
import { chromium } from "playwright-core";
1212
import { playAudit } from "playwright-lighthouse";
1313
import { z } from "zod";
1414

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

2627
app.use(router);
2728

28-
/** @type {Partial<import('playwright').BrowserContext>} defaultContext */
29+
/** @type {Partial<import('playwright-core').BrowserContext>} defaultContext */
2930
const defaultContext = {
3031
viewport: {
3132
width: 1280,
@@ -121,6 +122,7 @@ const screenshotSchema = z.object({
121122
hasTouch: z.boolean().default(false),
122123
isMobile: z.boolean().default(false),
123124
});
125+
124126
router.post(
125127
"/v1/screenshots",
126128
defineEventHandler(async (event) => {

0 commit comments

Comments
 (0)