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
51 changes: 51 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# Git files
.git/
.gitignore

# Python virtual environment
venv/
.venv/

# Python cache files
__pycache__/
*.pyc
*.pyo
*.pyd

# Distribution / packaging
.eggs/
*.egg-info/
dist/
build/
wheels/
*.tar.gz
*.whl

# Test files
tests/

# Temporary files
temp_queue_images/
*.tmp
*.bak
*.swp

# Documentation / Planning files
*.md
LICENSE

# Archives
*.7z

# OS generated files
.DS_Store
Thumbs.db

# IDE / Editor specific files
.vscode/
.idea/
*.sublime-project
*.sublime-workspace

# Logs
*.log
1 change: 1 addition & 0 deletions .python-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.10
42 changes: 42 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
FROM nvidia/cuda:12.6.0-cudnn8-devel-ubuntu22.04

ENV DEBIAN_FRONTEND=noninteractive

RUN apt-get update && \
apt-get install -y --no-install-recommends \
python3.10 \
python3-pip \
python3.10-venv \
ffmpeg \
libsm6 \
libxext6 \
git \
&& rm -rf /var/lib/apt/lists/*

RUN ln -s /usr/bin/python3.10 /usr/local/bin/python && \
ln -s /usr/bin/pip3 /usr/local/bin/pip

WORKDIR /app

RUN pip install --no-cache-dir --upgrade pip

COPY requirements.txt requirements.txt

RUN pip install --no-cache-dir torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu126

# 残りの依存関係のインストール (torch と torchvision を除外)
# requirements.txt に torch/torchvision がバージョン指定なしで含まれているため、grepで除外
RUN grep -vE '^torch$|^torchvision$' requirements.txt | pip install --no-cache-dir -r /dev/stdin

# 5. Hugging Face Hub 認証 (ビルド時引数として定義)
# ビルド時に --build-arg HUGGING_FACE_HUB_TOKEN=your_token で渡す
# または実行時に環境変数として渡す場合はこの ARG/ENV は不要
ARG HUGGING_FACE_HUB_TOKEN
ENV HUGGING_FACE_HUB_TOKEN=${HUGGING_FACE_HUB_TOKEN}

COPY .dockerignore .dockerignore
COPY . .

EXPOSE 8080

CMD ["uvicorn", "api.api:app", "--host", "0.0.0.0", "--port", "8080"]
72 changes: 72 additions & 0 deletions plan/docker_plan.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# FramePack-FastAPI Dockerfile 作成計画

## 概要

このドキュメントは、`FramePack-FastAPI` プロジェクトの Docker イメージを構築するための Dockerfile 作成計画を記述します。GPU (CUDA 12.6) 利用、Hugging Face Hub へのアクセス、FastAPI サーバーの実行を考慮します。

## 計画詳細

1. **ベースイメージの選定:**
* Python 3.10 と CUDA 12.6 に対応する公式イメージを選択します。
* 候補: `nvidia/cuda:12.6.0-cudnn8-devel-ubuntu22.04` (または同等の機能を持つイメージ)
* 理由: Python バージョン、CUDA 要件を満たし、`apt-get` によるシステムライブラリのインストールが可能です。

2. **システム依存ライブラリのインストール:**
* `opencv-python-contrib`, `av`, モデルダウンロード (`git`) に必要なライブラリをインストールします。
* コマンド: `apt-get update && apt-get install -y --no-install-recommends ffmpeg libsm6 libxext6 git && rm -rf /var/lib/apt/lists/*`
* 理由: アプリケーションの実行とモデル取得に必要な依存関係を解決します。`--no-install-recommends` と `rm -rf /var/lib/apt/lists/*` でイメージサイズを削減します。

3. **Python 環境のセットアップ:**
* `pip` を最新バージョンにアップグレードします。
* `requirements.txt` をコンテナにコピーします。
* **GPU 対応 PyTorch のインストール:** `README.md` に記載の CUDA 12.6 対応コマンドを実行します。
* コマンド: `pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu126`
* **残りの依存関係のインストール:** `requirements.txt` から `torch` と `torchvision` を除外してインストールします。
* `requirements.txt` を編集するか、`grep -vE '^torch|^torchvision'` などでフィルタリングしてインストールします。
* コマンド例 (フィルタリング): `grep -vE '^torch|^torchvision' requirements.txt | pip install --no-cache-dir -r /dev/stdin`
* 理由: `requirements.txt` に記載の CPU 版 PyTorch を避け、指定された GPU 版をインストールします。`--no-cache-dir` でイメージサイズを削減します。

4. **アプリケーションコードのコピー:**
* `.dockerignore` ファイルを作成し、不要なファイルやディレクトリ (`.git`, `venv/`, `__pycache__`, `*.7z`, `temp_queue_images/`, `tests/`, `*.md` など) を指定して、ビルドコンテキストとイメージサイズを削減します。
* プロジェクト全体 (`.`) をコンテナ内の作業ディレクトリ `/app` にコピーします。
* コマンド:

```dockerfile
COPY .dockerignore .dockerignore
COPY . /app
```

5. **Hugging Face Hub 認証:**
* 認証トークンは Dockerfile に含めず、コンテナ実行時に環境変数 `HUGGING_FACE_HUB_TOKEN` として渡すことを想定します。
* 理由: セキュリティのベストプラクティスに従います。Hugging Face ライブラリは通常、この環境変数を自動的に検出します。

6. **ポートの公開:**
* FastAPI アプリケーションが使用するポート `8080` を公開します。
* コマンド: `EXPOSE 8080`

7. **作業ディレクトリの設定:**
* コンテナ内の作業ディレクトリを `/app` に設定します。
* コマンド: `WORKDIR /app`

8. **起動コマンドの設定:**
* コンテナ起動時に FastAPI サーバーを実行するコマンドを設定します。
* コマンド: `CMD ["uvicorn", "api.api:app", "--host", "0.0.0.0", "--port", "8080"]`

## 計画の視覚化 (Mermaid)

```mermaid
graph TD
A[ベースイメージ選定 (Python 3.10 + CUDA 12.6)] --> B(システム依存ライブラリ インストール (ffmpeg, libsm6, libxext6, git));
B --> C(Python 環境セットアップ (pip upgrade));
C --> D(GPU対応PyTorchインストール (cu126));
D --> E(requirements.txt インストール (torch除く, --no-cache-dir));
E --> F(アプリケーションコード コピー (`.` -> `/app`, .dockerignore));
F --> G(Hugging Face Hub 認証設定 (環境変数想定));
G --> H(ポート公開: 8080);
H --> I(作業ディレクトリ設定 (/app));
I --> J(起動コマンド設定 (uvicorn));
```

## 次のステップ

この計画に基づき、Code モードで `Dockerfile` と `.dockerignore` ファイルを作成します。
99 changes: 99 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
[project]
name = "framepack-fastapi"
version = "0.1.0"
description = "Add your description here"
readme = "README.md"
requires-python = ">=3.10"
dependencies = [
"accelerate==1.6.0",
"aiofiles==23.2.1",
"annotated-types==0.7.0",
"anyio==4.9.0",
"av==12.1.0",
"certifi==2025.4.26",
"charset-normalizer==3.4.2",
"click==8.1.8",
"colorama==0.4.6",
"diffusers==0.33.1",
"einops==0.8.1",
"exceptiongroup==1.2.2",
"fastapi==0.115.12",
"ffmpy==0.5.0",
"filelock==3.13.1",
# "flash-attn"
"fsspec==2024.6.1",
"gradio==5.23.0",
"gradio-client==1.8.0",
"groovy==0.1.2",
"h11==0.16.0",
"httpcore==1.0.9",
"httptools==0.6.4",
"httpx==0.28.1",
"huggingface-hub==0.30.2",
"idna==3.10",
"importlib-metadata==8.7.0",
"iniconfig==2.1.0",
"jinja2==3.1.4",
"markdown-it-py==3.0.0",
"markupsafe==2.1.5",
"mdurl==0.1.2",
"mpmath==1.3.0",
"networkx==3.3",
"numpy==1.26.2",
"opencv-contrib-python==4.11.0.86",
"orjson==3.10.18",
"packaging==25.0",
"pandas==2.2.3",
"peft==0.15.2",
"pillow==11.1.0",
"pluggy==1.5.0",
"psutil==7.0.0",
"pydantic==2.11.4",
"pydantic-core==2.33.2",
"pydub==0.25.1",
"pygments==2.19.1",
"pytest==8.3.5",
"pytest-mock==3.14.0",
"python-dateutil==2.9.0.post0",
"python-dotenv==1.1.0",
"python-multipart==0.0.20",
"pytz==2025.2",
"pyyaml==6.0.2",
"regex==2024.11.6",
"requests==2.31.0",
"rich==14.0.0",
"ruff==0.11.8",
"safehttpx==0.1.6",
"safetensors==0.5.3",
# "sageattention"
"scipy==1.12.0",
"semantic-version==2.10.0",
"sentencepiece==0.2.0",
"shellingham==1.5.4",
"six==1.17.0",
"sniffio==1.3.1",
"starlette==0.46.2",
"sympy==1.13.3",
"tokenizers==0.20.3",
"tomli==2.2.1",
"tomlkit==0.13.2",
"torch==2.7.0+cu126",
"torchaudio==2.7.0+cu126",
"torchsde==0.2.6",
"torchvision==0.22.0+cu126",
"tqdm==4.67.1",
"trampoline==0.1.2",
"transformers==4.46.2",
# "triton"
"typer==0.15.3",
"typing-extensions==4.12.2",
"typing-inspection==0.4.0",
"tzdata==2025.2",
"urllib3==2.4.0",
"uvicorn==0.34.2",
"watchdog==6.0.0",
"watchfiles==1.0.5",
"websockets==15.0.1",
"xformers==0.0.30",
"zipp==3.21.0"
]