Repository navigation
Expand file tree
/
Copy pathDockerfile
More file actions
256 lines (248 loc) · 10.9 KB
/
Copy pathDockerfile
File metadata and controls
256 lines (248 loc) · 10.9 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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
ARG BASE_IMAGE=debian:bookworm-slim
FROM ${BASE_IMAGE} AS system-browser
ARG TARGETARCH
ARG APT_MIRROR=
ARG CHROME_DEB_URL=
ARG CHROME_DEB_URL_AMD64=https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
ARG CHROME_DEB_URL_ARM64=https://dl.google.com/linux/direct/google-chrome-stable_current_arm64.deb
ARG CHROME_FOR_TESTING_URL=
ARG CHROME_FOR_TESTING_URL_AMD64=
ARG CHROME_FOR_TESTING_URL_ARM64=
ARG ARM64_CHROME_FALLBACK=chromium
ARG CHROMIUM_PACKAGE=chromium
ARG APP_UID=1000
ARG APP_GID=1000
ENV DEBIAN_FRONTEND=noninteractive \
TZ=Asia/Shanghai
# 主要非洲市场语言覆盖:
# - 埃塞俄比亚/厄立特里亚及 Ethiopic 字母:阿姆哈拉语 am_ET、提格里尼亚语 ti_ET/ti_ER、奥罗莫语 om_ET、锡达马语 sid_ET、沃莱塔语 wal_ET。
# - 东非和大湖区:斯瓦希里语 sw_KE/sw_TZ、索马里语 so_ET/so_SO/so_KE/so_DJ、卢旺达语 rw_RW、肯尼亚奥罗莫语 om_KE。
# - 西非:豪萨语 ha_NG、约鲁巴语 yo_NG、伊博语 ig_NG、尼日利亚英语 en_NG。
# - 南部非洲:南非/赞比亚/津巴布韦/博茨瓦纳英语,以及南非荷兰语、祖鲁语、科萨语。
# - 北非和通用市场语言:北非阿拉伯语区域、法语 fr_FR、葡语 pt_PT、马达加斯加语 mg_MG。
# 默认使用 Debian 是为了同一个 Dockerfile 同时覆盖 amd64 和 arm64:
# amd64 仍优先安装官方 Google Chrome,arm64 在官方 deb 不可用时用原生 Chromium 兜底。
RUN set -eux; \
if [ -n "${APT_MIRROR}" ]; then \
os_id=""; \
if [ -f /etc/os-release ]; then . /etc/os-release; os_id="${ID:-}"; fi; \
if [ "${os_id}" = "debian" ] && printf '%s' "${APT_MIRROR}" | grep -qi ubuntu; then \
echo "Ignoring Ubuntu APT_MIRROR=${APT_MIRROR} for Debian base image; set a Debian mirror or leave APT_MIRROR empty."; \
elif [ "${os_id}" = "ubuntu" ] && printf '%s' "${APT_MIRROR}" | grep -qi debian; then \
echo "Ignoring Debian APT_MIRROR=${APT_MIRROR} for Ubuntu base image; set an Ubuntu mirror or leave APT_MIRROR empty."; \
else \
if [ -f /etc/apt/sources.list ]; then \
sed -i "s|http://archive.ubuntu.com/ubuntu|${APT_MIRROR}|g; s|http://security.ubuntu.com/ubuntu|${APT_MIRROR}|g; s|http://deb.debian.org/debian|${APT_MIRROR}|g; s|http://security.debian.org/debian-security|${APT_MIRROR}-security|g" /etc/apt/sources.list; \
fi; \
if [ -f /etc/apt/sources.list.d/debian.sources ]; then \
sed -i "s|http://deb.debian.org/debian|${APT_MIRROR}|g; s|http://security.debian.org/debian-security|${APT_MIRROR}-security|g" /etc/apt/sources.list.d/debian.sources; \
fi; \
fi; \
fi; \
apt-get update; \
apt-get install -y --no-install-recommends \
ca-certificates \
curl \
dbus-x11 \
fontconfig \
fonts-dejavu-core \
fonts-dejavu-extra \
fonts-liberation \
fonts-noto-cjk \
fonts-noto-color-emoji \
fonts-noto-core \
fonts-noto-extra \
fonts-noto-ui-core \
fonts-noto-ui-extra \
fonts-sil-abyssinica \
ffmpeg \
gosu \
lame \
locales \
novnc \
procps \
psmisc \
python3 \
python3-pip \
python3-setuptools \
python3-venv \
python3-wheel \
tzdata \
x11-xserver-utils \
xclip \
xdotool \
xdg-utils \
x11vnc \
xvfb; \
printf '%s\n' \
'en_US.UTF-8 UTF-8' \
'zh_CN.UTF-8 UTF-8' \
'bn_BD.UTF-8 UTF-8' \
'am_ET UTF-8' \
'om_ET UTF-8' \
'om_KE.UTF-8 UTF-8' \
'sid_ET UTF-8' \
'so_DJ.UTF-8 UTF-8' \
'so_ET UTF-8' \
'so_KE.UTF-8 UTF-8' \
'so_SO.UTF-8 UTF-8' \
'sw_KE UTF-8' \
'sw_TZ UTF-8' \
'ti_ER UTF-8' \
'ti_ET UTF-8' \
'wal_ET UTF-8' \
'rw_RW UTF-8' \
'ha_NG UTF-8' \
'yo_NG UTF-8' \
'ig_NG UTF-8' \
'en_NG UTF-8' \
'en_ZA.UTF-8 UTF-8' \
'en_ZM UTF-8' \
'en_ZW.UTF-8 UTF-8' \
'en_BW.UTF-8 UTF-8' \
'af_ZA.UTF-8 UTF-8' \
'zu_ZA.UTF-8 UTF-8' \
'xh_ZA.UTF-8 UTF-8' \
'ar_DZ.UTF-8 UTF-8' \
'ar_EG.UTF-8 UTF-8' \
'ar_LY.UTF-8 UTF-8' \
'ar_MA.UTF-8 UTF-8' \
'ar_SD.UTF-8 UTF-8' \
'ar_SS UTF-8' \
'ar_TN.UTF-8 UTF-8' \
'fr_FR.UTF-8 UTF-8' \
'pt_PT.UTF-8 UTF-8' \
'mg_MG.UTF-8 UTF-8' \
>> /etc/locale.gen; \
sort -u -o /etc/locale.gen /etc/locale.gen; \
locale-gen; \
update-locale LANG=zh_CN.UTF-8; \
fc-cache -f; \
target_arch="${TARGETARCH:-$(dpkg --print-architecture)}"; \
chrome_deb_url="${CHROME_DEB_URL:-}"; \
if [ "${target_arch}" != "amd64" ] && printf '%s' "${chrome_deb_url}" | grep -Eq 'amd64[./_-]'; then \
echo "Ignoring amd64 CHROME_DEB_URL while building for ${target_arch}; use CHROME_DEB_URL_ARM64 instead."; \
chrome_deb_url=""; \
fi; \
case "${target_arch}" in \
amd64) \
chrome_deb_url="${chrome_deb_url:-${CHROME_DEB_URL_AMD64}}"; \
chrome_for_testing_url="${CHROME_FOR_TESTING_URL:-${CHROME_FOR_TESTING_URL_AMD64}}"; \
chrome_for_testing_platform="linux64"; \
chrome_for_testing_dir="chrome-linux64"; \
;; \
arm64) \
chrome_deb_url="${chrome_deb_url:-${CHROME_DEB_URL_ARM64}}"; \
chrome_for_testing_url="${CHROME_FOR_TESTING_URL:-${CHROME_FOR_TESTING_URL_ARM64}}"; \
chrome_for_testing_platform="linux-arm64"; \
chrome_for_testing_dir="chrome-linux-arm64"; \
;; \
*) \
echo "Unsupported Docker TARGETARCH=${target_arch}; expected amd64 or arm64." >&2; \
exit 1; \
;; \
esac; \
browser_flavor="google-chrome"; \
curl_flags="-fSL --retry 5 --retry-delay 2 --retry-all-errors --connect-timeout 30"; \
if ! curl ${curl_flags} "${chrome_deb_url}" -o /tmp/google-chrome-stable.deb; then \
rm -f /tmp/google-chrome-stable.deb; \
if [ "${target_arch}" = "arm64" ] && [ "${ARM64_CHROME_FALLBACK}" = "chromium" ]; then \
echo "Google Chrome ARM64 deb is unavailable; installing ${CHROMIUM_PACKAGE} because ARM64_CHROME_FALLBACK=chromium."; \
apt-get install -y --no-install-recommends "${CHROMIUM_PACKAGE}"; \
chromium_bin="$(command -v chromium || command -v chromium-browser || true)"; \
if [ -z "${chromium_bin}" ]; then \
echo "Chromium executable was not found after installing ${CHROMIUM_PACKAGE}." >&2; \
exit 1; \
fi; \
ln -sf "${chromium_bin}" /usr/bin/google-chrome; \
ln -sf "${chromium_bin}" /usr/bin/google-chrome-for-testing; \
browser_flavor="chromium"; \
else \
echo "Google Chrome deb is unavailable for TARGETARCH=${target_arch}: ${chrome_deb_url}" >&2; \
if [ "${target_arch}" = "amd64" ]; then \
echo "For amd64, check build network access to dl.google.com or set CHROME_DEB_URL_AMD64 to an internal cache." >&2; \
else \
echo "For arm64, pass CHROME_DEB_URL_ARM64 after Google publishes the official Linux ARM64 deb, or keep ARM64_CHROME_FALLBACK=chromium with a base image that provides a native Chromium deb package." >&2; \
fi; \
exit 1; \
fi; \
else \
apt-get install -y --no-install-recommends /tmp/google-chrome-stable.deb; \
rm -f /tmp/google-chrome-stable.deb; \
if ! command -v google-chrome >/dev/null 2>&1 && command -v google-chrome-stable >/dev/null 2>&1; then \
ln -s "$(command -v google-chrome-stable)" /usr/bin/google-chrome; \
fi; \
fi; \
google-chrome --version; \
if [ "${browser_flavor}" = "google-chrome" ]; then \
chrome_version="$(google-chrome --version | awk '{print $3}')"; \
if [ -n "${chrome_for_testing_url}" ]; then \
curl ${curl_flags} "${chrome_for_testing_url}" -o /tmp/chrome-for-testing.zip; \
mkdir -p /opt/chrome-for-testing; \
python3 -m zipfile -e /tmp/chrome-for-testing.zip /opt/chrome-for-testing; \
rm -f /tmp/chrome-for-testing.zip; \
find /opt/chrome-for-testing -type d -exec chmod 755 {} +; \
find /opt/chrome-for-testing -type f -exec chmod 644 {} +; \
chrome_for_testing_root="/opt/chrome-for-testing/${chrome_for_testing_dir}"; \
if [ ! -d "${chrome_for_testing_root}" ]; then \
chrome_for_testing_root="$(find /opt/chrome-for-testing -mindepth 1 -maxdepth 1 -type d -name 'chrome-*' | head -n 1)"; \
fi; \
if [ ! -f "${chrome_for_testing_root}/chrome" ]; then \
echo "Chrome for Testing executable not found under /opt/chrome-for-testing." >&2; \
exit 1; \
fi; \
find "${chrome_for_testing_root}" -maxdepth 1 -type f -name 'chrome*' -exec chmod 755 {} +; \
if [ -f "${chrome_for_testing_root}/chrome_sandbox" ]; then \
chown root:root "${chrome_for_testing_root}/chrome_sandbox"; \
chmod 4755 "${chrome_for_testing_root}/chrome_sandbox"; \
fi; \
ln -sf "${chrome_for_testing_root}/chrome" /usr/bin/google-chrome-for-testing; \
else \
echo "Chrome for Testing is not installed by default; linking testing path to the installed official stable browser ${chrome_version}."; \
ln -sf "$(command -v google-chrome)" /usr/bin/google-chrome-for-testing; \
fi; \
fi; \
google-chrome-for-testing --version; \
groupadd --gid "${APP_GID}" mukai; \
useradd --uid "${APP_UID}" --gid "${APP_GID}" --create-home --shell /bin/bash mukai; \
mkdir -p /tmp/.X11-unix; \
chmod 1777 /tmp/.X11-unix; \
apt-get clean; \
rm -rf /var/lib/apt/lists/*
# system-browser 阶段只沉淀浏览器、DISPLAY、字体和系统工具,便于长期缓存并单独推送到镜像仓库。
FROM system-browser
ARG PIP_INDEX_URL=https://mirrors.aliyun.com/pypi/simple
ARG PIP_TRUSTED_HOST=mirrors.aliyun.com
ENV LANG=zh_CN.UTF-8 \
LANGUAGE=zh_CN:zh \
LC_ALL=zh_CN.UTF-8 \
PYTHONDONTWRITEBYTECODE=1 \
PYTHONUNBUFFERED=1 \
PIP_DISABLE_PIP_VERSION_CHECK=1 \
PIP_INDEX_URL=${PIP_INDEX_URL} \
PIP_TRUSTED_HOST=${PIP_TRUSTED_HOST} \
ENV=docker \
LOG_TO_FILE=false \
GATEWAY_BIND_HOST=0.0.0.0 \
GATEWAY_PUBLIC_HOST=127.0.0.1 \
GATEWAY_CONTROL_PORT=12000 \
GATEWAY_HTTP_PORT=12100 \
GATEWAY_STREAM_PORT=13000 \
GATEWAY_CAPTURE_WS_PORT=14000 \
CHROME_CHANNEL=stable \
CHROME_PATH= \
CHROME_STABLE_PATH=/usr/bin/google-chrome \
CHROME_TESTING_PATH=/usr/bin/google-chrome-for-testing \
CHROME_EXTENSION_PATH=/opt/cloud-browser/extensions/tab-capture \
CHROME_PROFILE_BASE_DIR=/data/browser/profiles \
CHROME_EXTENSION_LOAD_STRATEGY=profile \
CHROME_WINDOW_MODE=app \
CHROME_PROFILE_TEMPLATE_DIR=/data/browser/profile-templates/current \
CHROME_PROFILE_TEMPLATE_CLEANUP=true \
CHROME_RESOLUTION_MODE=fixed \
CHROME_WIDTH=320 \
CHROME_HEIGHT=480
WORKDIR /app
COPY requirements-server.txt ./
RUN pip3 install --no-cache-dir -r requirements-server.txt \
|| pip3 install --break-system-packages --no-cache-dir -r requirements-server.txt