-
Notifications
You must be signed in to change notification settings - Fork 2
Optimize: size #6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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 | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Lets use specific version, with all 3 numbers. prevents unwanted breaks in future |
||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| # 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/* | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+16
to
+24
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Build may fail: removing /var/cache/apk as non-root This Move privileged cleanup under root (or ignore errors): USER chrome
-RUN pnpm install --prod --frozen-lockfile && \
+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/*
+ find /app/node_modules -name ".cache" -type d -exec rm -rf {} + 2>/dev/null || true && \
+ # clean up user caches
+ rm -rf ~/.pnpm ~/.npm /tmp/*
+
+# remove apk cache as root
+USER root
+RUN rm -rf /var/cache/apk/* || true
+USER chrome📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents
Comment on lines
+19
to
+24
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead of this, we can try and use tool we use in Open Runtimes; it knows a bit more files and paths: |
||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| # production stage | ||||||||||||||||||||||||||||||||||||||||||||||||||
| FROM zenika/alpine-chrome:with-node | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A bit worryin to use non-official image without specifying version. Lets stick to node alpine image, and install specific version of chromium There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. its OSS - using this and then node creates issues. |
||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| # 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/ | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. lets copy entire src directory |
||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| 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"] | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 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 |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -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"; | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
|
|
@@ -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!"); | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
|
|
@@ -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), | ||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||
|
Comment on lines
37
to
42
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Header schema allows non-string values; Playwright expects strings Current -headers: z.record(z.string(), z.any()).default({}),
+headers: z.record(z.string(), z.string()).default({}),If you must allow booleans/numbers, coerce: -headers: z.record(z.string(), z.any()).default({}),
+headers: z
+ .record(z.string(), z.union([z.string(), z.number(), z.boolean()]))
+ .default({})
+ .transform((h) =>
+ Object.fromEntries(Object.entries(h).map(([k, v]) => [k, String(v)])),
+ ),📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| router.post( | ||||||||||||||||||||||||||||
| "/v1/screenshots", | ||||||||||||||||||||||||||||
| defineEventHandler(async (event) => { | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Align PNPM version with packageManager field
package.json pins
packageManager: pnpm@9.12.1but Docker installs pnpm@10. This may desync lockfile semantics.Option A (keep lockfile as-is):
Option B (if you prefer pnpm 10): bump package.json’s packageManager and regenerate lockfile.
📝 Committable suggestion
🤖 Prompt for AI Agents