-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathentrypoint.sh
More file actions
executable file
·56 lines (49 loc) · 1.65 KB
/
entrypoint.sh
File metadata and controls
executable file
·56 lines (49 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
45
46
47
48
49
50
51
52
53
54
55
56
#!/bin/bash
set -e
echo "🐛 Starting BugStore..."
# Wait for database to be ready (MySQL/MariaDB)
if echo "$DATABASE_URL" | grep -q "mysql"; then
echo "⏳ Waiting for MySQL..."
for i in $(seq 1 30); do
python3 -c "
from sqlalchemy import create_engine, text
import os
e = create_engine(os.environ['DATABASE_URL'])
with e.connect() as c:
c.execute(text('SELECT 1'))
" 2>/dev/null && break
echo " Attempt $i/30 — retrying in 2s..."
sleep 2
done
fi
# Initialize database tables
echo "📦 Initializing database..."
python3 init_db.py
# Seed database if AUTO_SEED is enabled and tables are empty
if [ "${BUGSTORE_AUTO_SEED:-true}" = "true" ]; then
ROWS=$(python3 -c "
from src.database import SessionLocal
from src.models import User
db = SessionLocal()
print(db.query(User).count())
db.close()
" 2>/dev/null || echo "0")
if [ "$ROWS" = "0" ]; then
echo "🌱 Seeding database with test data..."
python3 seed.py
else
echo "✓ Database already seeded ($ROWS users found)"
fi
fi
WORKERS=${BUGSTORE_WORKERS:-4}
TIMEOUT=${BUGSTORE_TIMEOUT:-30}
if [ "${BUGSTORE_WAF_ENABLED:-false}" = "true" ]; then
echo "🛡️ WAF + Rate Limit enabled — starting Caddy with Coraza WAF..."
CADDY_CONFIG="/app/Caddyfile.waf"
else
echo "🔓 WAF disabled — starting Caddy as HTTPS reverse proxy only..."
CADDY_CONFIG="/app/Caddyfile"
fi
echo "🌐 Caddy config: $CADDY_CONFIG (${WORKERS} workers, ${TIMEOUT}s timeout)"
caddy start --config "$CADDY_CONFIG" --adapter caddyfile
cd /app && python3 -m uvicorn src.main:app --host 0.0.0.0 --port 8000 --workers "$WORKERS" --timeout-keep-alive "$TIMEOUT"