AnyBot/box/Dockerfile

113 lines
8.3 KiB
Docker

# AnyBot's own computer ("Bot 的電腦"): a Linux desktop the bots share, like the original's box
# (an X11 desktop driven by xdotool, watched through noVNC on port 6080). One TigerVNC server is
# the screen and the VNC server; AT-SPI is on, so every app's controls (web pages included) can
# be read with their places and numbered on the bot's picture (box/a11y, after XBot's box).
# The desktop is LazyBoy2's box (was fluxbox, a bare menu on a right click): a minimal XFCE
# (xfwm4 + xfdesktop + a panel with 應用程式, 瀏覽器, 終端機, the open windows and a clock),
# Arc-Dark + Papirus + jf open 粉圓, Traditional Chinese menus, Taipei time. Not on LazyBoy2's:
# 檔案管理員 (Thunar, with thumbnails), 文字編輯器 (Mousepad) and 影像檢視器 (Ristretto), so a
# file a bot made or downloaded opens with a double click.
FROM debian:bookworm-slim
# No TZ here: a TZ variable overrides /etc/localtime for every program, so setting the timezone
# the normal way (/etc/localtime, /etc/timezone) seemed to do nothing. /etc/localtime is Taipei.
ENV DEBIAN_FRONTEND=noninteractive LANG=C.UTF-8
# dpkg never unpacks docs, man pages or other languages' messages (zh_TW is kept: the XFCE menus
# are in Traditional Chinese).
RUN printf '%s\n' \
'path-exclude=/usr/share/doc/*' \
'path-include=/usr/share/doc/*/copyright' \
'path-exclude=/usr/share/man/*' \
'path-exclude=/usr/share/info/*' \
'path-exclude=/usr/share/gtk-doc/*' \
'path-exclude=/usr/share/backgrounds/*' \
'path-exclude=/usr/share/locale/*' \
'path-include=/usr/share/locale/locale.alias' \
'path-include=/usr/share/locale/zh_TW/*' \
'path-include=/usr/share/locale/zh/*' \
> /etc/dpkg/dpkg.cfg.d/zz-anybot-slim \
&& apt-get update && apt-get install -y --no-install-recommends \
tigervnc-standalone-server tigervnc-tools xdotool x11-utils x11-xserver-utils imagemagick xterm \
dbus-x11 xfconf xfce4-panel xfwm4 xfdesktop4 xfce4-settings xfce4-terminal \
thunar tumbler mousepad ristretto xdg-utils \
arc-theme papirus-icon-theme adwaita-icon-theme gnome-themes-extra librsvg2-common \
at-spi2-core libatk-adaptor python3-gi gir1.2-atspi-2.0 libglib2.0-bin gsettings-desktop-schemas dconf-gsettings-backend \
novnc python3-websockify chromium chromium-l10n fonts-dejavu-core fonts-liberation fonts-noto-cjk fonts-noto-color-emoji \
locales tzdata \
ca-certificates curl wget git jq unzip zip less nano vim-tiny procps psmisc \
python3 python3-pip python3-venv nodejs npm sudo tini xclip poppler-utils \
&& echo "zh_TW.UTF-8 UTF-8" >> /etc/locale.gen && echo "en_US.UTF-8 UTF-8" >> /etc/locale.gen && locale-gen \
&& ln -sf /usr/share/zoneinfo/Asia/Taipei /etc/localtime && echo "Asia/Taipei" > /etc/timezone \
&& rm -rf /usr/share/icons/ePapirus /usr/share/icons/ePapirus-Dark /usr/share/icons/Papirus-Light \
&& test -e /usr/share/icons/Papirus-Dark/48x48/apps/web-browser.svg \
&& test -d /usr/share/themes/Arc-Dark/xfwm4 \
&& test -f /usr/share/locale/zh_TW/LC_MESSAGES/xfce4-panel.mo \
&& apt-get clean && rm -rf /var/lib/apt/lists/* \
&& useradd -m -s /bin/bash bot && echo 'bot ALL=(ALL) NOPASSWD:ALL' > /etc/sudoers.d/bot \
&& ln -sf /usr/share/novnc/vnc.html /usr/share/novnc/index.html
# jf open 粉圓 (OFL) as the desktop's font, pinned like LazyBoy2's.
RUN mkdir -p /usr/share/fonts/truetype/huninn \
&& curl -fsSL https://github.com/justfont/open-huninn-font/releases/download/v2.1/jf-openhuninn-2.1.ttf \
-o /usr/share/fonts/truetype/huninn/jf-openhuninn-2.1.ttf \
&& echo '9d5bf4932d31fe94c18cd8cfddc98bc1b14ce10f4e354c682179db290a99c825 /usr/share/fonts/truetype/huninn/jf-openhuninn-2.1.ttf' | sha256sum -c \
&& fc-cache -f
COPY start.sh /usr/local/bin/anybot-box-start
COPY a11y /usr/local/bin/anybot-a11y
COPY browser /usr/local/bin/anybot-browser
COPY screen /usr/local/bin/anybot-screen
COPY terminal /usr/local/bin/anybot-terminal
COPY Xresources /etc/anybot/Xresources
COPY welcome.html /usr/share/anybot/welcome.html
COPY xfce/wallpaper.svg /usr/share/anybot/wallpaper.svg
COPY xfce/xfce4-panel.xml /usr/share/anybot/xfce-skel/xfce4-panel.xml
COPY xfce/xfwm4.xml /usr/share/anybot/xfce-skel/xfwm4.xml
COPY xfce/xfce4-desktop.xml /usr/share/anybot/xfce-skel/xfce4-desktop.xml
COPY xfce/helpers.rc /etc/xdg/xfce4/helpers.rc
COPY xfce/mimeapps.list /etc/xdg/mimeapps.list
COPY xfce/menu.xml /etc/xdg/menus/xfce-applications.menu
COPY xfce/xfce4-panel-lock.xml /etc/xdg/xfce4/xfconf/xfce-perchannel-xml/xfce4-panel.xml
COPY xfce/helper-browser.desktop /usr/share/xfce4/helpers/anybot-browser.desktop
COPY xfce/helper-terminal.desktop /usr/share/xfce4/helpers/anybot-terminal.desktop
COPY xfce/browser.desktop /usr/share/applications/anybot-browser.desktop
COPY xfce/terminal.desktop /usr/share/applications/anybot-terminal.desktop
COPY fonts.conf /etc/fonts/conf.d/99-anybot-cjk.conf
COPY gtk3-settings.ini /etc/gtk-3.0/settings.ini
COPY licenses/huninn-OFL.txt /usr/share/licenses/huninn/OFL.txt
RUN chmod +x /usr/local/bin/anybot-box-start /usr/local/bin/anybot-a11y /usr/local/bin/anybot-browser /usr/local/bin/anybot-screen /usr/local/bin/anybot-terminal \
# The menu shows 瀏覽器 and 終端機 once each: anybot-browser is the one way to start Chromium
# (the same profile and DevTools port as the browser tools), anybot-terminal the terminal.
# (Into [Desktop Entry]: chromium.desktop ends with its actions, where an appended line went.)
&& for f in chromium xfce4-terminal debian-xterm debian-uxterm xterm uxterm; do \
if [ -f "/usr/share/applications/$f.desktop" ]; then sed -i '/^\[Desktop Entry\]/a NoDisplay=true' "/usr/share/applications/$f.desktop"; fi; \
done \
# The menu's names in plain words (檔案管理員, not 「Thunar 檔案管理員」); the build stops if a
# new Debian says them differently.
&& sed -i 's/^Name\[zh_TW\]=Thunar 檔案管理員$/Name[zh_TW]=檔案管理員/' /usr/share/applications/thunar.desktop \
&& sed -i 's/^Name\[zh_TW\]=Mousepad$/Name[zh_TW]=文字編輯器/' /usr/share/applications/org.xfce.mousepad.desktop \
&& sed -i 's/^Name\[zh_TW\]=Ristretto 影像檢視器$/Name[zh_TW]=影像檢視器/' /usr/share/applications/org.xfce.ristretto.desktop \
&& grep -qx 'Name\[zh_TW\]=檔案管理員' /usr/share/applications/thunar.desktop \
&& grep -qx 'Name\[zh_TW\]=文字編輯器' /usr/share/applications/org.xfce.mousepad.desktop \
&& grep -qx 'Name\[zh_TW\]=影像檢視器' /usr/share/applications/org.xfce.ristretto.desktop \
# (Which program opens what: /etc/xdg/mimeapps.list; the browser's file says it takes web pages and PDFs.)
&& { ! command -v update-desktop-database >/dev/null || update-desktop-database -q /usr/share/applications; } \
# Chromium has no sandbox inside a plain container (no user namespaces); the box itself is
# the sandbox. Under gVisor (容器隔離=runsc) the box has its own virtualized kernel and
# Chromium's sandbox works: AnyBot then starts the box with ANYBOT_BOX_SANDBOX=1 and the
# sandbox is switched back on (one more wall between a hostile web page and the machine).
# Debian's chromium wrapper reads these flags for every launch (menu, bots, xdg-open).
&& printf '%s\n' \
'if [ "${ANYBOT_BOX_SANDBOX:-0}" = 1 ]; then' \
' export CHROMIUM_FLAGS="$CHROMIUM_FLAGS --disable-dev-shm-usage --no-first-run --no-default-browser-check --disable-gpu --password-store=basic"' \
'else' \
' export CHROMIUM_FLAGS="$CHROMIUM_FLAGS --no-sandbox --test-type --disable-dev-shm-usage --no-first-run --no-default-browser-check --disable-gpu --password-store=basic"' \
'fi' > /etc/chromium.d/anybot
# Accessibility on for every app, including those started over `docker exec`.
# gail too: GTK 2 apps (lxappearance, PCManFM, many older tools) offer no controls to AT-SPI
# without it — no numbers at all, only a picture to guess at. GTK 3 apps ignore it.
# Traditional Chinese for every program (menus, Chromium, a terminal's messages); LC_ALL stays
# unset, so one command can still ask for LANG=C.
ENV LANG=zh_TW.UTF-8 LANGUAGE=zh_TW:zh:en DISPLAY=:1 SCREEN_SIZE=1280x800x24 XDG_CURRENT_DESKTOP=XFCE GTK_MODULES=gail:atk-bridge GTK_A11Y=atspi GNOME_ACCESSIBILITY=1 NO_AT_BRIDGE=0
EXPOSE 6080
LABEL anybot.box.version="12"
ENTRYPOINT ["/usr/bin/tini", "--"]
CMD ["/usr/local/bin/anybot-box-start"]