Skip to content

Commit 04b5a56

Browse files
committed
commit
1 parent d89c3ce commit 04b5a56

17 files changed

Lines changed: 2611 additions & 13 deletions

.dockerignore

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
# Git
2+
.git
3+
.gitignore
4+
5+
# Python
6+
__pycache__/
7+
*.py[cod]
8+
*$py.class
9+
*.so
10+
.Python
11+
build/
12+
develop-eggs/
13+
dist/
14+
downloads/
15+
eggs/
16+
.eggs/
17+
lib/
18+
lib64/
19+
parts/
20+
sdist/
21+
var/
22+
wheels/
23+
*.egg-info/
24+
.installed.cfg
25+
*.egg
26+
MANIFEST
27+
28+
# Virtual environments
29+
.env
30+
.venv
31+
env/
32+
venv/
33+
ENV/
34+
env.bak/
35+
venv.bak/
36+
37+
# IDE
38+
.vscode/
39+
.idea/
40+
*.swp
41+
*.swo
42+
43+
# OS
44+
.DS_Store
45+
Thumbs.db
46+
47+
# Project specific
48+
outputs/
49+
temp_queue_images/
50+
archive/
51+
hf_download/
52+
job_queue.json
53+
quick_prompts.json
54+
*.log
55+
56+
# Docker
57+
Dockerfile*
58+
docker-compose*.yml
59+
.dockerignore
60+
61+
# Documentation
62+
*.md
63+
plan/
64+
65+
# Cache
66+
.cache/
67+
.pytest_cache/
68+
.mypy_cache/
69+
.ruff_cache/
70+
71+
# Temporary files
72+
*.tmp
73+
*.temp

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,3 +188,5 @@ job_queue.json
188188
main.obj
189189
main.exp
190190
main.lib
191+
CLAUDE.md
192+
.mcp/

