FROM python:3.12-alpine

RUN adduser -D -u 10001 app

WORKDIR /app

COPY checks.py notify.py monitor.py config.json ./

RUN mkdir -p /data && chown -R app:app /data /app

USER app

ENV PYTHONUNBUFFERED=1

HEALTHCHECK --interval=60s --timeout=10s --retries=3 --start-period=30s \
    CMD python -c "import os,time; p='/data/state.json'; raise SystemExit(0 if os.path.exists(p) and time.time()-os.path.getmtime(p)<300 else 1)"

CMD ["python", "-u", "/app/monitor.py"]
