# whatsapp-bridge — headful Chromium under Xvfb, for read-only WhatsApp ingestion.
#
# Chromium comes from Debian's apt repo (PUPPETEER_SKIP_DOWNLOAD=true), not from
# Puppeteer's own bundled download, for two reasons:
#   1. The container host in this project is a Raspberry Pi 5 (arm64) — Puppeteer
#      publishes no arm64 Chromium build, so the bundled download simply fails
#      there. Debian's chromium package is built for both arm64 and amd64.
#   2. It picks up Chromium security updates through apt like everything else on
#      the host, instead of pinning whatever revision Puppeteer vendored.
FROM node:20-bookworm-slim

ENV PUPPETEER_SKIP_DOWNLOAD=true \
    CHROMIUM_PATH=/usr/bin/chromium \
    NODE_ENV=production

# fonts-liberation + fonts-noto-color-emoji: without them Chromium renders WhatsApp
# Web as tofu boxes, which also breaks the QR-code page on first login.
RUN apt-get update && apt-get install -y --no-install-recommends \
      chromium \
      xvfb \
      ca-certificates \
      fonts-liberation \
      fonts-noto-color-emoji \
    && rm -rf /var/lib/apt/lists/*

WORKDIR /app

COPY package.json ./
RUN npm install --omit=dev && npm cache clean --force

COPY index.js ./

VOLUME ["/data"]

# xvfb-run is the whole mechanism that lets Chromium run headful (see the
# headless: false comment in index.js) with no display attached to the host.
# -a picks a free display number so a restart never collides with a stale lock.
CMD ["xvfb-run", "-a", "--server-args=-screen 0 1280x1024x24", "node", "index.js"]