Dockerfile

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
# FramePack-FastAPI with External Model Mount
2+
3+
FROM nvidia/cuda:12.1-devel-ubuntu22.04
4+
5+
# Install system dependencies
6+
RUN apt-get update && apt-get install -y \
7+
python3.10 \
8+
python3.10-dev \
9+
python3-pip \
10+
curl \
11+
git \
12+
build-essential \
13+
libgl1-mesa-glx \
14+
libglib2.0-0 \
15+
libsm6 \
16+
libxext6 \
17+
libxrender-dev \
18+
libgomp1 \
19+
ffmpeg \
20+
&& rm -rf /var/lib/apt/lists/*
21+
22+
# Create symlink for python
23+
RUN ln -s /usr/bin/python3.10 /usr/bin/python
24+
25+
# Install uv
26+
COPY --from=ghcr.io/astral-sh/uv:latest /uv /bin/uv
27+
28+
# Set working directory
29+
WORKDIR /app
30+
31+
# Copy dependency files
32+
COPY pyproject.toml requirements.txt ./
33+
34+
# Create virtual environment and install dependencies
35+
RUN uv venv /opt/venv
36+
ENV PATH="/opt/venv/bin:$PATH"
37+
38+
# Install Python dependencies
39+
RUN uv pip install --no-cache -r requirements.txt
40+
41+
# Copy application code
42+
COPY . .
43+
44+
# Create necessary directories
45+
RUN mkdir -p outputs/images temp_queue_images loras
46+
47+
# Create model mount points
48+
RUN mkdir -p /app/hf_download
49+
VOLUME ["/app/hf_download"]
50+
51+
# Set environment variables
52+
ENV PYTHONPATH="/app:$PYTHONPATH"
53+
ENV PYTHONUNBUFFERED=1
54+
ENV HF_HOME="/app/hf_download"
55+
ENV TRANSFORMERS_CACHE="/app/hf_download"
56+
ENV HF_DATASETS_CACHE="/app/hf_download"
57+
58+
# Expose port
59+
EXPOSE 8000
60+
61+
# Health check
62+
HEALTHCHECK --interval=30s --timeout=30s --start-period=5s --retries=3 \
63+
CMD curl -f http://localhost:8000/docs || exit 1
64+
65+
# Start command
66+
CMD ["uvicorn", "api.api:app", "--host", "0.0.0.0", "--port", "8000"]

README_DOCKER.md

Lines changed: 248 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,248 @@
1+
# FramePack-FastAPI Docker Guide
2+
3+
このガイドでは、FramePack-FastAPIをDockerで実行する方法を説明します。
4+
5+
## 🐳 Docker構成
6+
7+
### 利用可能なDockerfile
8+
9+
1. **Dockerfile** - CPU版(軽量、推論のみ)
10+
2. **Dockerfile.gpu** - GPU版(CUDA対応、高性能)
11+
12+
### Docker Compose設定
13+
14+
1. **docker-compose.yml** - CPU版用
15+
2. **docker-compose.gpu.yml** - GPU版用
16+
17+
## 🚀 クイックスタート
18+
19+
### CPU版を起動
20+
```bash
21+
# 自動ビルド&起動
22+
./docker-run.sh
23+
24+
# または手動で
25+
docker-compose up
26+
```
27+
28+
### GPU版を起動
29+
```bash
30+
# 自動ビルド&起動(GPU必須)
31+
./docker-run.sh --gpu
32+
33+
# または手動で
34+
docker-compose -f docker-compose.gpu.yml up
35+
```
36+
37+
## 🔨 手動ビルド
38+
39+
### CPUイメージをビルド
40+
```bash
41+
./docker-build.sh
42+
# または
43+
docker build -f Dockerfile -t framepack-fastapi:latest .
44+
```
45+
46+
### GPUイメージをビルド
47+
```bash
48+
./docker-build.sh --gpu
49+
# または
50+
docker build -f Dockerfile.gpu -t framepack-fastapi-gpu:latest .
51+
```
52+
53+
## 🏃‍♂️ 実行方法
54+
55+
### 1. Docker Composeを使用(推奨)
56+
57+
#### CPU版
58+
```bash
59+
docker-compose up -d # バックグラウンド実行
60+
docker-compose logs -f # ログを表示
61+
```
62+
63+
#### GPU版
64+
```bash
65+
docker-compose -f docker-compose.gpu.yml up -d
66+
docker-compose -f docker-compose.gpu.yml logs -f
67+
```
68+
69+
### 2. 直接Dockerコマンドを使用
70+
71+
#### CPU版
72+
```bash
73+
docker run -d \
74+
-p 8000:8000 \
75+
-v $(pwd)/outputs:/app/outputs \
76+
-v $(pwd)/temp_queue_images:/app/temp_queue_images \
77+
-v $(pwd)/loras:/app/loras \
78+
-v $(pwd)/hf_download:/app/hf_download \
79+
framepack-fastapi:latest
80+
```
81+
82+
#### GPU版
83+
```bash
84+
docker run -d \
85+
--gpus all \
86+
-p 8000:8000 \
87+
-v $(pwd)/outputs:/app/outputs \
88+
-v $(pwd)/temp_queue_images:/app/temp_queue_images \
89+
-v $(pwd)/loras:/app/loras \
90+
-v $(pwd)/hf_download:/app/hf_download \
91+
framepack-fastapi-gpu:latest
92+
```
93+
94+
## 🔧 カスタマイズ
95+
96+
### ポート変更
97+
```bash
98+
# ポート8080で起動
99+
./docker-run.sh --port 8080
100+
101+
# または環境変数で設定
102+
export PORT=8080
103+
docker-compose up
104+
```
105+
106+
### 環境変数
107+
108+
重要な環境変数:
109+
110+
```bash
111+
# API設定
112+
API_HOST=0.0.0.0
113+
API_PORT=8000
114+
115+
# モデルキャッシュ
116+
HF_HOME=/app/hf_download
117+
TRANSFORMERS_CACHE=/app/hf_download
118+
119+
# GPU設定(GPU版のみ)
120+
CUDA_VISIBLE_DEVICES=0
121+
NVIDIA_VISIBLE_DEVICES=all
122+
```
123+
124+
### ボリューム設定
125+
126+
永続化されるデータ:
127+
128+
- `./outputs` - 生成された動画・画像
129+
- `./temp_queue_images` - キュー用一時画像
130+
- `./loras` - LoRAファイル
131+
- `./hf_download` - Hugging Faceモデルキャッシュ
132+
- `./job_queue.json` - ジョブキュー状態
133+
134+
## 📋 システム要件
135+
136+
### CPU版
137+
- **RAM**: 最小8GB、推奨16GB以上
138+
- **ストレージ**: 最小20GB の空き容量
139+
- **CPU**: マルチコア推奨
140+
141+
### GPU版
142+
- **GPU**: NVIDIA GPU(CUDA 12.1対応)
143+
- **VRAM**: 最小8GB、推奨24GB以上
144+
- **RAM**: 最小16GB、推奨32GB以上
145+
- **ストレージ**: 最小50GB の空き容量
146+
- **NVIDIA Docker**: インストール済み
147+
148+
## 🛠️ トラブルシューティング
149+
150+
### よくある問題
151+
152+
#### 1. GPU版でGPUが認識されない
153+
```bash
154+
# NVIDIA Dockerの確認
155+
docker run --rm --gpus all nvidia/cuda:12.1-base-ubuntu22.04 nvidia-smi
156+
157+
# GPU対応確認
158+
docker-compose -f docker-compose.gpu.yml exec framepack-api-gpu python -c "import torch; print(torch.cuda.is_available())"
159+
```
160+
161+
#### 2. メモリ不足エラー
162+
```bash
163+
# Dockerのメモリ制限を確認・調整
164+
docker stats
165+
166+
# Swapファイルを有効化(Linux)
167+
sudo swapon --show
168+
```
169+
170+
#### 3. モデルダウンロードが遅い/失敗する
171+
```bash
172+
# Hugging Face キャッシュを事前ダウンロード
173+
mkdir -p hf_download
174+
docker run -v $(pwd)/hf_download:/app/hf_download framepack-fastapi-gpu:latest python -c "
175+
from transformers import AutoTokenizer
176+
AutoTokenizer.from_pretrained('hunyuanvideo-community/HunyuanVideo', cache_dir='/app/hf_download')
177+
"
178+
```
179+
180+
#### 4. ポート競合
181+
```bash
182+
# 使用中のポートを確認
183+
netstat -tlnp | grep :8000
184+
185+
# 別のポートを使用
186+
docker-compose up -e API_PORT=8080
187+
```
188+
189+
### ログの確認
190+
191+
```bash
192+
# サービスログ
193+
docker-compose logs framepack-api
194+
195+
# リアルタイムログ
196+
docker-compose logs -f framepack-api
197+
198+
# 特定コンテナのログ
199+
docker logs <container_id>
200+
```
201+
202+
### パフォーマンス監視
203+
204+
```bash
205+
# リソース使用量
206+
docker stats
207+
208+
# GPU使用量(GPU版)
209+
docker-compose -f docker-compose.gpu.yml exec framepack-api-gpu nvidia-smi
210+
```
211+
212+
## 🌐 API アクセス
213+
214+
コンテナ起動後、以下のURLでアクセス可能:
215+
216+
- **API**: http://localhost:8000
217+
- **API ドキュメント**: http://localhost:8000/docs
218+
- **動画生成**: http://localhost:8000/generate
219+
- **画像生成**: http://localhost:8000/api/generate-image
220+
221+
## 🔄 更新とメンテナンス
222+
223+
### イメージの更新
224+
```bash
225+
# 最新コードでリビルド
226+
./docker-build.sh --tag latest
227+
228+
# 古いイメージを削除
229+
docker image prune -f
230+
```
231+
232+
### データのバックアップ
233+
```bash
234+
# 生成データをバックアップ
235+
tar -czf framepack-backup-$(date +%Y%m%d).tar.gz outputs/ temp_queue_images/ loras/ hf_download/
236+
```
237+
238+
### コンテナの停止と削除
239+
```bash
240+
# サービス停止
241+
docker-compose down
242+
243+
# データボリュームも含めて削除
244+
docker-compose down -v
245+
246+
# 完全クリーンアップ
247+
docker system prune -af
248+
```

0 commit comments

Comments
 (0)