Spaces:
Sleeping
Sleeping
| 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 | |