lucid-natsar-dev / deploy-main.yaml
lucid-hf's picture
CI: deploy Docker/PDM Space
ebf66a5 verified
# azure-pipelines.yml
# CI/CD: Deploy entire repo to Hugging Face Space (Docker + PDM)
# Space will build from your Dockerfile and run `src/app.py`.
trigger:
branches:
include:
- main
pool:
vmImage: "ubuntu-latest"
variables:
- group: HF_TOKEN_NATSAR
- name: PYTHON_VERSION
value: "3.10"
- name: HF_SPACE_ID_PROD
value: "lucid-hf/lucid-natsar"
steps:
- checkout: self
lfs: true
- script: |
git lfs install --local
git lfs pull
displayName: "Fetch Git LFS assets"
- task: UsePythonVersion@0
inputs:
versionSpec: "$(PYTHON_VERSION)"
- script: |
python -m pip install --upgrade pip
pip install huggingface_hub==0.25.*
python - <<'PY'
import os
from huggingface_hub import HfApi, upload_folder
token = os.environ["HF_TOKEN"] # provided via Pipeline variable (Secret)
space_id = os.environ["HF_SPACE_ID"] # from variables above
api = HfApi(token=token)
# Ensure Space exists and uses Docker
api.create_repo(
repo_id=space_id,
repo_type="space",
exist_ok=True,
space_sdk="docker"
)
# Upload repo contents (respect ignore patterns to speed builds)
upload_folder(
folder_path=".", # whole repo: Dockerfile, pyproject.toml, src/, models/, etc.
repo_id=space_id,
repo_type="space",
path_in_repo=".", # put at Space root
token=token,
commit_message="CI: deploy Docker/PDM Space",
ignore_patterns=[
".git/*",
"__pycache__/*",
"*.zip", "*.tar", "*.tar.gz",
"*.ipynb", "*.ipynb_checkpoints/*",
"venv/*", ".venv/*",
"dist/*", "build/*",
".mypy_cache/*", ".pytest_cache/*",
"annotated_video/*", "annotated_images/*",
"training_model/*"
]
)
displayName: "Deploy to Hugging Face Space (Docker/PDM)"
env:
HF_TOKEN: $(HF_TOKEN_PROD) # Add this as a secret variable in Pipeline settings
HF_SPACE_ID: $(HF_SPACE_ID_PROD)