-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdocker-entrypoint.sh
More file actions
executable file
·44 lines (38 loc) · 1.65 KB
/
docker-entrypoint.sh
File metadata and controls
executable file
·44 lines (38 loc) · 1.65 KB
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
#!/bin/bash
set -e
echo "=== API-Watch Container Starting ==="
echo "Date: $(date -u +%Y-%m-%dT%H:%M:%SZ)"
echo "Python: $(python --version)"
echo "Working dir: $(pwd)"
# ── Run database migrations ─────────────────────────────────
if [ -n "$DATABASE_URL" ] && [ -d "alembic" ]; then
# Only run Alembic for PostgreSQL (production DB with persistent state)
echo "Running database migrations (PostgreSQL)..."
python -m alembic upgrade head 2>&1 || {
echo "⚠ Migrations failed — attempting table creation fallback..."
python -c "
import asyncio
from src.database import init_db
asyncio.run(init_db())
print('Tables created via init_db()')
" 2>&1 || echo "⚠ Table creation also failed — app may still work if DB is already set up"
}
echo "Migrations complete."
else
echo "No DATABASE_URL set — using SQLite. Tables will be created by app lifespan."
fi
# ── Create writable directories ──────────────────────────────
mkdir -p /app/data /app/logs 2>/dev/null || true
# ── Start gunicorn ───────────────────────────────────────────
PORT=${PORT:-8000}
WORKERS=${GUNICORN_WORKERS:-1}
TIMEOUT=${GUNICORN_TIMEOUT:-120}
echo "Starting gunicorn on port $PORT with $WORKERS worker(s)..."
exec gunicorn src.api_server:app \
--worker-class uvicorn.workers.UvicornWorker \
--bind "0.0.0.0:$PORT" \
--workers "$WORKERS" \
--timeout "$TIMEOUT" \
--access-logfile - \
--error-logfile - \
--log-level info