#!/usr/bin/env bash # One-shot deploy of OpenSOC to a Hugging Face Space. # Pre-conditions: # - `huggingface-cli login` has been run (browser PAT login). # - HF_USER env var is set to your HF username, e.g. `export HF_USER=foo`. # Idempotent: safe to re-run after committing fresh artifacts. set -euo pipefail : "${HF_USER:?Set HF_USER to your Hugging Face username, e.g. export HF_USER=foo}" SPACE_NAME="opensoc-env" SPACE_URL="https://huggingface.co/spaces/${HF_USER}/${SPACE_NAME}" echo "Deploying to ${SPACE_URL}" # Create the Space if it doesn't exist (no-op if it does). huggingface-cli repo create "${SPACE_NAME}" --type space --space-sdk docker -y \ || echo "(space already exists or create errored — continuing)" # Add the Space as a git remote (idempotent). if ! git remote get-url space >/dev/null 2>&1; then git remote add space "${SPACE_URL}" else git remote set-url space "${SPACE_URL}" fi # Stage SPACE_README.md as the Space's README so HF picks up `sdk: docker`. TMP_BRANCH="space-deploy-$(date +%s)" git checkout -b "${TMP_BRANCH}" cat SPACE_README.md > README.md.space mv README.md README.md.bak mv README.md.space README.md git add README.md git commit -m "Space metadata header (auto)" git push -u space "${TMP_BRANCH}:main" echo "" echo "Pushed to ${SPACE_URL}. Restoring local README ..." git reset --hard HEAD~1 mv README.md.bak README.md 2>/dev/null || true git checkout main git branch -D "${TMP_BRANCH}" echo "" echo "Done. Open ${SPACE_URL%/spaces*}/spaces/${HF_USER}/${SPACE_NAME} to watch the build," echo "then visit:" echo " ${SPACE_URL%/spaces*}/${HF_USER}-${SPACE_NAME}.hf.space/health" echo " ${SPACE_URL%/spaces*}/${HF_USER}-${SPACE_NAME}.hf.space/demo"