Spaces:
Sleeping
Sleeping
ktsn-ud commited on
Commit ·
acff396
1
Parent(s): fabe75b
デプロイのためのGitHub ActionsのワークフローとHF Spaces用のDockerfileを作成
Browse files- .github/workflows/deploy_to_hf_space.yaml +38 -0
- Dockerfile +28 -0
.github/workflows/deploy_to_hf_space.yaml
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
name: Deploy to Hugging Face Space
|
| 2 |
+
|
| 3 |
+
on:
|
| 4 |
+
push:
|
| 5 |
+
branches:
|
| 6 |
+
- main
|
| 7 |
+
workflow_dispatch:
|
| 8 |
+
|
| 9 |
+
jobs:
|
| 10 |
+
deploy-to-space:
|
| 11 |
+
runs-on: ubuntu-latest
|
| 12 |
+
steps:
|
| 13 |
+
- name: Checkout repository
|
| 14 |
+
uses: actions/checkout@v4
|
| 15 |
+
|
| 16 |
+
- name: Push to Hugging Face Space
|
| 17 |
+
env:
|
| 18 |
+
# GitHub Secretsに設定したHF_TOKENを利用
|
| 19 |
+
HF_TOKEN: ${{ secrets.HF_TOKEN }}
|
| 20 |
+
run: |
|
| 21 |
+
# Hugging Face Spaceのリポジトリをクローン
|
| 22 |
+
git clone https://chibafes-dev-admin:$HF_TOKEN@huggingface.co/spaces/chibafes-dev/chibafes-website-api-v2 space-repo
|
| 23 |
+
|
| 24 |
+
# .gitディレクトリとクローン先ディレクトリを除き、全ファイルをコピー
|
| 25 |
+
# これにより、Actions内で生成したデータファイルもSpaceに同期
|
| 26 |
+
rsync -av --delete --exclude='.git/' --exclude='space-repo/' ./ space-repo/
|
| 27 |
+
|
| 28 |
+
# Spaceリポジトリ内で変更をコミットし、プッシュ
|
| 29 |
+
cd space-repo
|
| 30 |
+
git config user.name "GitHub Actions"
|
| 31 |
+
git config user.email "actions@github.com"
|
| 32 |
+
git add .
|
| 33 |
+
# 変更がある場合のみコミットを実行
|
| 34 |
+
if ! git diff-index --quiet HEAD; then
|
| 35 |
+
git commit -m "Update from GitHub Actions"
|
| 36 |
+
fi
|
| 37 |
+
# chibafes-dev-admin の部分はトークンを発行した Hugging Face のユーザー名
|
| 38 |
+
git push https://chibafes-dev-admin:$HF_TOKEN@huggingface.co/spaces/chibafes-dev/chibafes-website-api-v2 main
|
Dockerfile
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
FROM python:3.12.11-slim
|
| 2 |
+
|
| 3 |
+
# 作業ディレクトリの設定
|
| 4 |
+
WORKDIR /app
|
| 5 |
+
|
| 6 |
+
# 依存関係のインストール
|
| 7 |
+
COPY requirements.txt .
|
| 8 |
+
RUN pip install --no-cache-dir --upgrade pip && \
|
| 9 |
+
pip install --no-cache-dir -r requirements.txt
|
| 10 |
+
|
| 11 |
+
# プロジェクトのソースコードをコピー
|
| 12 |
+
COPY . .
|
| 13 |
+
|
| 14 |
+
# データディレクトリを作成し、権限を付与
|
| 15 |
+
RUN mkdir -p data/generated && chmod -R 755 data
|
| 16 |
+
|
| 17 |
+
# データファイルをビルド
|
| 18 |
+
RUN python scripts/build_all.py
|
| 19 |
+
|
| 20 |
+
# Hugging Face Hub のキャッシュディレクトリを設定
|
| 21 |
+
ENV HF_HOME /tmp/hf_cache
|
| 22 |
+
|
| 23 |
+
# アプリケーションがリッスンするポート
|
| 24 |
+
EXPOSE 7860
|
| 25 |
+
|
| 26 |
+
# uvicornでFastAPIアプリケーションを起動
|
| 27 |
+
# Hugging Face Spacesはデフォルトでポート7860を公開します
|
| 28 |
+
CMD ["uvicorn", "api.index:app", "--host", "0.0.0.0", "--port", "7860"]
|