# Dutywall standalone appliance — the self-host / air-gap deliverable.
# Multi-arch (amd64 + arm64 for a Pi/box). Runs dm_core + dm_agent + the Flask
# shell (app.py) under gunicorn with a single worker (the in-process scheduler
# must not be duplicated).
FROM python:3.12-slim

# Fonts for weather/safety/radar cards; ffmpeg for video posters; Chromium so
# the box can screenshot a web page for Roku (no WebView on those TVs).
RUN apt-get update \
 && apt-get install -y --no-install-recommends \
      fonts-dejavu-core fonts-liberation curl ffmpeg chromium \
 && rm -rf /var/lib/apt/lists/*

# LibreOffice (nogui) rasterizes Word/Excel/PowerPoint into the slideshow.
RUN apt-get update \
 && apt-get install -y --no-install-recommends \
      libreoffice-writer-nogui libreoffice-calc-nogui libreoffice-impress-nogui \
 && rm -rf /var/lib/apt/lists/*

RUN useradd -m -u 10001 app
WORKDIR /app

COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt

# Application code
COPY dm_core/ dm_core/
COPY dm_agent/ dm_agent/
COPY app.py player.html REVISION ./
# Sideload package + alarm seed (copied into the data volume on first boot)
COPY looping-video.zip /opt/roku-admin/looping-video.zip
COPY alarm.wav /app/seed/alarm.wav
COPY docker/entrypoint.sh /entrypoint.sh
RUN chmod 755 /entrypoint.sh \
 && mkdir -p /var/www/roku/media/dyn \
 && chown -R app:app /app /var/www/roku /opt/roku-admin \
 && find /app /opt/roku-admin -type d -exec chmod 755 {} + \
 && find /app /opt/roku-admin -type f -exec chmod 644 {} + \
 && chmod 755 /entrypoint.sh

USER app
EXPOSE 8090
HEALTHCHECK --interval=30s --timeout=5s --start-period=10s \
  CMD curl -fsS http://127.0.0.1:8090/healthz >/dev/null || exit 1
ENTRYPOINT ["/entrypoint.sh"]
