chouchouvs commited on
Commit
6a18d72
·
verified ·
1 Parent(s): 7a796bc

Update entrypoint.sh

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