Spaces:
Sleeping
Sleeping
File size: 1,551 Bytes
6a18d72 653d71e 6a18d72 653d71e 6a18d72 653d71e 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 |
#!/usr/bin/env bash
set -euo pipefail
: "${GITHUB_REPO_URL:=https://github.com/chourmovs/RFPmaster.git}"
: "${GITHUB_TOKEN:=}" # set in Space “Repository secrets”
: "${API_MODULE:=rfp_api}" # module exposing `app = FastAPI(...)`
: "${API_APP_ATTR:=app}"
: "${WORKSPACE:=/home/user/workspace}"
CLONE_DIR="${WORKSPACE}/RFPmaster"
echo "[startup] WORKSPACE=${WORKSPACE}"
echo "[startup] target clone dir: ${CLONE_DIR}"
# clone repo (private if token provided)
if [ ! -d "${CLONE_DIR}" ]; then
echo "[git] Cloning repo…"
if [ -n "${GITHUB_TOKEN}" ]; then
# Safer: send token via header (avoids putting it in the URL & process list)
git -c http.extraHeader="Authorization: Basic $(printf 'oauth2:%s' "${GITHUB_TOKEN}" | base64 -w0)" \
clone --depth=1 "${GITHUB_REPO_URL}" "${CLONE_DIR}"
else
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
git config --global --add safe.directory "${CLONE_DIR}" || true
echo "[pip] Installing requirements (if any)…"
if [ -f "${CLONE_DIR}/requirements.txt" ]; then
pip install -r "${CLONE_DIR}/requirements.txt"
else
pip install fastapi uvicorn requests
fi
export PYTHONPATH="${CLONE_DIR}:${PYTHONPATH:-}"
cd "${CLONE_DIR}"
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
|