Files
docupulse/entrypoint.sh
2025-05-26 22:08:20 +02:00

53 lines
1.5 KiB
Bash

#!/bin/bash
# Print environment variables for debugging
echo "Environment variables:"
echo "POSTGRES_USER: $POSTGRES_USER"
echo "POSTGRES_PASSWORD: $POSTGRES_PASSWORD"
echo "POSTGRES_DB: $POSTGRES_DB"
echo "DATABASE_URL: $DATABASE_URL"
# Wait for the database to be ready
echo "Waiting for database to be ready..."
while ! nc -z db 5432; do
sleep 0.1
done
echo "Database is ready!"
# Wait for PostgreSQL to be ready to accept connections
echo "Waiting for PostgreSQL to accept connections..."
until PGPASSWORD=$POSTGRES_PASSWORD psql -h db -U $POSTGRES_USER -d $POSTGRES_DB -c '\q'; do
echo "PostgreSQL is unavailable - sleeping"
sleep 1
done
echo "PostgreSQL is up - executing command"
# Run migrations if they exist, otherwise initialize them
echo "Checking database migrations..."
if [ -d "migrations" ]; then
echo "Running existing migrations..."
flask db upgrade
else
echo "Initializing new migrations..."
flask db init
flask db migrate -m "Initial migration"
flask db upgrade
fi
# Create default site settings if they don't exist
echo "Creating default site settings..."
python3 -c "
from app import create_app
from models import SiteSettings, db
app = create_app()
with app.app_context():
try:
settings = SiteSettings.get_settings()
print('Default site settings created successfully')
except Exception as e:
print(f'Error creating site settings: {e}')
"
# Start the application
echo "Starting application..."
exec gunicorn --bind 0.0.0.0:5000 app:app