You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
36 lines
1.1 KiB
36 lines
1.1 KiB
#!/bin/sh
|
|
set -e
|
|
|
|
# Wait for PostgreSQL database connection if POSTGRES_HOST is specified
|
|
if [ -n "$POSTGRES_HOST" ]; then
|
|
echo "Waiting for PostgreSQL database ($POSTGRES_HOST)..."
|
|
while ! python -c "
|
|
import os, sys, psycopg2
|
|
try:
|
|
conn = psycopg2.connect(
|
|
dbname=os.getenv('POSTGRES_DB', 'divar_crawler'),
|
|
user=os.getenv('POSTGRES_USER', 'postgres'),
|
|
password=os.getenv('POSTGRES_PASSWORD', 'postgres'),
|
|
host=os.getenv('POSTGRES_HOST', 'db'),
|
|
port=os.getenv('POSTGRES_PORT', '5432'),
|
|
connect_timeout=2
|
|
)
|
|
conn.close()
|
|
sys.exit(0)
|
|
except Exception:
|
|
sys.exit(1)
|
|
" 2>/dev/null; do
|
|
sleep 1
|
|
done
|
|
echo "PostgreSQL database is ready!"
|
|
fi
|
|
|
|
# Automatically run Django migrations and collectstatic before starting backend server
|
|
if [ "$1" = "gunicorn" ] || ([ "$1" = "python" ] && [ "$2" = "backend/manage.py" ]); then
|
|
echo "Running Django migrations..."
|
|
python backend/manage.py migrate --noinput
|
|
echo "Collecting static files..."
|
|
python backend/manage.py collectstatic --noinput --clear || true
|
|
fi
|
|
|
|
exec "$@"
|