Spaces:
Paused
Paused
| 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 | |