testing
This commit is contained in:
24
Dockerfile
24
Dockerfile
@@ -27,27 +27,13 @@ RUN mkdir -p /app/uploads/rooms /app/uploads/profile_pics /app/static/uploads &&
|
||||
chown -R celery:celery /app && \
|
||||
chmod -R 755 /app/uploads
|
||||
|
||||
# Create and set up startup script
|
||||
RUN echo '#!/bin/bash\n\
|
||||
echo "Waiting for database..."\n\
|
||||
while ! nc -z db 5432; do\n\
|
||||
sleep 0.1\n\
|
||||
done\n\
|
||||
echo "Database is ready!"\n\
|
||||
\n\
|
||||
echo "Running database migrations..."\n\
|
||||
flask db upgrade\n\
|
||||
\n\
|
||||
echo "Creating admin user..."\n\
|
||||
flask create-admin\n\
|
||||
\n\
|
||||
echo "Starting application..."\n\
|
||||
exec "$@"' > /app/start.sh && \
|
||||
chmod +x /app/start.sh && \
|
||||
chown celery:celery /app/start.sh
|
||||
# Make entrypoint script executable
|
||||
RUN chmod +x /app/entrypoint.sh && \
|
||||
chown celery:celery /app/entrypoint.sh
|
||||
|
||||
# Switch to non-root user
|
||||
USER celery
|
||||
|
||||
# Set entrypoint
|
||||
ENTRYPOINT ["/app/start.sh"]
|
||||
ENTRYPOINT ["/app/entrypoint.sh"]
|
||||
CMD ["gunicorn", "--bind", "0.0.0.0:5000", "app:app"]
|
||||
11
app.py
11
app.py
@@ -80,17 +80,6 @@ def create_app():
|
||||
db.session.execute(text('SELECT 1'))
|
||||
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({
|
||||
'status': 'healthy',
|
||||
'database': 'connected',
|
||||
|
||||
@@ -22,10 +22,10 @@ services:
|
||||
restart: unless-stopped
|
||||
healthcheck:
|
||||
test: ["CMD", "curl", "-f", "http://localhost:5000/health"]
|
||||
interval: 30s
|
||||
timeout: 10s
|
||||
retries: 5
|
||||
start_period: 40s
|
||||
interval: 60s
|
||||
timeout: 30s
|
||||
retries: 3
|
||||
start_period: 120s
|
||||
deploy:
|
||||
resources:
|
||||
limits:
|
||||
|
||||
@@ -42,10 +42,9 @@ echo "PostgreSQL is up - executing command"
|
||||
echo "Running initialization..."
|
||||
python3 -c "
|
||||
from app import create_app
|
||||
from models import SiteSettings, db
|
||||
from models import SiteSettings, db, User
|
||||
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()
|
||||
@@ -79,9 +78,24 @@ with app.app_context():
|
||||
except Exception as e:
|
||||
print(f'Error creating site settings: {e}')
|
||||
|
||||
# Initialize admin user
|
||||
print('Initializing admin user...')
|
||||
init_admin()
|
||||
# Create admin user if it doesn't exist
|
||||
print('Creating admin user...')
|
||||
admin = User.query.filter_by(email='administrator@docupulse.com').first()
|
||||
if not admin:
|
||||
admin = User(
|
||||
username='administrator',
|
||||
email='administrator@docupulse.com',
|
||||
last_name='None',
|
||||
company='docupulse',
|
||||
is_admin=True,
|
||||
is_active=True
|
||||
)
|
||||
admin.set_password('changeme')
|
||||
db.session.add(admin)
|
||||
db.session.commit()
|
||||
print('Default administrator user created successfully.')
|
||||
else:
|
||||
print('Admin user already exists.')
|
||||
|
||||
# Create default templates
|
||||
print('Creating default templates...')
|
||||
|
||||
Reference in New Issue
Block a user