chouchouvs commited on
Commit
fa26bd8
·
verified ·
1 Parent(s): 10bf571

Update entrypoint.sh

Browse files
Files changed (1) hide show
  1. entrypoint.sh +49 -33
entrypoint.sh CHANGED
@@ -1,56 +1,72 @@
1
  #!/usr/bin/env bash
2
  set -euo pipefail
3
 
4
- : "${GITHUB_REPO_URL:=https://github.com/chourmovs/RFPmaster.git}"
5
- : "${GITHUB_TOKEN:=}" # à mettre dans Secrets si repo privé
6
- : "${API_MODULE:=rfp_api_app}" # <<< module exposant `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 (privé si token présent)
16
- if [ ! -d "${CLONE_DIR}" ]; then
17
- if [ -n "${GITHUB_TOKEN}" ]; then
18
- echo "[git] cloning with token"
19
- git clone "https://${GITHUB_TOKEN}@${GITHUB_REPO_URL#https://}" "${CLONE_DIR}"
 
 
 
 
 
 
20
  else
21
- echo "[git] cloning public"
22
- git clone "${GITHUB_REPO_URL}" "${CLONE_DIR}"
 
 
 
 
23
  fi
24
- else
25
- echo "[git] repo already present, pulling latest"
26
- git -C "${CLONE_DIR}" pull --rebase || true
27
- fi
28
 
29
- git config --global --add safe.directory "${CLONE_DIR}" || true
 
 
30
 
31
- echo "[pip] Installing requirements (if any)…"
32
- if [ -f "${CLONE_DIR}/requirements.txt" ]; then
33
- pip install -r "${CLONE_DIR}/requirements.txt"
34
- else
35
- pip install fastapi uvicorn requests
36
- fi
37
 
38
- export PYTHONPATH="${CLONE_DIR}:${PYTHONPATH:-}"
39
- cd "${CLONE_DIR}"
40
 
41
- echo "[check] ensuring ${API_MODULE}.py exists at repo root…"
42
- if ! python - << 'PY'
 
43
  import importlib, sys
44
  m = sys.argv[1]
45
  importlib.import_module(m)
46
  print(f"[check] import {m}: OK")
47
  PY
48
- "${API_MODULE}"
49
- then
50
- echo "[ERROR] Cannot import module ${API_MODULE}. Make sure ${API_MODULE}.py is committed at repo root."
51
- ls -la
52
- exit 1
53
- fi
54
 
 
 
 
 
 
 
 
 
 
55
  echo "[uvicorn] launching ${API_MODULE}:${API_APP_ATTR} on 0.0.0.0:7860"
56
  exec uvicorn "${API_MODULE}:${API_APP_ATTR}" --host 0.0.0.0 --port 7860
 
1
  #!/usr/bin/env bash
2
  set -euo pipefail
3
 
4
+ # --- Réglages (surchageables en Variables ou Secrets HF) ---
5
+ : "${GITHUB_REPO_API_URL:=https://github.com/chourmovs/RFPmasterApi.git}"
6
+ : "${GITHUB_REPO_CORE_URL:=https://github.com/chourmovs/RFPmaster.git}"
7
+ : "${GITHUB_TOKEN:=}" # si besoin pour repos privés
8
+ : "${API_MODULE:=rfp_api_app}" # doit exposer "app"
9
  : "${API_APP_ATTR:=app}"
10
+ : "${BRANCH_API:=}" # ex: main ; vide = HEAD par défaut
11
+ : "${BRANCH_CORE:=}" # ex: main
12
  : "${WORKSPACE:=/home/user/workspace}"
13
 
14
+ # --- Dossiers de clone ---
15
+ API_DIR="${WORKSPACE}/RFPmasterApi"
16
+ CORE_DIR="${WORKSPACE}/RFPmaster" # contiendra rfp_parser/
17
 
18
  echo "[startup] WORKSPACE=${WORKSPACE}"
19
+ mkdir -p "${WORKSPACE}"
20
 
21
+ clone_or_update () {
22
+ local repo_url="$1" target="$2" branch="$3"
23
+
24
+ if [ ! -d "${target}/.git" ]; then
25
+ echo "[git] cloning ${repo_url} -> ${target}"
26
+ if [ -n "${GITHUB_TOKEN}" ]; then
27
+ git -c http.extraHeader="Authorization: Basic $(printf 'oauth2:%s' "${GITHUB_TOKEN}" | base64 -w0)" \
28
+ clone --depth=1 ${branch:+-b "${branch}"} "${repo_url}" "${target}"
29
+ else
30
+ git clone --depth=1 ${branch:+-b "${branch}"} "${repo_url}" "${target}"
31
+ fi
32
  else
33
+ echo "[git] updating ${target}"
34
+ git -C "${target}" fetch --depth=1 origin
35
+ if [ -n "${branch}" ]; then
36
+ git -C "${target}" checkout -q "${branch}" || true
37
+ fi
38
+ git -C "${target}" reset --hard ${branch:+origin/"${branch}"} ${branch:+"$(true)"} || git -C "${target}" reset --hard origin/HEAD
39
  fi
40
+ }
 
 
 
41
 
42
+ # --- Clone/update des deux repos ---
43
+ clone_or_update "${GITHUB_REPO_API_URL}" "${API_DIR}" "${BRANCH_API}"
44
+ clone_or_update "${GITHUB_REPO_CORE_URL}" "${CORE_DIR}" "${BRANCH_CORE}"
45
 
46
+ # Safe dir pour Git (HF)
47
+ git config --global --add safe.directory "${API_DIR}" || true
48
+ git config --global --add safe.directory "${CORE_DIR}" || true
 
 
 
49
 
50
+ # --- PYTHONPATH : on expose les deux répertoires ---
51
+ export PYTHONPATH="${API_DIR}:${CORE_DIR}:${PYTHONPATH:-}"
52
 
53
+ # --- Sanity checks imports ---
54
+ echo "[check] importing ${API_MODULE}"
55
+ python - <<'PY' "${API_MODULE}"
56
  import importlib, sys
57
  m = sys.argv[1]
58
  importlib.import_module(m)
59
  print(f"[check] import {m}: OK")
60
  PY
 
 
 
 
 
 
61
 
62
+ echo "[check] importing rfp_parser"
63
+ python - <<'PY'
64
+ import importlib
65
+ importlib.import_module("rfp_parser")
66
+ print("[check] import rfp_parser: OK")
67
+ PY
68
+
69
+ # --- Lancement Uvicorn ---
70
+ cd "${API_DIR}"
71
  echo "[uvicorn] launching ${API_MODULE}:${API_APP_ATTR} on 0.0.0.0:7860"
72
  exec uvicorn "${API_MODULE}:${API_APP_ATTR}" --host 0.0.0.0 --port 7860