YuraBodnar's picture
ci(deploy): migrate HF Space deployment from Docker to free Gradio SDK
e45d733
Raw History Blame Contribute Delete
2.53 kB
# Deploys by pushing this repo directly to the Hugging Face Space's git remote; the Space
# rebuilds itself from the pushed README.md front matter + app.py. There is no container
# registry step and no Terraform.
#
# SDK: "gradio", not "docker" (see README.md's YAML front matter and app.py). Docker Spaces
# need a verified billing method on this Hugging Face account; the Gradio SDK does not, and
# app.py is a thin adapter that runs the existing FastAPI app under it unchanged. Local dev
# and CI (ci.yml) still use the Dockerfile / docker-compose; this workflow is the only place
# that depends on the Space's own SDK choice.
#
# Required repo secrets (set manually via GitHub Settings -> Secrets -> Actions,
# no automation creates these):
# HF_TOKEN — a Hugging Face write token (hf.co/settings/tokens)
# HF_SPACE — the target Space, e.g. "username/chokepoint-ai"
name: deploy
on:
push:
branches: [main]
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.12"
- name: Install Space runtime dependencies (smoke check)
run: pip install -r requirements.txt
- name: Import the app exactly as the Space will run it
run: |
python -c "
from fastapi.testclient import TestClient
from app import app
resp = TestClient(app).get('/healthz')
assert resp.status_code == 200, resp.text
print('app.py imports and /healthz responds:', resp.json())
"
- name: Push to Hugging Face Space
env:
HF_TOKEN: ${{ secrets.HF_TOKEN }}
HF_SPACE: ${{ secrets.HF_SPACE }}
run: |
git remote add space "https://user:${HF_TOKEN}@huggingface.co/spaces/${HF_SPACE}"
git push space HEAD:main --force
- name: Smoke test the deployed Space
env:
HF_SPACE: ${{ secrets.HF_SPACE }}
run: |
SPACE_SLUG=$(echo "$HF_SPACE" | tr '/' '-' | tr '[:upper:]' '[:lower:]')
URL="https://${SPACE_SLUG}.hf.space/healthz"
for i in $(seq 1 12); do
if curl -sf "$URL" | grep -q '"ok"'; then
echo "Space is healthy: $URL"
exit 0
fi
echo "Waiting for Space to come up... ($i/12)"
sleep 5
done
echo "Space did not become healthy within 60s: $URL"
exit 1