# 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).
FROM debian:bookworm-slim
ENV DEBIAN_FRONTEND=noninteractive LANG=C.UTF-8 TZ=UTC
RUN apt-get update && apt-get install -y --no-install-recommends \
      tigervnc-standalone-server tigervnc-tools xdotool x11-utils x11-xserver-utils imagemagick fluxbox xterm \
      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 fonts-noto-cjk fonts-noto-color-emoji \
      ca-certificates curl wget git jq unzip zip less nano vim-tiny procps psmisc \
      python3 python3-pip python3-venv nodejs npm sudo tini dbus-x11 xclip poppler-utils \
    && 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
COPY start.sh /usr/local/bin/anybot-box-start
COPY a11y /usr/local/bin/anybot-a11y
COPY browser /usr/local/bin/anybot-browser
COPY fluxbox-init /etc/anybot/fluxbox-init
COPY overlay /etc/anybot/overlay
COPY Xresources /etc/anybot/Xresources
COPY menu /etc/anybot/menu
RUN chmod +x /usr/local/bin/anybot-box-start /usr/local/bin/anybot-a11y /usr/local/bin/anybot-browser \
    # Chromium has no sandbox inside a container (no user namespaces); the box itself is the
    # sandbox. Debian's chromium wrapper reads these flags for every launch (menu, bots, xdg-open).
    && printf '%s\n' 'export CHROMIUM_FLAGS="$CHROMIUM_FLAGS --no-sandbox --disable-dev-shm-usage --no-first-run --no-default-browser-check --disable-gpu --password-store=basic --test-type"' > /etc/chromium.d/anybot
# Accessibility on for every app, including those started over `docker exec`.
ENV DISPLAY=:1 SCREEN_SIZE=1280x800x24 GTK_MODULES=atk-bridge GTK_A11Y=atspi GNOME_ACCESSIBILITY=1 NO_AT_BRIDGE=0
EXPOSE 6080
LABEL anybot.box.version="6"
ENTRYPOINT ["/usr/bin/tini", "--"]
CMD ["/usr/local/bin/anybot-box-start"]
