FROM python:3.12-slim

ENV PYTHONDONTWRITEBYTECODE=1 \
    PYTHONUNBUFFERED=1 \
    PIP_NO_CACHE_DIR=1

WORKDIR /app

ARG BROWSER_DEBUG_TOOLS=false

RUN apt-get update \
    && apt-get install -y --no-install-recommends ca-certificates curl \
    && rm -rf /var/lib/apt/lists/*

RUN if [ "$BROWSER_DEBUG_TOOLS" = "true" ]; then \
      apt-get update \
      && apt-get install -y --no-install-recommends \
        fluxbox \
        novnc \
        websockify \
        x11vnc \
        xvfb \
      && rm -rf /var/lib/apt/lists/*; \
    fi

COPY requirements.txt requirements-dev.txt pyproject.toml ./
COPY src ./src
COPY tests ./tests
COPY scripts ./scripts

RUN pip install --upgrade pip \
    && pip install -r requirements.txt \
    && pip install . \
    && chmod +x /app/scripts/browser-debug.sh \
    && python -m playwright install --with-deps chromium

COPY README.md ./

VOLUME ["/data"]
ENTRYPOINT ["python", "-m", "mywhoosh_garmin_sync"]
CMD ["serve"]
