File size: 1,590 Bytes
e40dce0
 
 
 
 
 
 
44962ca
 
fac8dfc
 
 
44962ca
 
 
 
 
 
 
 
 
e40dce0
 
 
 
 
 
 
 
 
fe45848
e40dce0
 
44962ca
 
 
43be4c0
 
bad3400
fe45848
 
 
 
 
 
 
 
 
 
a127b8d
 
 
 
 
 
c6b0120
 
04721a8
c6b0120
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/usr/bin/env bash
set -euo pipefail

log() {
  echo "[entrypoint] $*"
}

RAW_DB_URL="${OTREE_DATABASE_URL:-${DATABASE_URL:-sqlite:////tmp/otree.sqlite3}}"

echo "[DEBUG] OTREE_DATABASE_URL='${OTREE_DATABASE_URL-}'"
echo "[DEBUG] DATABASE_URL='${DATABASE_URL-}'"

# Accept accidental "psql 'url'" copy-pastes by extracting the quoted URL.
if [[ "$RAW_DB_URL" == psql* ]]; then
  CLEANED=$(printf '%s' "$RAW_DB_URL" | sed -n "s/.*'\(postgres[^']*\)'.*/\1/p")
  if [[ -n "$CLEANED" ]]; then
    RAW_DB_URL="$CLEANED"
  fi
fi

DB_URL="$RAW_DB_URL"
DB_PATH=""

if [[ "$DB_URL" == sqlite:////* ]]; then
  DB_PATH="/${DB_URL#sqlite:////}"
elif [[ "$DB_URL" == sqlite:///* ]]; then
  DB_PATH="${DB_URL#sqlite:///}"
fi

if [[ -n "$DB_PATH" ]]; then
  log "SQLite compatibility path requested: $DB_PATH"
fi

SCHEME=$(printf '%s' "$DB_URL" | cut -d: -f1)
log "Database scheme detected: ${SCHEME:-unknown}"

export DATABASE_URL="$DB_URL"

PORT_VALUE="${PORT:-7860}"
log "Preparing runtime workspace"
RUNTIME_DIR=${OTREE_RUNTIME_DIR:-/tmp/otree-app}
rm -rf "$RUNTIME_DIR"
mkdir -p "$RUNTIME_DIR"
cp -a /app/. "$RUNTIME_DIR"/

cd "$RUNTIME_DIR"
log "Working directory: $(pwd)"
touch db.sqlite3 || true

# Ensure uvicorn trusts the Hugging Face proxy so X-Forwarded-Proto gets respected.
if [[ -z "${FORWARDED_ALLOW_IPS:-}" ]]; then
  export FORWARDED_ALLOW_IPS="*"
  log "FORWARDED_ALLOW_IPS not provided; defaulting to '*'"
fi

log "Starting oTree services on 0.0.0.0:${PORT_VALUE}"
export PORT="$PORT_VALUE"
python scripts/check_db_connectivity.py || true
exec python scripts/run_serve_and_worker.py