sutmo commited on
Commit
3376d65
·
verified ·
1 Parent(s): 75c56e4

Upload backend.Dockerfile

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