# RepoRadar — Discord bot Docker image
FROM python:3.12-slim

# Avoid interactive prompts + keep Python output unbuffered for clean logs.
ENV PYTHONUNBUFFERED=1 \
    PYTHONDONTWRITEBYTECODE=1 \
    PIP_NO_CACHE_DIR=1

WORKDIR /app

# Install dependencies first for better layer caching.
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt

# Copy the application source.
COPY . .

# Run as a non-root user; own the data directory it writes the SQLite DB to.
RUN useradd --create-home --uid 10001 reporadar \
    && mkdir -p /app/data \
    && chown -R reporadar:reporadar /app
USER reporadar

# Persist the SQLite database across container recreations.
VOLUME ["/app/data"]

# Lightweight import check so orchestrators can detect a broken image.
HEALTHCHECK --interval=60s --timeout=10s --retries=3 \
    CMD python -c "import nextcord, aiohttp, aiosqlite" || exit 1

CMD ["python", "main.py"]
