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 && \
|
chown -R celery:celery /app && \
|
||||||
chmod -R 755 /app/uploads
|
chmod -R 755 /app/uploads
|
||||||
|
|
||||||
# Create and set up startup script
|
# Make entrypoint script executable
|
||||||
RUN echo '#!/bin/bash\n\
|
RUN chmod +x /app/entrypoint.sh && \
|
||||||
echo "Waiting for database..."\n\
|
chown celery:celery /app/entrypoint.sh
|
||||||
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
|
|
||||||
|
|
||||||
# Switch to non-root user
|
# Switch to non-root user
|
||||||
USER celery
|
USER celery
|
||||||
|
|
||||||
# Set entrypoint
|
# 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.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',
|
||||||
|
|||||||
@@ -22,10 +22,10 @@ services:
|
|||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
healthcheck:
|
healthcheck:
|
||||||
test: ["CMD", "curl", "-f", "http://localhost:5000/health"]
|
test: ["CMD", "curl", "-f", "http://localhost:5000/health"]
|
||||||
interval: 30s
|
interval: 60s
|
||||||
timeout: 10s
|
timeout: 30s
|
||||||
retries: 5
|
retries: 3
|
||||||
start_period: 40s
|
start_period: 120s
|
||||||
deploy:
|
deploy:
|
||||||
resources:
|
resources:
|
||||||
limits:
|
limits:
|
||||||
|
|||||||
@@ -42,10 +42,9 @@ echo "PostgreSQL is up - executing command"
|
|||||||
echo "Running initialization..."
|
echo "Running initialization..."
|
||||||
python3 -c "
|
python3 -c "
|
||||||
from app import create_app
|
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_events_table import upgrade as upgrade_events
|
||||||
from migrations.add_notifs_table import upgrade as upgrade_notifs
|
from migrations.add_notifs_table import upgrade as upgrade_notifs
|
||||||
from init_admin import init_admin
|
|
||||||
from utils.email_templates import create_default_templates
|
from utils.email_templates import create_default_templates
|
||||||
|
|
||||||
app = create_app()
|
app = create_app()
|
||||||
@@ -79,9 +78,24 @@ with app.app_context():
|
|||||||
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
|
# Create admin user if it doesn't exist
|
||||||
print('Initializing admin user...')
|
print('Creating admin user...')
|
||||||
init_admin()
|
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
|
# Create default templates
|
||||||
print('Creating default templates...')
|
print('Creating default templates...')
|
||||||
|
|||||||
Reference in New Issue
Block a user