testing entrypoint

This commit is contained in:
2025-06-06 21:08:19 +02:00
parent fd34dd20ca
commit fc05fda666
2 changed files with 51 additions and 50 deletions

14
app.py
View File

@@ -76,9 +76,21 @@ def create_app():
@app.route('/health') @app.route('/health')
def health_check(): def health_check():
try: try:
# Check database connection # Check database connection with a timeout
db.session.execute(text('SELECT 1')) db.session.execute(text('SELECT 1'))
db.session.commit() db.session.commit()
# Check if we can actually query a table
try:
User.query.first()
except Exception as e:
app.logger.error(f"Database query failed: {str(e)}")
return jsonify({
'status': 'unhealthy',
'error': f"Database query failed: {str(e)}",
'timestamp': datetime.utcnow().isoformat()
}), 500
return jsonify({ return jsonify({
'status': 'healthy', 'status': 'healthy',
'database': 'connected', 'database': 'connected',

View File

@@ -38,67 +38,56 @@ until PGPASSWORD=$POSTGRES_PASSWORD psql -h db -U $POSTGRES_USER -d $POSTGRES_DB
done done
echo "PostgreSQL is up - executing command" echo "PostgreSQL is up - executing command"
# Run migrations # Run all initialization in a single Python script to avoid multiple Flask instances
echo "Running database migrations..." echo "Running initialization..."
flask db upgrade
# Create events table
echo "Creating events table..."
python3 -c "
from migrations.add_events_table import upgrade
from app import create_app
app = create_app()
with app.app_context():
try:
upgrade()
print('Events table created successfully')
except Exception as e:
print(f'Error creating events table: {e}')
"
# Create notifs table
echo "Creating notifs table..."
python3 -c "
from migrations.add_notifs_table import upgrade
from app import create_app
app = create_app()
with app.app_context():
try:
upgrade()
print('Notifs table created successfully')
except Exception as e:
print(f'Error creating notifs table: {e}')
"
# Create default site settings if they don't exist
echo "Creating default site settings..."
python3 -c " python3 -c "
from app import create_app from app import create_app
from models import SiteSettings, db from models import SiteSettings, db
from migrations.add_events_table import upgrade as upgrade_events
from migrations.add_notifs_table import upgrade as upgrade_notifs
from init_admin import init_admin
from utils.email_templates import create_default_templates
app = create_app() app = create_app()
with app.app_context(): with app.app_context():
# Run migrations
print('Running database migrations...')
from flask_migrate import upgrade
upgrade()
# Create events table
print('Creating events table...')
try:
upgrade_events()
print('Events table created successfully')
except Exception as e:
print(f'Error creating events table: {e}')
# Create notifs table
print('Creating notifs table...')
try:
upgrade_notifs()
print('Notifs table created successfully')
except Exception as e:
print(f'Error creating notifs table: {e}')
# Create default site settings
print('Creating default site settings...')
try: try:
settings = SiteSettings.get_settings() settings = SiteSettings.get_settings()
print('Default site settings created successfully') print('Default site settings created successfully')
except Exception as e: except Exception as e:
print(f'Error creating site settings: {e}') print(f'Error creating site settings: {e}')
# Initialize admin user
print('Initializing admin user...')
init_admin()
# Create default templates
print('Creating default templates...')
create_default_templates()
" "
# Initialize admin user
echo "Initializing admin user..."
python3 -c "
from init_admin import init_admin
init_admin()
"
# Create admin user
echo "Creating admin user..."
flask create-admin
# Create default templates
echo "Creating default templates..."
flask create-default-templates
# Start the application # Start the application
echo "Starting application..." echo "Starting application..."
exec gunicorn --bind 0.0.0.0:5000 app:app exec gunicorn --bind 0.0.0.0:5000 app:app