# ── Market Data Service ─────────────────────────────────────────────────
# Multi-stage build: slim Python 3.11+ image
FROM python:3.11-slim AS base

# Prevent Python from writing bytecode and enable unbuffered output
ENV PYTHONDONTWRITEBYTECODE=1 \
    PYTHONUNBUFFERED=1

WORKDIR /app

# System dependencies (none needed for this service)
RUN apt-get update && apt-get install -y --no-install-recommends \
    && rm -rf /var/lib/apt/lists/*

# ── Dependencies ───────────────────────────────────────────────────────
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt

# ── Application code ──────────────────────────────────────────────────
COPY app/ ./app/
COPY pyproject.toml .

# ── Health check ──────────────────────────────────────────────────────
HEALTHCHECK --interval=15s --timeout=5s --start-period=10s --retries=3 \
    CMD python -c "import urllib.request; urllib.request.urlopen('http://localhost:8891/health')" || exit 1

# ── Default command ───────────────────────────────────────────────────
# Override with docker-compose command or CLI args
EXPOSE 8891

ENTRYPOINT ["python", "-m", "app"]
CMD ["run", "--provider", "binance", "--symbols", "BTCUSDT,ETHUSDT"]
