-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathdocker-entrypoint.backend.sh
More file actions
65 lines (55 loc) · 2.17 KB
/
Copy pathdocker-entrypoint.backend.sh
File metadata and controls
65 lines (55 loc) · 2.17 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
#!/bin/bash
set -e
echo "============================================"
echo "Jet Admin Backend - Docker Entrypoint"
echo "============================================"
cd /app/apps/backend
# ============================================
# Setup Environment
# ============================================
echo "[1/3] Configuring backend..."
# All env vars (PORT, DATABASE_URL, FIREBASE_CREDENTIALS, VAULT_ENCRYPTION_KEY,
# SUPABASE_*, GROQ_API_KEY, GOOGLE_CLIENT_*, BACKEND_URL, etc.) are injected
# directly by Render's environment panel and are already present in process.env.
#
# Render sets PORT to its public-facing port (e.g. 10000).
# Node.js reads it via environment.js: process.env.PORT || 8090
# No .env file generation or port overrides needed.
export NODE_ENV=${NODE_ENV:-production}
# ============================================
# Wait for Dependencies
# ============================================
echo "[2/3] Waiting for dependencies..."
# Wait for PostgreSQL
if [ -n "$DATABASE_URL" ]; then
DB_HOST=$(echo "$DATABASE_URL" | sed -E 's|.*@([^:/]+).*|\1|')
DB_PORT=$(echo "$DATABASE_URL" | sed -nE 's|.*:([0-9]+)/.*|\1|p')
DB_USER=$(echo "$DATABASE_URL" | sed -E 's|.*://([^:]+):.*|\1|')
[ -z "$DB_PORT" ] && DB_PORT=5432
echo " Waiting for PostgreSQL at $DB_HOST:$DB_PORT..."
timeout=60
while ! pg_isready -h "$DB_HOST" -p "$DB_PORT" -U "$DB_USER" -q 2>/dev/null; do
timeout=$((timeout - 1))
[ $timeout -le 0 ] && echo " ERROR: PostgreSQL not available" && exit 1
sleep 1
done
echo " PostgreSQL is ready"
fi
# ============================================
# Database Initialization
# ============================================
if [ "$SEED_DATABASE" = "true" ]; then
echo "[3/3] Initializing database..."
npx prisma migrate deploy
npm run seed
echo " Database initialized"
else
echo "[3/3] Skipping database seed"
fi
# ============================================
# Start Backend
# ============================================
echo "============================================"
echo "Starting Node.js backend server on port ${PORT:-8090}..."
echo "============================================"
exec "$@"