raqim / deploy-hf.sh
RAQIM Deploy
Deploy RAQIM 2026-05-02 19:06
0e14acb
#!/usr/bin/env bash
# ============================================================
# RAQIM — Hugging Face Spaces Deployment Script
# ============================================================
set -euo pipefail
HF_TOKEN="${HF_TOKEN:?Set HF_TOKEN as a Replit secret}"
HF_USERNAME="${HF_USERNAME:?Set HF_USERNAME as a Replit secret}"
SPACE_NAME="raqim"
SPACE_ID="${HF_USERNAME}/${SPACE_NAME}"
SPACE_URL="https://huggingface.co/spaces/${SPACE_ID}"
GIT_URL="https://${HF_USERNAME}:${HF_TOKEN}@huggingface.co/spaces/${SPACE_ID}"
SRC="/home/runner/workspace"
echo "=================================================="
echo " Deploying RAQIM → HF Space: ${SPACE_ID}"
echo "=================================================="
# ── 1. Create the Space (idempotent) ───────────────────────────────────────
echo ""
echo "▶ Creating Space (if it doesn't exist)..."
STATUS=$(curl -s -o /dev/null -w "%{http_code}" \
-X POST "https://huggingface.co/api/repos/create" \
-H "Authorization: Bearer ${HF_TOKEN}" \
-H "Content-Type: application/json" \
-d "{\"type\":\"space\",\"name\":\"${SPACE_NAME}\",\"sdk\":\"docker\",\"private\":false}")
if [ "$STATUS" = "200" ] || [ "$STATUS" = "201" ]; then echo " ✓ Space created."
elif [ "$STATUS" = "409" ]; then echo " ✓ Space already exists — updating."
else echo " ✗ Unexpected status ${STATUS}"; exit 1
fi
# ── 2. Clone the Space repo ────────────────────────────────────────────────
echo ""
echo "▶ Cloning Space repo..."
TMP_DIR=$(mktemp -d)
trap 'rm -rf "$TMP_DIR"' EXIT
SPACE_DIR="$TMP_DIR/space"
git clone --depth=1 "$GIT_URL" "$SPACE_DIR" 2>/dev/null || {
mkdir -p "$SPACE_DIR"
cd "$SPACE_DIR" && git init && git remote add origin "$GIT_URL" && cd -
}
# ── 3. Copy source files with tar (no rsync, no git-archive) ───────────────
echo ""
echo "▶ Copying files..."
# Remove everything except .git in the space dir
find "$SPACE_DIR" -maxdepth 1 ! -name '.git' ! -path "$SPACE_DIR" -exec rm -rf {} + 2>/dev/null || true
# Copy via tar with exclusions
(cd "$SRC" && tar -cf - \
--exclude='./.git' \
--exclude='./node_modules' \
--exclude='./**/node_modules' \
--exclude='./**/dist' \
--exclude='./artifacts/api-server/uploads' \
--exclude='./artifacts/api-server/raqim.db' \
--exclude='./artifacts/api-server/raqim.db-wal' \
--exclude='./artifacts/api-server/raqim.db-shm' \
--exclude='./**/*.db' \
--exclude='./**/*.db-wal' \
--exclude='./**/*.db-shm' \
--exclude='./.local' \
--exclude='./attached_assets' \
--exclude='./*.log' \
. ) | tar -xf - -C "$SPACE_DIR"
echo " ✓ Files copied."
# ── 4. Commit and push ──────────────────────────────────────────────────────
echo ""
echo "▶ Pushing to HF Spaces..."
cd "$SPACE_DIR"
git config user.email "deploy@raqim.app"
git config user.name "RAQIM Deploy"
git add -A
git diff --cached --quiet && echo " (nothing new to commit)" || \
git commit -m "Deploy RAQIM $(date '+%Y-%m-%d %H:%M')"
git push origin HEAD:main --force
echo ""
echo "=================================================="
echo " ✓ Deployed!"
echo " Space URL : ${SPACE_URL}"
echo " Build logs: ${SPACE_URL}/logs"
echo ""
echo " Set these secrets in ${SPACE_URL}/settings :"
echo " • JWT_SECRET (generated: 83ac8c77aad0c1e797c18dde23607675be29e4f9ab546a12cfd7c88001babac9)"
echo " • SESSION_SECRET (already in Replit secrets)"
echo " • HF_TOKEN (your write token — for DB backup)"
echo " • HF_USERNAME (abedelbahnasy55)"
echo "=================================================="