FROM python:3.12-slim

LABEL org.opencontainers.image.title="rss-bridge-ntfy-web"
LABEL org.opencontainers.image.description="RSS/Atom -> ntfy bridge with a web UI"

ENV PYTHONDONTWRITEBYTECODE=1 \
    PYTHONUNBUFFERED=1 \
    DATA_DIR=/data \
    PORT=8080 \
    TZ=UTC

WORKDIR /app

# Install dependencies first to leverage layer caching.
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt

# Application code.
COPY main.py engine.py store.py webapp.py opml.py ./
COPY templates ./templates
COPY static ./static

# Persistent data (settings, feeds, history db, logs) lives here.
RUN mkdir -p /data
VOLUME ["/data"]

EXPOSE 8080

HEALTHCHECK --interval=30s --timeout=5s --start-period=10s --retries=3 \
    CMD python -c "import urllib.request,os; urllib.request.urlopen('http://127.0.0.1:'+os.environ.get('PORT','8080')+'/api/health')" || exit 1

CMD ["python", "main.py"]
