backend.Dockerfile 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. ARG BASE_IMAGE=pytorch/pytorch:2.3.1-cuda12.1-cudnn8-runtime
  2. ARG MODEL_SIZE=base_plus
  3. FROM ${BASE_IMAGE}
  4. # Gunicorn environment variables
  5. ENV GUNICORN_WORKERS=1
  6. ENV GUNICORN_THREADS=2
  7. ENV GUNICORN_PORT=5000
  8. # SAM 2 environment variables
  9. ENV APP_ROOT=/opt/sam2
  10. ENV PYTHONUNBUFFERED=1
  11. ENV SAM2_BUILD_CUDA=0
  12. ENV MODEL_SIZE=${MODEL_SIZE}
  13. # Install system requirements
  14. RUN apt-get update && apt-get install -y --no-install-recommends \
  15. ffmpeg \
  16. libavutil-dev \
  17. libavcodec-dev \
  18. libavformat-dev \
  19. libswscale-dev \
  20. pkg-config \
  21. build-essential \
  22. libffi-dev
  23. COPY setup.py .
  24. COPY README.md .
  25. RUN pip install --upgrade pip setuptools
  26. RUN pip install -e ".[interactive-demo]"
  27. # https://github.com/Kosinkadink/ComfyUI-VideoHelperSuite/issues/69#issuecomment-1826764707
  28. RUN rm /opt/conda/bin/ffmpeg && ln -s /bin/ffmpeg /opt/conda/bin/ffmpeg
  29. # Make app directory. This directory will host all files required for the
  30. # backend and SAM 2 inference files.
  31. RUN mkdir ${APP_ROOT}
  32. # Copy backend server files
  33. COPY demo/backend/server ${APP_ROOT}/server
  34. # Copy SAM 2 inference files
  35. COPY sam2 ${APP_ROOT}/server/sam2
  36. # Download SAM 2.1 checkpoints
  37. ADD https://dl.fbaipublicfiles.com/segment_anything_2/092824/sam2.1_hiera_tiny.pt ${APP_ROOT}/checkpoints/sam2.1_hiera_tiny.pt
  38. ADD https://dl.fbaipublicfiles.com/segment_anything_2/092824/sam2.1_hiera_small.pt ${APP_ROOT}/checkpoints/sam2.1_hiera_small.pt
  39. ADD https://dl.fbaipublicfiles.com/segment_anything_2/092824/sam2.1_hiera_base_plus.pt ${APP_ROOT}/checkpoints/sam2.1_hiera_base_plus.pt
  40. ADD https://dl.fbaipublicfiles.com/segment_anything_2/092824/sam2.1_hiera_large.pt ${APP_ROOT}/checkpoints/sam2.1_hiera_large.pt
  41. WORKDIR ${APP_ROOT}/server
  42. # https://pythonspeed.com/articles/gunicorn-in-docker/
  43. CMD gunicorn --worker-tmp-dir /dev/shm \
  44. --worker-class gthread app:app \
  45. --log-level info \
  46. --access-logfile /dev/stdout \
  47. --log-file /dev/stderr \
  48. --workers ${GUNICORN_WORKERS} \
  49. --threads ${GUNICORN_THREADS} \
  50. --bind 0.0.0.0:${GUNICORN_PORT} \
  51. --timeout 60