Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 73 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
# Git
.git
.gitignore

# Python
__pycache__/
*.py[cod]
*$py.class
*.so
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# Virtual environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# IDE
.vscode/
.idea/
*.swp
*.swo

# OS
.DS_Store
Thumbs.db

# Project specific
outputs/
temp_queue_images/
archive/
hf_download/
job_queue.json
quick_prompts.json
*.log

# Docker
Dockerfile*
docker-compose*.yml
.dockerignore

# Documentation
*.md
plan/

# Cache
.cache/
.pytest_cache/
.mypy_cache/
.ruff_cache/

# Temporary files
*.tmp
*.temp
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -188,3 +188,5 @@ job_queue.json
main.obj
main.exp
main.lib
CLAUDE.md
.mcp/
66 changes: 66 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# FramePack-FastAPI with External Model Mount

FROM nvidia/cuda:12.1-devel-ubuntu22.04

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

This Dockerfile uses a CUDA base image (nvidia/cuda:12.1-devel-ubuntu22.04), which implies it's intended for GPU usage. However, README_DOCKER.md and README_DOCKER_REVISED.md describe Dockerfile as the 'CPU version' or '開発用サーバー (モデルなし)'. This seems contradictory. If this Dockerfile is indeed for GPU, it might be clearer to name it Dockerfile.gpu and ensure the CPU/dev version uses a non-CUDA base image.


