Spaces:
Sleeping
Sleeping
Update entrypoint.sh
Browse files- entrypoint.sh +9 -18
entrypoint.sh
CHANGED
|
@@ -1,26 +1,25 @@
|
|
| 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:=}"
|
| 7 |
-
: "${API_MODULE:=rfp_api}"
|
| 8 |
-
: "${API_APP_ATTR:=app}"
|
| 9 |
-
: "${WORKSPACE:=/workspace}"
|
|
|
|
| 10 |
CLONE_DIR="${WORKSPACE}/RFPmaster"
|
| 11 |
|
| 12 |
echo "[startup] WORKSPACE=${WORKSPACE}"
|
| 13 |
echo "[startup] target clone dir: ${CLONE_DIR}"
|
| 14 |
|
| 15 |
-
#
|
| 16 |
if [ ! -d "${CLONE_DIR}" ]; then
|
| 17 |
echo "[git] Cloning repo…"
|
| 18 |
if [ -n "${GITHUB_TOKEN}" ]; then
|
| 19 |
-
#
|
| 20 |
-
|
| 21 |
-
|
| 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
|
|
@@ -29,25 +28,17 @@ else
|
|
| 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 |
-
|
|
|
|
| 1 |
#!/usr/bin/env bash
|
| 2 |
set -euo pipefail
|
| 3 |
|
|
|
|
| 4 |
: "${GITHUB_REPO_URL:=https://github.com/chourmovs/RFPmaster.git}"
|
| 5 |
+
: "${GITHUB_TOKEN:=}" # set in Space “Repository secrets”
|
| 6 |
+
: "${API_MODULE:=rfp_api}" # module exposing `app = FastAPI(...)`
|
| 7 |
+
: "${API_APP_ATTR:=app}"
|
| 8 |
+
: "${WORKSPACE:=/home/user/workspace}"
|
| 9 |
+
|
| 10 |
CLONE_DIR="${WORKSPACE}/RFPmaster"
|
| 11 |
|
| 12 |
echo "[startup] WORKSPACE=${WORKSPACE}"
|
| 13 |
echo "[startup] target clone dir: ${CLONE_DIR}"
|
| 14 |
|
| 15 |
+
# clone repo (private if token provided)
|
| 16 |
if [ ! -d "${CLONE_DIR}" ]; then
|
| 17 |
echo "[git] Cloning repo…"
|
| 18 |
if [ -n "${GITHUB_TOKEN}" ]; then
|
| 19 |
+
# Safer: send token via header (avoids putting it in the URL & process list)
|
| 20 |
+
git -c http.extraHeader="Authorization: Basic $(printf 'oauth2:%s' "${GITHUB_TOKEN}" | base64 -w0)" \
|
| 21 |
+
clone --depth=1 "${GITHUB_REPO_URL}" "${CLONE_DIR}"
|
| 22 |
else
|
|
|
|
| 23 |
git clone --depth=1 "${GITHUB_REPO_URL}" "${CLONE_DIR}"
|
| 24 |
fi
|
| 25 |
else
|
|
|
|
| 28 |
git -C "${CLONE_DIR}" reset --hard origin/HEAD || true
|
| 29 |
fi
|
| 30 |
|
|
|
|
| 31 |
git config --global --add safe.directory "${CLONE_DIR}" || true
|
| 32 |
|
|
|
|
| 33 |
echo "[pip] Installing requirements (if any)…"
|
| 34 |
if [ -f "${CLONE_DIR}/requirements.txt" ]; then
|
| 35 |
pip install -r "${CLONE_DIR}/requirements.txt"
|
| 36 |
else
|
|
|
|
| 37 |
pip install fastapi uvicorn requests
|
| 38 |
fi
|
| 39 |
|
|
|
|
| 40 |
export PYTHONPATH="${CLONE_DIR}:${PYTHONPATH:-}"
|
|
|
|
|
|
|
| 41 |
cd "${CLONE_DIR}"
|
| 42 |
|
|
|
|
| 43 |
echo "[uvicorn] launching ${API_MODULE}:${API_APP_ATTR} on 0.0.0.0:7860"
|
| 44 |
exec uvicorn "${API_MODULE}:${API_APP_ATTR}" --host 0.0.0.0 --port 7860
|
|
|