lokesh180340026 commited on
Commit
3edfdaf
·
verified ·
1 Parent(s): 6cd3f45
Files changed (1) hide show
  1. Dockerfile +71 -100
Dockerfile CHANGED
@@ -1,10 +1,19 @@
 
1
  # ComfyUI Dockerfile for Hugging Face Spaces
2
- # Pre-configured with LTX-Video 2.0 Models (Downloads at RUNTIME)
3
- # Total model size: ~42GB - Downloaded on first startup
4
-
5
- FROM python:3.12-slim-bookworm
6
-
 
 
 
 
 
 
 
7
  # Environment variables
 
8
  ENV DEBIAN_FRONTEND=noninteractive \
9
  PYTHONUNBUFFERED=1 \
10
  PYTHONDONTWRITEBYTECODE=1 \
@@ -12,9 +21,12 @@ ENV DEBIAN_FRONTEND=noninteractive \
12
  PIP_DISABLE_PIP_VERSION_CHECK=1 \
13
  COMFYUI_PATH=/app/ComfyUI \
14
  COMFYUI_PORT=7860 \
15
- HF_HOME=/app/cache/huggingface
 
16
 
17
- # Install system dependencies
 
 
18
  RUN apt-get update && apt-get install -y --no-install-recommends \
19
  git \
20
  git-lfs \
@@ -27,33 +39,62 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
27
  libxrender1 \
28
  libgomp1 \
29
  ffmpeg \
 
30
  && apt-get clean \
