R1000 commited on
Commit
e090d34
·
verified ·
1 Parent(s): 1d3c305

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +51 -39
Dockerfile CHANGED
@@ -2,6 +2,7 @@
2
 
3
  FROM python:3.10-slim
4
 
 
5
  ENV DEBIAN_FRONTEND=noninteractive \
6
  PYTHONUNBUFFERED=1 \
7
  PYTHONDONTWRITEBYTECODE=1 \
@@ -13,43 +14,48 @@ ENV DEBIAN_FRONTEND=noninteractive \
13
  OPENBLAS_NUM_THREADS=2 \
14
  NUMEXPR_NUM_THREADS=2 \
15
  TOKENIZERS_PARALLELISM=false \
 
16
  HF_XET_HIGH_PERFORMANCE=1
17
 
18
  EXPOSE 7860
19
 
 
20
  RUN apt-get update && apt-get install -y --no-install-recommends \
21
  git git-lfs curl wget ca-certificates ffmpeg libgl1 libglib2.0-0 \
22
  libsm6 libxext6 libxrender1 libgomp1 build-essential \
23
  && rm -rf /var/lib/apt/lists/* \
24
  && git lfs install
25
 
 
26
  RUN useradd --create-home --shell /bin/bash --uid 1000 user
27
 
28
  WORKDIR /app
29
 
 
30
  RUN python -m pip install --upgrade pip setuptools wheel && \
31
  python -m pip install \
32
- "torch==2.7.1" \
33
- "torchvision==0.22.1" \
34
- "torchaudio==2.7.1" \
35
- --index-url https://download.pytorch.org/whl/cpu
36
 
 
37
  RUN git clone --depth 1 https://github.com/comfyanonymous/ComfyUI.git /app/ComfyUI && \
38
  cd /app/ComfyUI && python -m pip install -r requirements.txt
39
 
40
- # Keep the CPU PyTorch versions after installing ComfyUI requirements.
41
  RUN python -m pip install --force-reinstall \
42
- "torch==2.7.1" \
43
- "torchvision==0.22.1" \
44
- "torchaudio==2.7.1" \
45
- --index-url https://download.pytorch.org/whl/cpu
46
 
47
  # ------------------------------------------------------------------
48
- # Seven custom nodes
49
  # ------------------------------------------------------------------
50
  RUN mkdir -p /app/ComfyUI/custom_nodes && \
51
  cd /app/ComfyUI/custom_nodes && \
52
- git clone https://github.com/ltdrdata/ComfyUI-Manager.git comfyui-manager && \
53
  git clone --depth 1 https://github.com/RealRebelAI/ComfyUI-GGUF_KREA-2.git ComfyUI-GGUF_KREA-2 && \
54
  git clone --depth 1 https://github.com/crystian/comfyui-crystools.git comfyui-crystools && \
55
  git clone --depth 1 https://github.com/rgthree/rgthree-comfy.git rgthree-comfy && \
@@ -63,23 +69,25 @@ RUN mkdir -p /app/ComfyUI/custom_nodes && \
63
  git clone --depth 1 https://github.com/ty0x2333/ComfyUI-Dev-Utils.git ComfyUI-Dev-Utils && \
64
  git clone --depth 1 https://github.com/ServiceStack/comfy-asset-downloader.git comfy-asset-downloader
65
 
66
- RUN set -eux; \
 
 
 
67
  find /app/ComfyUI/custom_nodes -mindepth 1 -maxdepth 1 -type d | while read -r d; do \
68
  if [ -f "$d/requirements.txt" ]; then \
69
- python -m pip install -r "$d/requirements.txt"; \
70
  fi; \
71
  done
72
 
 
73
  RUN python -m pip install \
74
- "huggingface_hub>=0.33" "hf_transfer>=0.1.9" psutil websocket-client opencv-python-headless einops \
 
 
75
  transformers safetensors color-matcher scikit-image numba dynamicprompts diffusers
76
 
77
  # ------------------------------------------------------------------
78
- # Runtime directories.
79
- #
80
- # IMPORTANT:
81
- # ComfyUI 0.35.x creates /app/ComfyUI/user at startup.
82
- # It must be writable by the non-root "user" account.
83
  # ------------------------------------------------------------------
84
  RUN mkdir -p \
85
  /app/ComfyUI/user \
@@ -97,16 +105,17 @@ RUN mkdir -p \
97
  /app/ComfyUI/temp \
98
  /data && \
99
  chown -R user:user \
100
- /app/ComfyUI/user \
101
- /app/ComfyUI/models \
102
- /app/ComfyUI/workflows \
103
- /app/ComfyUI/input \
104
- /app/ComfyUI/output \
105
- /app/ComfyUI/temp \
106
- /data
107
 
 
108
  COPY --chown=user start.sh /app/start.sh
109
- RUN chmod +x /app/start.sh && chown user:user /app/start.sh
110
 
111
  USER user
112
 
@@ -116,21 +125,24 @@ ENV HOME=/home/user \
116
  PATH=/home/user/.local/bin:$PATH \
117
  PYTHONPATH=/app/ComfyUI
118
 
119
- # Build-time sanity check.
120
  RUN python - <<'PY'
121
  import torch
122
- print("PyTorch:", torch.__version__)
123
- print("CUDA available:", torch.cuda.is_available())
124
- assert torch.__version__.startswith("2.7.1")
125
- assert not torch.cuda.is_available()
126
-
127
- import comfy_kitchen
128
- print("comfy_kitchen:", comfy_kitchen.__file__)
129
- print("int8_attention_is_available:",
130
- hasattr(comfy_kitchen, "int8_attention_is_available"))
 
131
  PY
132
 
 
 
133
  HEALTHCHECK --interval=30s --timeout=10s --start-period=180s --retries=5 \
134
- CMD curl -fsS http://127.0.0.1:7860/system_stats >/dev/null || exit 1
135
 
136
- ENTRYPOINT ["/app/start.sh"]
 
2
 
3
  FROM python:3.10-slim
4
 
5
+ # Environment variables optimized for CPU and Hugging Face Spaces
6
  ENV DEBIAN_FRONTEND=noninteractive \
7
  PYTHONUNBUFFERED=1 \
8
  PYTHONDONTWRITEBYTECODE=1 \
 
14
  OPENBLAS_NUM_THREADS=2 \
15
  NUMEXPR_NUM_THREADS=2 \
16
  TOKENIZERS_PARALLELISM=false \
17
+ HF_HUB_ENABLE_HF_TRANSFER=1 \
18
  HF_XET_HIGH_PERFORMANCE=1
19
 
20
  EXPOSE 7860
21
 
22
+ # Install system dependencies
23
  RUN apt-get update && apt-get install -y --no-install-recommends \
24
  git git-lfs curl wget ca-certificates ffmpeg libgl1 libglib2.0-0 \
25
  libsm6 libxext6 libxrender1 libgomp1 build-essential \
26
  && rm -rf /var/lib/apt/lists/* \
27
  && git lfs install
28
 
29
+ # Create non-root user for security (UID 1000 matches HF Spaces default)
30
  RUN useradd --create-home --shell /bin/bash --uid 1000 user
31
 
32
  WORKDIR /app
33
 
34
+ # Install PyTorch CPU version (Updated to stable 2.5.1, adjust if needed)
35
  RUN python -m pip install --upgrade pip setuptools wheel && \
36
  python -m pip install \
37
+ "torch==2.5.1" \
38
+ "torchvision==0.20.1" \
39
+ "torchaudio==2.5.1" \
40
+ --index-url https://download.pytorch.org/whl/cpu
41
 
42
+ # Clone ComfyUI and install base requirements
43
  RUN git clone --depth 1 https://github.com/comfyanonymous/ComfyUI.git /app/ComfyUI && \
44
  cd /app/ComfyUI && python -m pip install -r requirements.txt
45
 
46
+ # Force reinstall CPU PyTorch to prevent ComfyUI requirements from pulling CUDA versions
47
  RUN python -m pip install --force-reinstall \
48
+ "torch==2.5.1" \
49
+ "torchvision==0.20.1" \
50
+ "torchaudio==2.5.1" \
51
+ --index-url https://download.pytorch.org/whl/cpu
52
 
53
  # ------------------------------------------------------------------
54
+ # Install Custom Nodes
55
  # ------------------------------------------------------------------
56
  RUN mkdir -p /app/ComfyUI/custom_nodes && \
57
  cd /app/ComfyUI/custom_nodes && \
58
+ git clone --depth 1 https://github.com/ltdrdata/ComfyUI-Manager.git comfyui-manager && \
59
  git clone --depth 1 https://github.com/RealRebelAI/ComfyUI-GGUF_KREA-2.git ComfyUI-GGUF_KREA-2 && \
60
  git clone --depth 1 https://github.com/crystian/comfyui-crystools.git comfyui-crystools && \
61
  git clone --depth 1 https://github.com/rgthree/rgthree-comfy.git rgthree-comfy && \
 
69
  git clone --depth 1 https://github.com/ty0x2333/ComfyUI-Dev-Utils.git ComfyUI-Dev-Utils && \
70
  git clone --depth 1 https://github.com/ServiceStack/comfy-asset-downloader.git comfy-asset-downloader
71
 
72
+ # Install requirements for custom nodes
73
+ # Pre-install headless opencv to prevent nodes from pulling heavy GUI opencv-python
74
+ RUN python -m pip install opencv-python-headless && \
75
+ set -eux; \
76
  find /app/ComfyUI/custom_nodes -mindepth 1 -maxdepth 1 -type d | while read -r d; do \
77
  if [ -f "$d/requirements.txt" ]; then \
78
+ python -m pip install --no-cache-dir -r "$d/requirements.txt"; \
79
  fi; \
80
  done
81
 
82
+ # Install additional common dependencies
83
  RUN python -m pip install \
84
+ "huggingface_hub>=0.25.0" \
85
+ "hf_transfer>=0.1.9" \
86
+ psutil websocket-client einops \
87
  transformers safetensors color-matcher scikit-image numba dynamicprompts diffusers
88
 
89
  # ------------------------------------------------------------------
90
+ # Runtime directories and permissions
 
 
 
 
91
  # ------------------------------------------------------------------
92
  RUN mkdir -p \
93
  /app/ComfyUI/user \
 
105
  /app/ComfyUI/temp \
106
  /data && \
107
  chown -R user:user \
108
+ /app/ComfyUI/user \
109
+ /app/ComfyUI/models \
110
+ /app/ComfyUI/workflows \
111
+ /app/ComfyUI/input \
112
+ /app/ComfyUI/output \
113
+ /app/ComfyUI/temp \
114
+ /data
115
 
116
+ # Copy startup script (⚠️ IMPORTANT: start.sh must exist in your build directory)
117
  COPY --chown=user start.sh /app/start.sh
118
+ RUN chmod +x /app/start.sh
119
 
120
  USER user
121
 
 
125
  PATH=/home/user/.local/bin:$PATH \
126
  PYTHONPATH=/app/ComfyUI
127
 
128
+ # Build-time sanity check (Fixed: removed non-existent comfy_kitchen import)
129
  RUN python - <<'PY'
130
  import torch
131
+ print("PyTorch Version:", torch.__version__)
132
+ print("CUDA Available:", torch.cuda.is_available())
133
+
134
+ # Verify CPU-only build
135
+ assert torch.__version__.startswith("2.5.1"), f"Expected PyTorch 2.5.1, got {torch.__version__}"
136
+ assert not torch.cuda.is_available(), "CUDA should not be available in CPU build"
137
+
138
+ # Verify ComfyUI core is importable
139
+ import comfy
140
+ print("ComfyUI core imported successfully")
141
  PY
142
 
143
+ COPY ./workflow /app/ComfyUI/user/default/workflows/
144
+
145
  HEALTHCHECK --interval=30s --timeout=10s --start-period=180s --retries=5 \
146
+ CMD curl -fsS http://127.0.0.1:7860/system_stats >/dev/null || exit 1
147
 
148
+ ENTRYPOINT ["/app/start.sh"]