FROM registry.bstein.dev/bstein/python:3.12-slim AS base

ENV PYTHONDONTWRITEBYTECODE=1 \
    PYTHONUNBUFFERED=1 \
    PIP_DISABLE_PIP_VERSION_CHECK=1 \
    PIP_DEFAULT_TIMEOUT=60

WORKDIR /app
COPY requirements.txt /app/requirements.txt
COPY pyproject.toml /app/pyproject.toml
RUN pip install --no-cache-dir --retries 10 -r /app/requirements.txt

COPY atlasbot /app/atlasbot
RUN addgroup --system atlasbot && \
    adduser --system --ingroup atlasbot --home /app atlasbot && \
    chown -R atlasbot:atlasbot /app

FROM base AS test
COPY requirements-dev.txt /app/requirements-dev.txt
RUN pip install --no-cache-dir --retries 10 -r /app/requirements-dev.txt
COPY testing /app/testing
COPY tests /app/tests
COPY scripts /app/scripts

FROM base AS runtime
EXPOSE 8090
USER atlasbot
CMD ["python", "-m", "atlasbot.main"]
