# Harmonious crypto billing service — self-hosted image.
FROM python:3.12-slim-bookworm

WORKDIR /app

COPY billing/requirements.txt ./
RUN pip install --no-cache-dir -r requirements.txt

# The billing package (app, store, license_keys) is importable as `billing`.
COPY billing ./billing

RUN groupadd --gid 10001 billing \
    && useradd --uid 10001 --gid 10001 --no-create-home --home-dir /app billing \
    && mkdir -p /data \
    && chown 10001:10001 /data

# HOME=/data keeps any stdlib/cache writes on the writable volume.
ENV BILLING_DB_PATH=/data/billing.sqlite3 \
    PYTHONUNBUFFERED=1 \
    HOME=/data

USER 10001

EXPOSE 8090

HEALTHCHECK --interval=30s --timeout=10s --start-period=15s --retries=3 \
    CMD python -c "import urllib.request; urllib.request.urlopen('http://127.0.0.1:8090/health', timeout=5)"

CMD ["uvicorn", "billing.app:app", "--host", "0.0.0.0", "--port", "8090", "--proxy-headers", "--forwarded-allow-ips", "*"]
