FROM python:3.12.12-slim-bookworm

ENV PYTHONDONTWRITEBYTECODE=1 \
    PYTHONUNBUFFERED=1 \
    POETRY_VIRTUALENVS_CREATE=false

WORKDIR /app
RUN --mount=type=cache,target=/root/.cache/pip \
    pip install --timeout 30 --retries 8 "poetry==2.2.1"
COPY poetry.lock pyproject.toml ./
RUN --mount=type=cache,target=/root/.cache/pypoetry \
    poetry config requests.max-retries 6 \
    && poetry install --only main --no-root --no-interaction
COPY migrations ./migrations
COPY src ./src

# Процесс работает не от root
RUN useradd --system --uid 10001 --no-create-home app
USER app

ARG APP_REVISION=dev
ENV APP_REVISION=${APP_REVISION}
LABEL org.opencontainers.image.revision=${APP_REVISION}

EXPOSE 8080
HEALTHCHECK --interval=10s --timeout=3s --start-period=5s --retries=3 \
    CMD ["python", "src/healthcheck.py"]
CMD ["python", "src/gateway.py"]
