FROM docker.iranserver.com/python:3.10

ENV PYTHONDONTWRITEBYTECODE=1
ENV PYTHONUNBUFFERED=1

WORKDIR /app

# ------------------------
# APT MIRRORS (runflare)
# ------------------------
RUN rm -f /etc/apt/sources.list /etc/apt/sources.list.d/* && \
printf '%s\n' \
'deb https://mirror-linux.runflare.com/debian/ bookworm main contrib non-free non-free-firmware' \
'deb https://mirror-linux.runflare.com/debian/ bookworm-updates main contrib non-free non-free-firmware' \
'deb https://mirror-linux.runflare.com/debian-security/ bookworm-security main contrib non-free non-free-firmware' \
'' \
> /etc/apt/sources.list

RUN apt-get update && apt-get install -y --no-install-recommends \
    build-essential \
    curl \
    jq \
    && rm -rf /var/lib/apt/lists/*

# ------------------------
# Copy requirements
# ------------------------
COPY requirements.txt .

# ------------------------
# PIP MIRROR
# ------------------------
ENV PIP_INDEX_URL=https://mirror-pypi.runflare.com/simple
ENV PIP_TRUSTED_HOST=mirror-pypi.runflare.com

RUN pip install --upgrade pip && \
    pip install --prefer-binary -r requirements.txt

# ------------------------
# Copy test code
# ------------------------
COPY . .

# Expose is optional for test container
# EXPOSE 8000

CMD bash -c "pytest tests -v --maxfail=1 | tee /logs/test.log"
