Repository navigation
Expand file tree
/
Copy pathDockerfile.web-scraper
More file actions
66 lines (58 loc) · 3.47 KB
/
Copy pathDockerfile.web-scraper
File metadata and controls
66 lines (58 loc) · 3.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
FROM --platform=$BUILDPLATFORM node:24.21.0-trixie-slim@sha256:173f125896c3b47ddf056734c7ea789d04595a6a08769a8f78e0df642781fb66 AS builder
WORKDIR /app
# Copy workspace root `package.json` and `package-lock.json` files,
# and `package.json` file from the component, to just install dependencies.
COPY ["./*.json", "./"]
COPY ["./components/retrack-web-scraper/package.json", "./components/retrack-web-scraper/"]
RUN set -x && npm ci --ws
# Now copy the rest of the component files, test and build it.
COPY ["./components/retrack-web-scraper", "./components/retrack-web-scraper"]
RUN set -x && npm test --ws
RUN set -x && npm run build --ws
FROM node:24.21.0-trixie-slim@sha256:173f125896c3b47ddf056734c7ea789d04595a6a08769a8f78e0df642781fb66
ENV NODE_ENV=production \
PLAYWRIGHT_BROWSERS_PATH=/ms-playwright \
RETRACK_WEB_SCRAPER_BROWSER_CHROMIUM_EXECUTABLE_PATH=/usr/local/bin/chromium
WORKDIR /app
EXPOSE 7272
# Install system dependencies: dumb-init, fonts, and the minimal set of shared
# libraries that Chromium actually links against (instead of `playwright install
# --with-deps` which pulls in ~350 MB of Mesa/LLVM/X11 packages).
RUN set -x && apt-get update && \
apt-get install -y --no-install-recommends \
dumb-init fonts-freefont-ttf fonts-noto-color-emoji fonts-wqy-zenhei fontconfig \
libasound2 libatk-bridge2.0-0 libatk1.0-0 libcairo2 libcups2 libdbus-1-3 \
libdrm2 libgbm1 libglib2.0-0 libnspr4 libnss3 libpango-1.0-0 \
libx11-6 libxcomposite1 libxdamage1 libxext6 libxfixes3 libxkbcommon0 \
libxrandr2 && \
rm -rf /var/lib/apt/lists/*
COPY ./dev/docker/chromium_local.conf /etc/fonts/local.conf
RUN set -x && fc-cache -fv
# Preserve the workspace layout (root + leaf package.json + workspace lock
# file) so `npm ci` can resolve the web-scraper's deps via its workspace entry.
# Flattening these files into /app fails with npm >= 11 because the workspace
# lockfile records dependencies under `packages."components/retrack-web-scraper"`,
# not under the top-level `packages.""` key.
COPY --from=builder ["/app/package.json", "/app/package-lock.json", "./"]
COPY --from=builder ["/app/components/retrack-web-scraper/package.json", "./components/retrack-web-scraper/"]
COPY --from=builder ["/app/components/retrack-web-scraper/dist/", "./components/retrack-web-scraper/"]
# Install production dependencies for the web-scraper workspace only, then use
# Playwright to install only the Chromium binary (no --with-deps). Create a
# stable symlink so the app can find the binary regardless of the Playwright
# revision number. Post-install cleanup: remove headless-shell, ffmpeg, all but
# en-US locale.
RUN set -x && npm ci --omit=dev --workspace=retrack-web-scraper --include-workspace-root=false && \
npm exec --workspace=retrack-web-scraper --no -- playwright-core install chromium && \
rm -rf /ms-playwright/chromium_headless_shell-* && \
rm -rf /ms-playwright/ffmpeg-* && \
find /ms-playwright -path '*/locales/*' ! -name 'en-US.pak' -delete && \
CHROMIUM_BIN=$(find /ms-playwright -name chrome -type f -path '*/chrome-linux*/chrome' | head -1) && \
echo "Playwright installed Chromium at: $CHROMIUM_BIN" && \
ln -sf "$CHROMIUM_BIN" /usr/local/bin/chromium && \
npm cache clean --force && \
rm -rf /usr/local/lib/node_modules && \
rm -rf /opt/yarn-* && \
rm -f /usr/local/bin/npm /usr/local/bin/npx /usr/local/bin/yarn
USER node
ENTRYPOINT ["/usr/bin/dumb-init", "--"]
CMD ["node", "components/retrack-web-scraper/src/index.js"]