-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdocker-entrypoint.sh
More file actions
executable file
·59 lines (49 loc) · 2.33 KB
/
Copy pathdocker-entrypoint.sh
File metadata and controls
executable file
·59 lines (49 loc) · 2.33 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
#!/bin/sh
set -e
# ─────────────────────────────────────────────────────────────────────────────
# DerList Docker Entrypoint
#
# 1. Wait for PostgreSQL to be ready
# 2. Run Prisma migrations (fails on error — no silent masking)
# 3. Optionally seed the database with an owner account
# 4. Start the application via exec (replaces shell process)
# ─────────────────────────────────────────────────────────────────────────────
echo "╔══════════════════════════════════════════════╗"
echo "║ DerList — Starting Up... ║"
echo "╚══════════════════════════════════════════════╝"
# ── Validate required environment ──
if [ -z "$DATABASE_URL" ]; then
echo "❌ DATABASE_URL is not set. Cannot start."
exit 1
fi
# ── Wait for PostgreSQL ──
echo "⏳ Waiting for database..."
# Extract host and port from DATABASE_URL
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:-5432}
RETRIES=30
until pg_isready -h "$DB_HOST" -p "$DB_PORT" -q 2>/dev/null; do
RETRIES=$((RETRIES - 1))
if [ $RETRIES -eq 0 ]; then
echo "❌ Could not connect to PostgreSQL at $DB_HOST:$DB_PORT after 60 seconds."
exit 1
fi
echo " Waiting for PostgreSQL at $DB_HOST:$DB_PORT... ($RETRIES attempts left)"
sleep 2
done
echo "✅ Database is ready."
# ── Run Prisma Migrations ──
echo "🔄 Running database migrations..."
npx prisma migrate deploy
echo "✅ Migrations applied."
# ── Optional: Seed database with owner account ──
if [ -n "$ADMIN_EMAIL" ] && [ -n "$ADMIN_PASSWORD" ] && [ -n "$ADMIN_USERNAME" ]; then
echo "🌱 Running seed..."
npx tsx prisma/seed.ts || {
echo "⚠️ Seed failed (non-fatal — continuing startup)."
}
fi
# ── Start Application ──
echo "🚀 Starting DerList..."
exec node server.js