Files
dinoV2/Dockerfile
T

46 lines
1.8 KiB
Docker
Raw 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.
# Multi-stage: builder с зависимостями -> тонкий runtime-слой.
# Цель: CPU-инференс на VPS Ubuntu; torch ставится строго CPU-сборкой.
FROM python:3.12-slim AS builder
ENV PIP_NO_CACHE_DIR=1 \
PIP_DISABLE_PIP_VERSION_CHECK=1
WORKDIR /build
COPY requirements.txt .
# torch/torchvision первыми и только из CPU-индекса PyTorch,
# затем остальное из PyPI (torch уже удовлетворён и не переустанавливается)
RUN pip install --prefix=/install torch torchvision \
--index-url https://download.pytorch.org/whl/cpu \
&& pip install --prefix=/install -r requirements.txt
FROM python:3.12-slim
ENV PYTHONUNBUFFERED=1 \
PYTHONDONTWRITEBYTECODE=1 \
PORT=8000 \
WORKERS=1
RUN useradd --create-home --shell /usr/sbin/nologin appuser
WORKDIR /srv
COPY --from=builder /install /usr/local
COPY app ./app
# /srv принадлежит root: кэш под веса создаём и передаём appuser до USER
RUN mkdir -p /srv/.cache/torch && chown -R appuser:appuser /srv
USER appuser
# Кэш torch.hub (код dinov2 + веса ~84 МБ) запекаем в образ:
# контейнер стартует мгновенно и не зависит от github/fbaipublicfiles
ENV TORCH_HOME=/srv/.cache/torch
RUN python -c "from app.dino.model import DinoEmbedder; DinoEmbedder('dinov2_vits14', 'cpu', 224).load()"
EXPOSE 8000
HEALTHCHECK --interval=30s --timeout=5s --start-period=60s --retries=3 \
CMD python -c "import urllib.request; urllib.request.urlopen('http://127.0.0.1:' + __import__('os').environ.get('PORT', '8000') + '/health', timeout=3)"
ENTRYPOINT ["uvicorn", "app.main:create_app", "--factory", "--no-access-log"]
CMD ["--host", "0.0.0.0", "--port", "8000"]