-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathentrypoint.sh
More file actions
executable file
·58 lines (48 loc) · 1.76 KB
/
entrypoint.sh
File metadata and controls
executable file
·58 lines (48 loc) · 1.76 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
#!/usr/bin/env bash
WAIT_S="${WAIT_S:-1}"
MAX_RETRIES="${MAX_RETRIES:-30}"
set -euo pipefail
# Verify DATABASE_URL is set
if [ -z "${DATABASE_URL:-}" ]; then
echo "ERROR: DATABASE_URL environment variable is not set"
exit 1
fi
echo "DATABASE_URL is set: ${DATABASE_URL}"
# Extract database host and port from DATABASE_URL
# Format: postgres://user:pass@host:port/database
DB_HOST=$(echo "$DATABASE_URL" | sed -E 's|.*@([^:/]+).*|\1|')
DB_PORT=$(echo "$DATABASE_URL" | sed -E 's|.*:([0-9]+)/.*|\1|')
echo "Parsed database connection: host=${DB_HOST}, port=${DB_PORT}"
# Wait for database to accept connections
echo "Waiting for database to be ready..."
RETRIES=0
until pg_isready -h "${DB_HOST}" -p "${DB_PORT}" -U ltx_user -d ltx_db >/dev/null 2>&1; do
RETRIES=$((RETRIES + 1))
if [ $RETRIES -ge $MAX_RETRIES ]; then
echo "ERROR: Database did not become ready after ${MAX_RETRIES} attempts"
echo "Attempting to show pg_isready output:"
pg_isready -h "${DB_HOST}" -p "${DB_PORT}" -U ltx_user -d ltx_db || true
exit 1
fi
echo "Database is unavailable - sleeping (${WAIT_S}s) [attempt ${RETRIES}/${MAX_RETRIES}]"
sleep ${WAIT_S}
done
echo "Database is accepting connections!"
# Run diesel setup (creates database if needed, sets up diesel metadata)
echo "Setting up diesel database..."
if diesel database setup --locked-schema; then
echo "Diesel database setup completed successfully"
else
echo "Diesel setup failed, attempting to run migrations directly..."
if diesel migration run; then
echo "Migrations completed successfully"
else
echo "ERROR: Failed to run migrations"
echo "Attempting to show diesel migration status:"
diesel migration list || true
exit 1
fi
fi
echo "Database is ready!"
echo "Starting API server..."
exec api-ltx