CoolFace
Apppublic

yashprmr/MeridianFinancial

sourceHugging Facemitupdated 4mo agoView on Hugging Face
0likes
deploy_backend.sh90 linesDownload Raw Back to scripts
1#!/usr/bin/env bash2# scripts/deploy_backend.sh3# --------------------------4# Deploy the Meridian Financial FastAPI backend to HuggingFace Spaces.5#6# ACTIVE DEPLOYMENT TARGET: HuggingFace Spaces7# FUTURE/PLANNED TARGET:    AWS EC2 (see docs/deployment.md#future-aws-architecture)8#9# Usage:10#   HF_TOKEN=hf_xxx HF_API_SPACE=your-username/meridian-api bash scripts/deploy_backend.sh11#12# Environment variables:13#   HF_TOKEN        — HuggingFace write token (required)14#   HF_API_SPACE    — HF Space repo ID, e.g. bottyash/meridian-api15#   COMMIT_MSG      — Optional custom commit message16 17set -euo pipefail18 19# ---------------------------------------------------------------------------20# Config21# ---------------------------------------------------------------------------22HF_TOKEN="${HF_TOKEN:-}"23HF_API_SPACE="${HF_API_SPACE:-bottyash/meridian-api}"24COMMIT_MSG="${COMMIT_MSG:-Deploy backend from local}"25REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"26 27# ---------------------------------------------------------------------------28# Validation29# ---------------------------------------------------------------------------30if [[ -z "$HF_TOKEN" ]]; then31  echo "ERROR: HF_TOKEN environment variable is required."32  echo "  export HF_TOKEN=hf_your_token_here"33  exit 134fi35 36command -v python3 >/dev/null 2>&1 || { echo "ERROR: python3 not found"; exit 1; }37python3 -c "import huggingface_hub" 2>/dev/null || pip install huggingface_hub -q38 39# ---------------------------------------------------------------------------40# Run tests before deploy41# ---------------------------------------------------------------------------42echo "Running test suite before deploy..."43cd "$REPO_ROOT"44python3 -m pytest tests/ -q --tb=short45echo "Tests passed."46 47# ---------------------------------------------------------------------------48# Deploy to HF Spaces49# ---------------------------------------------------------------------------50echo ""51echo "Deploying backend to HuggingFace Spaces: $HF_API_SPACE"52 53python3 - << PYEOF54import os55from huggingface_hub import HfApi56 57api = HfApi(token=os.environ["HF_TOKEN"])58space_id = os.environ["HF_API_SPACE"]59commit_msg = os.environ.get("COMMIT_MSG", "Deploy backend")60 61# Upload src/ and config/62for folder, path_in_repo in [("src", "src"), ("config", "config")]:63    api.upload_folder(64        folder_path=folder,65        repo_id=space_id,66        repo_type="space",67        path_in_repo=path_in_repo,68        ignore_patterns=["*.pyc", "__pycache__"],69        commit_message=commit_msg,70    )71 72# Upload runtime files73for file, path_in_repo in [74    ("Dockerfile", "Dockerfile"),75    ("requirements.txt", "requirements.txt"),76]:77    api.upload_file(78        path_or_fileobj=file,79        path_in_repo=path_in_repo,80        repo_id=space_id,81        repo_type="space",82        commit_message=commit_msg,83    )84 85print(f"Backend deployed: https://huggingface.co/spaces/{space_id}")86PYEOF87 88echo ""89echo "Done. Backend deployed to: https://huggingface.co/spaces/$HF_API_SPACE"90