31
  && rm -rf /var/lib/apt/lists/*
32
 
 
33
  # Create app directory
34
- RUN mkdir -p /app/cache/huggingface && chmod -R 777 /app
 
 
35
 
36
  WORKDIR /app
37
 
38
- # Install PyTorch CPU
 
 
 
 
39
  RUN pip install --upgrade pip && \
40
  pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cpu
41
 
 
42
  # Clone ComfyUI
 
43
  RUN git clone --depth 1 https://github.com/Comfy-Org/ComfyUI.git ${COMFYUI_PATH}
44
 
45
  WORKDIR ${COMFYUI_PATH}
46
 
 
47
  # Install ComfyUI dependencies
 
48
  RUN pip install -r requirements.txt
49
 
 
50
  # Install ComfyUI Manager
 
51
  RUN git clone --depth 1 https://github.com/Comfy-Org/ComfyUI-Manager.git custom_nodes/ComfyUI-Manager
52
 
53
- # Install additional packages
54
- RUN pip install aiohttp requests tqdm Pillow numpy scipy huggingface_hub
55
-
56
- # Create all necessary directories
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
57
  RUN mkdir -p \
58
  models/checkpoints \
59
  models/clip \
@@ -66,105 +107,35 @@ RUN mkdir -p \
66
  models/loras \
67
  models/photomaker \
68
  models/style_models \
69
- models/text_encoders \
70
- models/latent_upscale_models \
71
  models/unet \
72
  models/upscale_models \
73
  models/vae \
74
  models/vae_approx \
 
75
  input \
76
  output \
77
  temp \
78
  user \
79
  && chmod -R 777 /app
80
 
81
- # Extra model paths configuration
82
- RUN echo 'comfyui:\n\
83
- base_path: /app/ComfyUI\n\
84
- checkpoints: models/checkpoints\n\
85
- clip: models/clip\n\
86
- clip_vision: models/clip_vision\n\
87
- configs: models/configs\n\
88
- controlnet: models/controlnet\n\
89
- embeddings: models/embeddings\n\
90
- loras: models/loras\n\
91
- text_encoders: models/text_encoders\n\
92
- latent_upscale_models: models/latent_upscale_models\n\
93
- upscale_models: models/upscale_models\n\
94
- vae: models/vae' > extra_model_paths.yaml
95
-
96
- # Create entrypoint script that downloads models at runtime
97
- RUN cat > /app/entrypoint.sh << 'EOF'
98
- #!/bin/bash
99
- set -e
100
-
101
- cd /app/ComfyUI
102
-
103
- download_model() {
104
- local url="$1"
105
- local output="$2"
106
- local name="$3"
107
-
108
- if [ -f "$output" ]; then
109
- echo "✓ $name already exists, skipping..."
110
- else
111
- echo "⬇ Downloading $name..."
112
- wget -q --show-progress --progress=bar:force -O "$output" "$url" || {
113
- echo "✗ Failed to download $name, retrying..."
114
- sleep 5
115
- wget -q --show-progress --progress=bar:force -O "$output" "$url"
116
- }
117
- echo "✓ $name downloaded successfully"
118
- fi
119
- }
120
-
121
- echo "=============================================="
122
- echo " Downloading LTX-Video 2.0 Models..."
123
- echo "=============================================="
124
-
125
- # 1. LTX-2-19B Checkpoint (FP8) - 25.22 GB
126
- download_model \
127
- "https://huggingface.co/Lightricks/LTX-2/resolve/main/ltx-2-19b-dev-fp8.safetensors" \
128
- "models/checkpoints/ltx-2-19b-dev-fp8.safetensors" \
129
- "LTX-2-19B Checkpoint (25.2 GB)"
130
-
131
- # 2. Gemma 3 12B Text Encoder (FP4 mixed) - 8.8 GB
132
- download_model \
133
- "https://huggingface.co/Comfy-Org/ltx-2/resolve/main/split_files/text_encoders/gemma_3_12B_it_fp4_mixed.safetensors" \
134
- "models/text_encoders/gemma_3_12B_it_fp4_mixed.safetensors" \
135
- "Gemma 3 12B Text Encoder (8.8 GB)"
136
-
137
- # 3. LTX-2 Spatial Upscaler - 949.64 MB
138
- download_model \
139
- "https://huggingface.co/Lightricks/LTX-2/resolve/main/ltx-2-spatial-upscaler-x2-1.0.safetensors" \
140
- "models/latent_upscale_models/ltx-2-spatial-upscaler-x2-1.0.safetensors" \
141
- "LTX-2 Spatial Upscaler (950 MB)"
142
-
143
- # 4. LTX-2 Distilled LoRA 384 - 7.15 GB
144
- download_model \
145
- "https://huggingface.co/Lightricks/LTX-2/resolve/main/ltx-2-19b-distilled-lora-384.safetensors" \
146
- "models/loras/ltx-2-19b-distilled-lora-384.safetensors" \
147
- "LTX-2 Distilled LoRA (7.15 GB)"
148
-
149
- # 5. LTX-2 Camera Control LoRA (Dolly Left) - 312.15 MB
150
- download_model \
151
- "https://huggingface.co/Lightricks/LTX-2-19b-LoRA-Camera-Control-Dolly-Left/resolve/main/ltx-2-19b-lora-camera-control-dolly-left.safetensors" \
152
- "models/loras/ltx-2-19b-lora-camera-control-dolly-left.safetensors" \
153
- "LTX-2 Camera Control LoRA (312 MB)"
154
-
155
- echo "=============================================="
156
- echo " All models ready! Starting ComfyUI..."
157
- echo "=============================================="
158
-
159
- exec python main.py --listen 0.0.0.0 --port 7860 --enable-cors-header --preview-method auto --cpu
160
- EOF
161
-
162
- RUN chmod +x /app/entrypoint.sh
163
 
 
 
 
164
  EXPOSE 7860
165
 
166
- HEALTHCHECK --interval=30s --timeout=10s --start-period=600s --retries=3 \
 
 
 
167
  CMD curl -f http://localhost:${COMFYUI_PORT}/ || exit 1
168
 
169
- # Run entrypoint which downloads models then starts ComfyUI
170
- ENTRYPOINT ["/app/entrypoint.sh"]
 
 
 
1
+ # =============================================================
2
  # ComfyUI Dockerfile for Hugging Face Spaces
3
+ # With Persistent Storage & ComfyUI Manager
4
+ # =============================================================
5
+ # Features:
6
+ # - ComfyUI + ComfyUI-Manager pre-installed
7
+ # - Persistent storage via /data (survives restarts)
8
+ # - Auto GPU/CPU detection at runtime
9
+ # - All models, custom nodes, outputs persist across rebuilds
10
+ # =============================================================
11
+
12
+ FROM python:3.11-slim-bookworm
13
+
14
+ # ---------------------------
15
  # Environment variables
16
+ # ---------------------------
17
  ENV DEBIAN_FRONTEND=noninteractive \
18
  PYTHONUNBUFFERED=1 \
19
  PYTHONDONTWRITEBYTECODE=1 \
 
21
  PIP_DISABLE_PIP_VERSION_CHECK=1 \
22
  COMFYUI_PATH=/app/ComfyUI \
23
  COMFYUI_PORT=7860 \
24
+ PYTORCH_CUDA_ALLOC_CONF=expandable_segments:True \
25
+ HF_HOME=/data/comfyui/.cache/huggingface
26
 
27
+ # ---------------------------
28
+ # System dependencies
29
+ # ---------------------------
30
  RUN apt-get update && apt-get install -y --no-install-recommends \
31
  git \
32
  git-lfs \
 
39
  libxrender1 \
40
  libgomp1 \
41
  ffmpeg \
42
+ procps \
43
  && apt-get clean \
44
  && rm -rf /var/lib/apt/lists/*
45
 
46
+ # ---------------------------
47
  # Create app directory
48
+ # ---------------------------
49
+ RUN mkdir -p /app/cache/huggingface && \
50
+ chmod -R 777 /app
51
 
52
  WORKDIR /app
53
 
54
+ # ---------------------------
55
+ # Install PyTorch (CPU version — lightweight for build)
56
+ # GPU Spaces will still work with this; for best GPU perf
57
+ # switch to: --extra-index-url https://download.pytorch.org/whl/cu121
58
+ # ---------------------------
59
  RUN pip install --upgrade pip && \
60
  pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cpu
61
 
62
+ # ---------------------------
63
  # Clone ComfyUI
64
+ # ---------------------------
65
  RUN git clone --depth 1 https://github.com/Comfy-Org/ComfyUI.git ${COMFYUI_PATH}
66
 
67
  WORKDIR ${COMFYUI_PATH}
68
 
69
+ # ---------------------------
70
  # Install ComfyUI dependencies
71
+ # ---------------------------
72
  RUN pip install -r requirements.txt
73
 
74
+ # ---------------------------
75
  # Install ComfyUI Manager
76
+ # ---------------------------
77
  RUN git clone --depth 1 https://github.com/Comfy-Org/ComfyUI-Manager.git custom_nodes/ComfyUI-Manager
78
 
79
+ # ---------------------------
80
+ # Install additional packages commonly needed by nodes
81
+ # ---------------------------
82
+ RUN pip install \
83
+ aiohttp \
84
+ requests \
85
+ tqdm \
86
+ Pillow \
87
+ numpy \
88
+ scipy \
89
+ opencv-python-headless \
90
+ huggingface-hub \
91
+ safetensors \
92
+ accelerate \
93
+ pyyaml
94
+
95
+ # ---------------------------
96
+ # Create model directories (will be migrated to /data at runtime)
97
+ # ---------------------------
98
  RUN mkdir -p \
99
  models/checkpoints \
100
  models/clip \
 
107
  models/loras \
108
  models/photomaker \
109
  models/style_models \
 
 
110
  models/unet \
111
  models/upscale_models \
112
  models/vae \
113
  models/vae_approx \
114
+ models/configs \
115
  input \
116
  output \
117
  temp \
118
  user \
119
  && chmod -R 777 /app
120
 
121
+ # ---------------------------
122
+ # Copy entrypoint script
123
+ # ---------------------------
124
+ COPY start.sh /app/start.sh
125
+ RUN chmod +x /app/start.sh
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
126
 
127
+ # ---------------------------
128
+ # Expose port (HuggingFace Spaces expects 7860)
129
+ # ---------------------------
130
  EXPOSE 7860
131
 
132
+ # ---------------------------
133
+ # Health check
134
+ # ---------------------------
135
+ HEALTHCHECK --interval=30s --timeout=10s --start-period=120s --retries=5 \
136
  CMD curl -f http://localhost:${COMFYUI_PORT}/ || exit 1
137
 
138
+ # ---------------------------
139
+ # Run via entrypoint (handles persistent storage + auto GPU/CPU)
140
+ # ---------------------------
141
+ ENTRYPOINT ["/app/start.sh"]