1- FROM python:3.12
1+ FROM python:3.12-slim-bookworm AS app-base
22
33LABEL org.opencontainers.image.url=https://github.com/Teahouse-Studios/akari-bot-webrender
44LABEL org.opencontainers.image.documentation=https://bot.teahouse.team/
@@ -8,38 +8,139 @@ LABEL org.opencontainers.image.licenses=MIT
88LABEL org.opencontainers.image.title="AkariBot WebRender"
99LABEL maintainer="Teahouse Studios <admin@teahou.se>"
1010
11- RUN pip install uv
11+ ARG WEBRENDER_UID=10001
12+ ARG WEBRENDER_GID=10001
13+ ARG UV_VERSION=0.10.3
14+
15+ ENV DEBIAN_FRONTEND=noninteractive \
16+ HOME=/home/webrender \
17+ PATH=/akari-bot-webrender/.venv/bin:${PATH} \
18+ PLAYWRIGHT_BROWSERS_PATH=/ms-playwright \
19+ PYTHONDONTWRITEBYTECODE=1 \
20+ PYTHONUNBUFFERED=1 \
21+ UV_COMPILE_BYTECODE=1 \
22+ UV_LINK_MODE=copy \
23+ UV_NO_CACHE=1 \
24+ WEBRENDER_HOST=0.0.0.0
25+
26+ RUN apt-get update \
27+ && apt-get install -y --no-install-recommends \
28+ ca-certificates \
29+ fonts-dejavu \
30+ fonts-noto-cjk \
31+ fonts-noto-color-emoji \
32+ tini \
33+ && rm -rf /var/lib/apt/lists/* \
34+ && groupadd --gid "${WEBRENDER_GID}" webrender \
35+ && useradd --uid "${WEBRENDER_UID}" --gid "${WEBRENDER_GID}" --create-home --shell /bin/sh webrender \
36+ && install -d -o webrender -g webrender /akari-bot-webrender \
37+ && install -d -o root -g root -m 0755 /ms-playwright
38+
39+ RUN pip install --no-cache-dir "uv==${UV_VERSION}"
1240
1341WORKDIR /akari-bot-webrender
1442
15- ENV PYTHONDONTWRITEBYTECODE=1
16- ENV PYTHONUNBUFFERED=1
17-
18- RUN apt-get update && apt-get install -y \
19- fonts-noto-cjk \
20- fonts-noto-color-emoji \
21- fonts-dejavu \
22- curl \
23- wget \
24- gnupg \
25- ca-certificates \
26- libnss3 \
27- libatk1.0-0 \
28- libatk-bridge2.0-0 \
29- libcups2 \
30- libxkbcommon0 \
31- libxcomposite1 \
32- libxdamage1 \
33- libxrandr2 \
34- libgbm1 \
35- libpango-1.0-0 \
36- libpangocairo-1.0-0 \
37- libasound2 \
43+ COPY --chown=webrender:webrender pyproject.toml uv.lock README.md ./
44+ RUN uv sync --frozen --no-dev --no-install-project \
45+ && playwright install-deps chromium \
3846 && rm -rf /var/lib/apt/lists/*
3947
40- COPY pyproject.toml uv.lock README.md ./
41- RUN uv sync --frozen
42- RUN uv run playwright install --with-deps chromium
48+ EXPOSE 15551
49+
50+ HEALTHCHECK --interval=30s --timeout=5s --start-period=20s --retries=3 \
51+ CMD ["python" , "-c" , "import json, os, urllib.request; response = urllib.request.urlopen('http://127.0.0.1:' + os.getenv('WEBRENDER_PORT', '15551') + '/status/', timeout=3); assert json.load(response).get('browser_initialized') is True" ]
52+
53+ # The normal image remains headless. Build it explicitly with --target headless,
54+ # or omit --target (the final default stage below is an alias of this stage).
55+ FROM app-base AS headless
56+
57+ RUN playwright install --only-shell chromium \
58+ && chmod -R a+rX /ms-playwright \
59+ && rm -rf /home/webrender/.cache/ms-playwright
60+
61+ COPY --chown=webrender:webrender . .
62+ RUN uv sync --frozen --no-dev \
63+ && chmod 0755 docker/entrypoint-headless.sh docker/entrypoint-gui.sh \
64+ && chown -R webrender:webrender /home/webrender
65+
66+ USER webrender
67+ ENTRYPOINT ["/usr/bin/tini" , "--" , "./docker/entrypoint-headless.sh" ]
68+ CMD ["python" , "./run_server.py" ]
69+
70+
71+ # Shared headed Chromium and virtual-X layer. Desktop targets add their own
72+ # session implementation so the XFCE image does not also carry the lightweight WM.
73+ FROM app-base AS headed-base
74+
75+ USER root
76+ RUN playwright install --no-shell chromium \
77+ && chmod -R a+rX /ms-playwright \
78+ && rm -rf /home/webrender/.cache/ms-playwright \
79+ && apt-get update \
80+ && apt-get install -y --no-install-recommends \
81+ dbus-x11 \
82+ x11-utils \
83+ x11-xserver-utils \
84+ xvfb \
85+ && rm -rf /var/lib/apt/lists/* \
86+ && install -d -m 1777 /tmp/.ICE-unix /tmp/.X11-unix
87+
88+ COPY --chown=webrender:webrender . .
89+ RUN uv sync --frozen --no-dev \
90+ && chmod 0755 docker/entrypoint-headless.sh docker/entrypoint-gui.sh \
91+ && chown -R webrender:webrender /home/webrender
92+
93+ ENV DISPLAY=:99 \
94+ WEBRENDER_DEBUG=0 \
95+ WEBRENDER_HEADLESS=0 \
96+ XVFB_SCREEN=2560x1600x24
4397
44- ADD . .
98+ USER webrender
99+ ENTRYPOINT ["/usr/bin/tini" , "--" , "./docker/entrypoint-gui.sh" ]
45100CMD ["python" , "./run_server.py" ]
101+
102+
103+ # Headed Chromium with a lightweight window manager.
104+ FROM headed-base AS headed
105+
106+ USER root
107+ RUN apt-get update \
108+ && apt-get install -y --no-install-recommends \
109+ twm \
110+ xfonts-base \
111+ && rm -rf /var/lib/apt/lists/*
112+
113+ ENV WEBRENDER_DESKTOP=twm
114+
115+ USER webrender
116+
117+
118+ # Complete XFCE desktop with optional, password-protected noVNC access.
119+ # noVNC is disabled unless ENABLE_NOVNC=1 is supplied at runtime.
120+ FROM headed-base AS desktop
121+
122+ USER root
123+ ARG NOVNC_VERSION=1.7.0
124+ ARG NOVNC_SHA256=b1003a11b6e6e8d8f7f5e5586daae7f8ca651d8aee0aa155ff9ac841c48f52c6
125+ RUN apt-get update \
126+ && apt-get install -y --no-install-recommends \
127+ xfce4 \
128+ x11vnc \
129+ && rm -rf /var/lib/apt/lists/* \
130+ && uv sync --frozen --no-dev --extra desktop \
131+ && python docker/install-novnc.py "${NOVNC_VERSION}" "${NOVNC_SHA256}" /usr/share/novnc
132+
133+ ENV ENABLE_NOVNC=0 \
134+ NO_AT_BRIDGE=1 \
135+ NOVNC_LISTEN=127.0.0.1 \
136+ NOVNC_PORT=6080 \
137+ VNC_PORT=5900 \
138+ WEBRENDER_DESKTOP=xfce
139+
140+ EXPOSE 6080
141+
142+ USER webrender
143+
144+
145+ # Keep `docker build .` backward-compatible: the default artifact is headless.
146+ FROM headless AS default
0 commit comments