adtserapio commited on
Commit
4a878aa
Β·
verified Β·
1 Parent(s): 8dc2118

fix: add debug logging, conditional DB seed

Browse files
Files changed (1) hide show
  1. docker/entrypoint.sh +21 -7
docker/entrypoint.sh CHANGED
@@ -1,7 +1,10 @@
1
  #!/usr/bin/env bash
2
  set -euo pipefail
3
 
 
 
4
  cleanup() {
 
5
  kill "${NGINX_PID:-}" "${ENV_SERVER_PID:-}" "${EHR_PID:-}" 2>/dev/null || true
6
  }
7
  trap cleanup EXIT INT TERM
@@ -11,31 +14,42 @@ export PORT="${PORT:-3000}"
11
  export EHR_BASE_URL="${EHR_BASE_URL:-http://127.0.0.1:${PORT}}"
12
  export EHRGYM_SERVER_URL="${EHRGYM_SERVER_URL:-http://127.0.0.1:8000}"
13
 
14
- # ── Database setup ──
15
- npx prisma generate
16
- npx prisma db push
17
- npx prisma db seed
 
 
 
 
 
 
 
18
 
19
  # ── Start env server (FastAPI + Playwright) on :8000 ──
 
20
  uvicorn env_server.app.main:app --host 127.0.0.1 --port 8000 &
21
  ENV_SERVER_PID=$!
22
 
23
  # ── Start Next.js EHR on internal :3000 ──
 
24
  npm run start --workspace @ehrgym/ehr -- --hostname 127.0.0.1 --port "$PORT" &
25
  EHR_PID=$!
26
 
27
  # ── Wait briefly for services to start ──
28
- sleep 2
 
29
 
30
  # ── Start nginx reverse-proxy on :7860 (the HF Spaces public port) ──
31
  if command -v nginx &>/dev/null && [[ -f /app/docker/nginx.conf ]]; then
32
- echo "Starting nginx reverse proxy on :7860 …"
33
  nginx -c /app/docker/nginx.conf -g 'daemon off;' &
34
  NGINX_PID=$!
 
35
  wait "$NGINX_PID"
36
  else
37
  # Fallback (local dev / docker-compose): no nginx, just wait on EHR
38
- echo "nginx not found β€” services on :${PORT} (EHR) and :8000 (env server)"
39
  wait "$EHR_PID"
40
  fi
41
 
 
1
  #!/usr/bin/env bash
2
  set -euo pipefail
3
 
4
+ echo "[entrypoint] Starting EHRGym …"
5
+
6
  cleanup() {
7
+ echo "[entrypoint] Shutting down …"
8
  kill "${NGINX_PID:-}" "${ENV_SERVER_PID:-}" "${EHR_PID:-}" 2>/dev/null || true
9
  }
10
  trap cleanup EXIT INT TERM
 
14
  export EHR_BASE_URL="${EHR_BASE_URL:-http://127.0.0.1:${PORT}}"
15
  export EHRGYM_SERVER_URL="${EHRGYM_SERVER_URL:-http://127.0.0.1:8000}"
16
 
17
+ # ── Database setup (only if DB file is missing) ──
18
+ DB_PATH="/app/prisma/dev.db"
19
+ if [[ ! -f "$DB_PATH" ]]; then
20
+ echo "[entrypoint] Database not found β€” seeding …"
21
+ npx prisma generate
22
+ npx prisma db push
23
+ npx prisma db seed
24
+ echo "[entrypoint] Database ready."
25
+ else
26
+ echo "[entrypoint] Database exists at $DB_PATH β€” skipping seed."
27
+ fi
28
 
29
  # ── Start env server (FastAPI + Playwright) on :8000 ──
30
+ echo "[entrypoint] Starting env server on :8000 …"
31
  uvicorn env_server.app.main:app --host 127.0.0.1 --port 8000 &
32
  ENV_SERVER_PID=$!
33
 
34
  # ── Start Next.js EHR on internal :3000 ──
35
+ echo "[entrypoint] Starting Next.js EHR on :${PORT} …"
36
  npm run start --workspace @ehrgym/ehr -- --hostname 127.0.0.1 --port "$PORT" &
37
  EHR_PID=$!
38
 
39
  # ── Wait briefly for services to start ──
40
+ sleep 3
41
+ echo "[entrypoint] Services started (env=$ENV_SERVER_PID, ehr=$EHR_PID)."
42
 
43
  # ── Start nginx reverse-proxy on :7860 (the HF Spaces public port) ──
44
  if command -v nginx &>/dev/null && [[ -f /app/docker/nginx.conf ]]; then
45
+ echo "[entrypoint] Starting nginx reverse proxy on :7860 …"
46
  nginx -c /app/docker/nginx.conf -g 'daemon off;' &
47
  NGINX_PID=$!
48
+ echo "[entrypoint] nginx started (pid=$NGINX_PID). EHRGym is ready."
49
  wait "$NGINX_PID"
50
  else
51
  # Fallback (local dev / docker-compose): no nginx, just wait on EHR
52
+ echo "[entrypoint] nginx not found β€” services on :${PORT} (EHR) and :8000 (env server)"
53
  wait "$EHR_PID"
54
  fi
55