FROM python:3.11-alpine

ENV PYTHONUNBUFFERED=1 \
    SOCKS5_MONITOR_CONFIG=/app/config.json

WORKDIR /app
COPY app.py config.example.json README.md ./
COPY static ./static

RUN mkdir -p /app/data && \
    cp /app/config.example.json /app/config.json

EXPOSE 8787
VOLUME ["/app/data"]

HEALTHCHECK --interval=30s --timeout=5s --start-period=10s --retries=3 \
  CMD python3 -c "import urllib.request; urllib.request.urlopen('http://127.0.0.1:8787/api/status', timeout=3).read()" || exit 1

CMD ["python3", "/app/app.py", "--host", "0.0.0.0", "--port", "8787", "--config", "/app/config.json"]
