Files
post-moderation/ai-moderation/Dockerfile
2026-10-20 00:37:43 +03:00

32 lines
1.3 KiB
Docker
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

FROM python:3.12-slim
ENV PYTHONUNBUFFERED=1 \
PYTHONDONTWRITEBYTECODE=1 \
PIP_NO_CACHE_DIR=1 \
PIP_DISABLE_PIP_VERSION_CHECK=1
WORKDIR /app
# torch ставим отдельно в облегчённой версии для процессора (без CUDA).
# Версии те же, что в requirements.txt, — второй pip их уже не тронет.
RUN pip install torch==2.14.1 torchvision==0.29.1 --index-url https://download.pytorch.org/whl/cpu
COPY requirements.txt .
RUN pip install -r requirements.txt
COPY app ./app
RUN useradd -r -m -u 1001 app \
&& mkdir -p /models \
&& chown app /models
USER app
ENV MODEL_CACHE_DIR=/models
ENV HF_HOME=/models/hf
EXPOSE 8000
# Первый старт качает модели (несколько минут) — даём запас start-period
HEALTHCHECK --interval=30s --timeout=5s --start-period=600s --retries=3 \
CMD python -c "import urllib.request,sys; sys.exit(0 if urllib.request.urlopen('http://127.0.0.1:8000/ready', timeout=4).status == 200 else 1)"
# --limit-concurrency: лишние соединения сразу получают 503, а не копятся
CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8000", "--limit-concurrency", "64", "--no-server-header"]