# pagerplug — containerized browser UI (and CLI).
#
# Build:  docker build -t pagerplug .
# Run:    docker run --rm -p 8765:8765 -v "$PWD/data:/data" pagerplug
#         then open http://localhost:8765 and load /data/<your>.unipps
FROM python:3.12-slim

# Run as a non-root user.
RUN useradd --create-home --uid 1000 app

WORKDIR /app

# Install the package with the web extras. Copy only what the build needs first
# so this layer caches across source-only changes.
COPY pyproject.toml README.md LICENSE ./
COPY pagerplug ./pagerplug
RUN pip install --no-cache-dir ".[web]"

# /data is where you mount your .unipps files; open and save them there so edits
# persist to the host.
RUN mkdir -p /data && chown -R app:app /app /data
USER app
VOLUME ["/data"]
EXPOSE 8765

HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
  CMD python3 -c "import urllib.request,sys; sys.exit(0 if urllib.request.urlopen('http://127.0.0.1:8765/').status==200 else 1)"

# Bind to all interfaces so the UI is reachable from the host.
CMD ["pagerplug", "web", "--host", "0.0.0.0", "--port", "8765"]
