Spaces:
Sleeping
Sleeping
File size: 1,988 Bytes
6a18d72 fa2de66 6a18d72 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
#!/usr/bin/env bash
set -euo pipefail
# ---- config
: "${GITHUB_REPO_URL:=https://github.com/chourmovs/RFPmaster.git}"
: "${GITHUB_TOKEN:=}" # <- set this in HF Space “Repository secrets”
: "${API_MODULE:=rfp_api}" # module exposing `app = FastAPI(...)` in the repo
: "${API_APP_ATTR:=app}" # attribute name
: "${WORKSPACE:=/workspace}"
CLONE_DIR="${WORKSPACE}/RFPmaster"
echo "[startup] WORKSPACE=${WORKSPACE}"
echo "[startup] target clone dir: ${CLONE_DIR}"
# ---- clone private repo at runtime (now env vars are present)
if [ ! -d "${CLONE_DIR}" ]; then
echo "[git] Cloning repo…"
if [ -n "${GITHUB_TOKEN}" ]; then
# inject token in URL (read-only)
TOKENIZED="${GITHUB_REPO_URL/https:\/\//https:\/\/${GITHUB_TOKEN}@}"
git clone --depth=1 "${TOKENIZED}" "${CLONE_DIR}"
else
echo "[warn] GITHUB_TOKEN is empty; trying to clone public repo URL"
git clone --depth=1 "${GITHUB_REPO_URL}" "${CLONE_DIR}"
fi
else
echo "[git] Repo already present, pulling latest…"
git -C "${CLONE_DIR}" fetch --depth=1 origin
git -C "${CLONE_DIR}" reset --hard origin/HEAD || true
fi
# allow git-safe checks if needed
git config --global --add safe.directory "${CLONE_DIR}" || true
# ---- Python deps
echo "[pip] Installing requirements (if any)…"
if [ -f "${CLONE_DIR}/requirements.txt" ]; then
pip install -r "${CLONE_DIR}/requirements.txt"
else
echo "[pip] No requirements.txt found — installing API basics."
pip install fastapi uvicorn requests
fi
# Optional: your API code may import local packages; make sure Python can find them
export PYTHONPATH="${CLONE_DIR}:${PYTHONPATH:-}"
# ---- run uvicorn from inside the repo so relative imports work
cd "${CLONE_DIR}"
# If your repo’s API file expects certain env (e.g., DEEPINFRA_API_KEY), set them in HF Secrets
echo "[uvicorn] launching ${API_MODULE}:${API_APP_ATTR} on 0.0.0.0:7860"
exec uvicorn "${API_MODULE}:${API_APP_ATTR}" --host 0.0.0.0 --port 7860
|