# Install system dependencies
RUN apt-get update && apt-get install -y \
python3.10 \
python3.10-dev \
python3-pip \
curl \
git \
build-essential \
libgl1-mesa-glx \
libglib2.0-0 \
libsm6 \
libxext6 \
libxrender-dev \
libgomp1 \
ffmpeg \
&& rm -rf /var/lib/apt/lists/*

# Create symlink for python
RUN ln -s /usr/bin/python3.10 /usr/bin/python

# Install uv
COPY --from=ghcr.io/astral-sh/uv:latest /uv /bin/uv

# Set working directory
WORKDIR /app

# Copy dependency files
COPY pyproject.toml requirements.txt ./

# Create virtual environment and install dependencies
RUN uv venv /opt/venv
ENV PATH="/opt/venv/bin:$PATH"

# Install Python dependencies
RUN uv pip install --no-cache -r requirements.txt

# Copy application code
COPY . .

# Create necessary directories
RUN mkdir -p outputs/images temp_queue_images loras

# Create model mount points
RUN mkdir -p /app/hf_download
VOLUME ["/app/hf_download"]

# Set environment variables
ENV PYTHONPATH="/app:$PYTHONPATH"
ENV PYTHONUNBUFFERED=1
ENV HF_HOME="/app/hf_download"
ENV TRANSFORMERS_CACHE="/app/hf_download"
ENV HF_DATASETS_CACHE="/app/hf_download"

# Expose port
EXPOSE 8000

# Health check
HEALTHCHECK --interval=30s --timeout=30s --start-period=5s --retries=3 \
CMD curl -f http://localhost:8000/docs || exit 1

# Start command
CMD ["uvicorn", "api.api:app", "--host", "0.0.0.0", "--port", "8000"]
248 changes: 248 additions & 0 deletions README_DOCKER.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,248 @@
# FramePack-FastAPI Docker Guide

このガイドでは、FramePack-FastAPIをDockerで実行する方法を説明します。

## 🐳 Docker構成

### 利用可能なDockerfile

1. **Dockerfile** - CPU版(軽量、推論のみ)
2. **Dockerfile.gpu** - GPU版(CUDA対応、高性能)
Comment on lines +9 to +10

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

This section correctly identifies Dockerfile as CPU and Dockerfile.gpu as GPU. This aligns with the intent described in README_DOCKER_REVISED.md, but contradicts the actual Dockerfile content and the usage in docker-compose.yml and the run scripts (see other comments). Please ensure consistency.


### Docker Compose設定

1. **docker-compose.yml** - CPU版用
2. **docker-compose.gpu.yml** - GPU版用
Comment on lines +14 to +15

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

Similarly, this section correctly identifies docker-compose.yml for CPU and docker-compose.gpu.yml for GPU. This aligns with README_DOCKER_REVISED.md but contradicts the current docker-compose.yml which requests GPU resources.


## 🚀 クイックスタート

### CPU版を起動
```bash
# 自動ビルド&起動
./docker-run.sh

# または手動で
docker-compose up
```

### GPU版を起動
```bash
# 自動ビルド&起動(GPU必須)
./docker-run.sh --gpu

# または手動で
docker-compose -f docker-compose.gpu.yml up
```

## 🔨 手動ビルド

### CPUイメージをビルド
```bash
./docker-build.sh
# または
docker build -f Dockerfile -t framepack-fastapi:latest .
```

### GPUイメージをビルド
```bash
./docker-build.sh --gpu
# または
docker build -f Dockerfile.gpu -t framepack-fastapi-gpu:latest .
```

## 🏃‍♂️ 実行方法

### 1. Docker Composeを使用(推奨)

#### CPU版
```bash
docker-compose up -d # バックグラウンド実行
docker-compose logs -f # ログを表示
```

#### GPU版
```bash
docker-compose -f docker-compose.gpu.yml up -d
docker-compose -f docker-compose.gpu.yml logs -f
```

### 2. 直接Dockerコマンドを使用

#### CPU版
```bash
docker run -d \
-p 8000:8000 \
-v $(pwd)/outputs:/app/outputs \
-v $(pwd)/temp_queue_images:/app/temp_queue_images \
-v $(pwd)/loras:/app/loras \
-v $(pwd)/hf_download:/app/hf_download \
framepack-fastapi:latest
```

#### GPU版
```bash
docker run -d \
--gpus all \
-p 8000:8000 \
-v $(pwd)/outputs:/app/outputs \
-v $(pwd)/temp_queue_images:/app/temp_queue_images \
-v $(pwd)/loras:/app/loras \
-v $(pwd)/hf_download:/app/hf_download \
framepack-fastapi-gpu:latest
```

## 🔧 カスタマイズ

### ポート変更
```bash
# ポート8080で起動
./docker-run.sh --port 8080

# または環境変数で設定
export PORT=8080
docker-compose up
```

### 環境変数

重要な環境変数:

```bash
# API設定
API_HOST=0.0.0.0
API_PORT=8000

# モデルキャッシュ
HF_HOME=/app/hf_download
TRANSFORMERS_CACHE=/app/hf_download

# GPU設定(GPU版のみ)
CUDA_VISIBLE_DEVICES=0
NVIDIA_VISIBLE_DEVICES=all
```

### ボリューム設定

永続化されるデータ:

- `./outputs` - 生成された動画・画像
- `./temp_queue_images` - キュー用一時画像
- `./loras` - LoRAファイル
- `./hf_download` - Hugging Faceモデルキャッシュ
- `./job_queue.json` - ジョブキュー状態

## 📋 システム要件

### CPU版
- **RAM**: 最小8GB、推奨16GB以上
- **ストレージ**: 最小20GB の空き容量
- **CPU**: マルチコア推奨

### GPU版
- **GPU**: NVIDIA GPU(CUDA 12.1対応)
- **VRAM**: 最小8GB、推奨24GB以上
- **RAM**: 最小16GB、推奨32GB以上
- **ストレージ**: 最小50GB の空き容量
- **NVIDIA Docker**: インストール済み

## 🛠️ トラブルシューティング

### よくある問題

#### 1. GPU版でGPUが認識されない
```bash
# NVIDIA Dockerの確認
docker run --rm --gpus all nvidia/cuda:12.1-base-ubuntu22.04 nvidia-smi

# GPU対応確認
docker-compose -f docker-compose.gpu.yml exec framepack-api-gpu python -c "import torch; print(torch.cuda.is_available())"
```

#### 2. メモリ不足エラー
```bash
# Dockerのメモリ制限を確認・調整
docker stats

# Swapファイルを有効化(Linux)
sudo swapon --show
```

#### 3. モデルダウンロードが遅い/失敗する
```bash
# Hugging Face キャッシュを事前ダウンロード
mkdir -p hf_download
docker run -v $(pwd)/hf_download:/app/hf_download framepack-fastapi-gpu:latest python -c "
from transformers import AutoTokenizer
AutoTokenizer.from_pretrained('hunyuanvideo-community/HunyuanVideo', cache_dir='/app/hf_download')
"
```

#### 4. ポート競合
```bash
# 使用中のポートを確認
netstat -tlnp | grep :8000

# 別のポートを使用
docker-compose up -e API_PORT=8080
```

### ログの確認

```bash
# サービスログ
docker-compose logs framepack-api

# リアルタイムログ
docker-compose logs -f framepack-api

# 特定コンテナのログ
docker logs <container_id>
```

### パフォーマンス監視

```bash
# リソース使用量
docker stats

# GPU使用量(GPU版)
docker-compose -f docker-compose.gpu.yml exec framepack-api-gpu nvidia-smi
```

## 🌐 API アクセス

コンテナ起動後、以下のURLでアクセス可能:

- **API**: http://localhost:8000
- **API ドキュメント**: http://localhost:8000/docs
- **動画生成**: http://localhost:8000/generate
- **画像生成**: http://localhost:8000/api/generate-image

## 🔄 更新とメンテナンス

### イメージの更新
```bash
# 最新コードでリビルド
./docker-build.sh --tag latest

# 古いイメージを削除
docker image prune -f
```

### データのバックアップ
```bash
# 生成データをバックアップ
tar -czf framepack-backup-$(date +%Y%m%d).tar.gz outputs/ temp_queue_images/ loras/ hf_download/
```

### コンテナの停止と削除
```bash
# サービス停止
docker-compose down

# データボリュームも含めて削除
docker-compose down -v

# 完全クリーンアップ
docker system prune -af
```
Loading
Loading