Repository navigation
Expand file tree
/
Copy pathDockerfile.web-scraper-camoufox
More file actions
84 lines (78 loc) · 4.93 KB
/
Copy pathDockerfile.web-scraper-camoufox
File metadata and controls
84 lines (78 loc) · 4.93 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# syntax=docker/dockerfile:1
FROM python:3.14.10-slim-trixie@sha256:3cabfd7d7aaf394e6040e79fa1eec6ca1c52b74ed9188650472695d9a9326999
EXPOSE 7777
ENV CAMOUFOX_PORT=7777
ENV CAMOUFOX_WS_PATH=camoufox
ENV CAMOUFOX_USE_MAIN_WORLD=true
ENV CAMOUFOX_HEADLESS=true
WORKDIR /app
# Layer 1: OS deps (Firefox runtime libraries + init). No git/curl needed: the
# camoufox library and its browser builds are fetched over HTTP from PyPI and the
# daijro release repo via `requests`, and playwright-python now ships as a proper
# PyPI wheel (no git clone of a release branch).
RUN set -x \
&& apt-get update \
&& apt-get install -y --no-install-recommends \
libgtk-3-0 libx11-xcb1 libasound2 dumb-init \
&& rm -rf /var/lib/apt/lists/*
# Layer 2: Camoufox install + fetch
#
# We use the OFFICIAL `camoufox` package (daijro) rather than the `cloverlabs-camoufox`
# fork. The fork's `launchServer.js` still does `require(${cwd}/lib/browserServerImpl.js)`,
# a driver internal that playwright 1.60 removed, so it crash-loops on playwright >= 1.60.
# The official package resolves Playwright through the driver's public `index.js` entrypoint
# and calls the public `firefox.launchServer()` API. Camoufox 0.5.9b6 requires playwright<1.63.
# The Playwright server rejects clients from another minor (HTTP 428), so the scraper's
# `playwright-core` must stay on the same minor as this image.
# fpgen's indexed-zstd dependency needs a native build on Python 3.14 arm64.
# Remove the build tools after pip install, keeping libzstd1 for the runtime.
#
# CAMOUFOX_VERSION is the Firefox version to pin (NOT the build label). The build label is
# resolved from the synced repo cache below rather than hardcoded, because daijro has in the
# past tagged the *same* version with a *different* build label per architecture.
#
# Three upstream gotchas, all guarded below so they fail the build loudly instead of silently
# shipping a browser-less image that crash-loops at runtime with `CamoufoxNotInstalled`:
# 1. `camoufox fetch <id>` exits 0 even when the build is absent from the cache.
# 2. The build label can be architecture-specific, so we resolve it from the platform-filtered
# cache rather than hardcoding it.
# 3. The official package's multiversion installer lays the browser down under
# `browsers/official/<version>-<build>-<sha8>` — i.e. with an 8-char sha suffix appended to
# the `<version>-<build>` id — and only treats it as installed once a `version.json` marker
# exists in that folder. So we locate the install by `<version>-<build>` *prefix* and assert
# its `version.json`, instead of matching the bare id (which never matches the sha-suffixed dir).
#
# The browser is a ~1.3 GB download from the daijro release repo, so it is fetched into a
# BuildKit cache mount rather than straight into the image: `camoufox fetch` treats an install
# carrying a `version.json` as already present and skips the download, so any later rebuild of
# this layer (a base image bump, an edit above) reuses the zip instead of re-downloading it on
# whatever connection the machine has. `camoufox` resolves its cache through `platformdirs`,
# hence `XDG_CACHE_HOME`. Copy the result into the runtime cache afterwards:
# cache mounts are not part of the image, and runtime sets no `XDG_CACHE_HOME`.
ARG CAMOUFOX_VERSION=158.0.1
ARG CAMOUFOX_BUILD_LABEL=beta.41
RUN --mount=type=cache,target=/root/.cache/pip \
--mount=type=cache,target=/camoufox-cache,sharing=locked \
set -eux \
&& apt-get update \
&& apt-get install -y --no-install-recommends build-essential libzstd-dev libzstd1 \
&& pip install camoufox==0.5.9b6 playwright==1.62.0 \
&& apt-get purge -y --auto-remove build-essential libzstd-dev \
&& rm -rf /var/lib/apt/lists/* \
&& export XDG_CACHE_HOME=/camoufox-cache \
&& python -m camoufox sync \
&& CAMOUFOX_BUILD="$(python -c "import json; d=json.load(open('/camoufox-cache/camoufox/repo_cache.json')); print(next((x['version']+'-'+x['build'] for r in d['repos'] if r['name']=='Official' for x in r['versions'] if x['version']=='${CAMOUFOX_VERSION}' and x['build']=='${CAMOUFOX_BUILD_LABEL}'), ''))")" \
&& test -n "${CAMOUFOX_BUILD}" \
&& echo "Resolved Camoufox build for ${CAMOUFOX_VERSION}: ${CAMOUFOX_BUILD}" \
&& echo y | python -m camoufox fetch "official/${CAMOUFOX_BUILD}" \
&& python -m camoufox set "official/prerelease/${CAMOUFOX_BUILD}" \
&& mkdir -p /root/.cache/camoufox \
&& cp -a /camoufox-cache/camoufox/. /root/.cache/camoufox/ \
&& CAMOUFOX_DIR="$(find /root/.cache/camoufox/browsers/official -mindepth 1 -maxdepth 1 -type d -name "${CAMOUFOX_BUILD}*" 2>/dev/null | head -1)" \
&& test -n "${CAMOUFOX_DIR}" \
&& test -f "${CAMOUFOX_DIR}/version.json" \
&& echo "Installed Camoufox browser at: ${CAMOUFOX_DIR}"
# Copy the custom runner that allows specifying different options.
COPY ./dev/docker/camoufox_launcher.py /app/
ENTRYPOINT ["/usr/bin/dumb-init", "--"]
CMD ["python", "/app/camoufox_launcher.py"]