FROM python:3.12-slim

ENV PYTHONUNBUFFERED=1 \
    PYTHONDONTWRITEBYTECODE=1 \
    DATA_DIR=/data

WORKDIR /app

# application code (no credentials, no config files)
COPY app/graylog_ops /app/graylog_ops
COPY app/bin /app/bin
COPY app/profiles /app/profiles
COPY app/allowlist.example.txt /app/allowlist.example.txt
COPY app/asn_brand_map.json /app/asn_brand_map.json

# seed data: current production snapshot (sqlite + geo + asn + blocklist)
COPY seed /app/seed

COPY entrypoint.sh /app/entrypoint.sh
RUN chmod +x /app/entrypoint.sh

VOLUME ["/data"]
EXPOSE 8088

HEALTHCHECK --interval=60s --timeout=5s --start-period=30s \
  CMD python3 -c "import os,urllib.request,sys; \
url='http://127.0.0.1:%s/healthz' % os.environ.get('APP_PORT','8088'); \
sys.exit(0 if urllib.request.urlopen(url, timeout=4).status == 200 else 1)"

ENTRYPOINT ["/app/entrypoint.sh"]
