-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdocker-entrypoint.sh
More file actions
69 lines (57 loc) · 1.98 KB
/
docker-entrypoint.sh
File metadata and controls
69 lines (57 loc) · 1.98 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
57
58
59
60
61
62
63
64
65
66
67
68
69
#!/bin/sh
set -e
# ============================================
# EBIC Production Entrypoint
# Handles DB readiness, migrations, and seeding
# ============================================
# --- DB Readiness Wait Loop ---
# Waits for MySQL to accept connections before proceeding.
# Required because docker-compose `depends_on` only waits for container start,
# not for the service inside to be ready.
wait_for_db() {
if [ -z "$DATABASE_URL" ]; then
echo "⚠️ DATABASE_URL not set, skipping database readiness check."
return 0
fi
# Extract host and port from DATABASE_URL
# Supports: mysql://user:pass@host:port/dbname
DB_HOST=$(echo "$DATABASE_URL" | sed -n 's|.*@\([^:/]*\).*|\1|p')
DB_PORT=$(echo "$DATABASE_URL" | sed -n 's|.*:\([0-9]*\)/.*|\1|p')
DB_PORT=${DB_PORT:-3306}
echo "⏳ Waiting for database at ${DB_HOST}:${DB_PORT}..."
MAX_RETRIES=30
RETRY_INTERVAL=2
RETRY_COUNT=0
while [ "$RETRY_COUNT" -lt "$MAX_RETRIES" ]; do
if nc -z "$DB_HOST" "$DB_PORT" 2>/dev/null; then
echo "✅ Database is reachable at ${DB_HOST}:${DB_PORT}"
# Extra grace period for MySQL to finish initialization
sleep 2
return 0
fi
RETRY_COUNT=$((RETRY_COUNT + 1))
echo " Attempt ${RETRY_COUNT}/${MAX_RETRIES} - database not ready, retrying in ${RETRY_INTERVAL}s..."
sleep "$RETRY_INTERVAL"
done
echo "❌ Database at ${DB_HOST}:${DB_PORT} not reachable after ${MAX_RETRIES} attempts."
exit 1
}
# --- Run Database Migrations ---
if [ "$RUN_MIGRATIONS" = "true" ]; then
wait_for_db
echo "🔄 Running Prisma migrations..."
prisma migrate deploy || npx prisma migrate deploy
echo "✅ Migrations complete!"
fi
# --- Run Seeds ---
if [ "$RUN_SEEDS" = "true" ]; then
wait_for_db
echo "🌱 Running database seeds..."
bun run prisma/seed-rbac.ts
bun run prisma/seed-templates.ts
bun run prisma/seed.ts
bun run prisma/seed-news-latc.ts
echo "✅ Seeds complete!"
fi
# Execute the main command (e.g., node server.js)
exec "$@"