-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathdocker-entrypoint.sh
More file actions
53 lines (46 loc) · 1.33 KB
/
docker-entrypoint.sh
File metadata and controls
53 lines (46 loc) · 1.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
#!/bin/bash
set -e
# Function to wait for the database to be ready
wait_for_db() {
echo "Waiting for database..."
# Extract host and port from DATABASE_URL
if [[ $DATABASE_URL == postgresql://* ]]; then
# Extract host from the URL (assuming format postgresql://user:pass@host:port/db)
DB_HOST=$(echo $DATABASE_URL | sed -e 's|^postgresql://[^@]*@\([^:/]*\).*|\1|')
# Extract port, defaulting to 5432 if not specified
DB_PORT=$(echo $DATABASE_URL | sed -n -e 's|^postgresql://[^@]*@[^:]*:\([0-9]*\).*|\1|p')
DB_PORT=${DB_PORT:-5432}
echo "Checking connection to database at $DB_HOST:$DB_PORT..."
# Wait until we can connect to the database
until nc -z -v -w30 $DB_HOST $DB_PORT; do
echo "Database is unavailable - sleeping"
sleep 2
done
echo "Database is up and running!"
else
echo "Invalid DATABASE_URL format. Skipping database check."
fi
}
# Run database migrations
run_migrations() {
echo "Running database migrations..."
alembic upgrade head
echo "Migrations completed!"
}
# Main entrypoint logic
case "$1" in
migrate)
wait_for_db
run_migrations
;;
start)
wait_for_db
run_migrations
echo "Starting A2A LangGraph Agent..."
exec python main.py
;;
*)
# If custom command is provided, execute it
exec "$@"
;;
esac