“shubhamdhamal” commited on
Commit
e7f3d6b
·
1 Parent(s): 7644eac

Add database initialization on startup

Browse files
Files changed (2) hide show
  1. Dockerfile +7 -3
  2. start.sh +22 -0
Dockerfile CHANGED
@@ -33,7 +33,10 @@ RUN pip install --no-cache-dir --upgrade pip && \
33
  COPY --chown=user . .
34
 
35
  # Create necessary directories with proper permissions
36
- RUN mkdir -p vector_db cache learning_paths
 
 
 
37
 
38
  # Hugging Face Spaces requires port 7860
39
  EXPOSE 7860
@@ -42,6 +45,7 @@ EXPOSE 7860
42
  ENV PORT=7860
43
  ENV FLASK_ENV=production
44
  ENV PYTHONUNBUFFERED=1
 
45
 
46
- # Run the Flask app with gunicorn
47
- CMD ["gunicorn", "run:app", "--bind", "0.0.0.0:7860", "--workers", "2", "--timeout", "120"]
 
33
  COPY --chown=user . .
34
 
35
  # Create necessary directories with proper permissions
36
+ RUN mkdir -p vector_db cache learning_paths instance
37
+
38
+ # Make startup script executable
39
+ RUN chmod +x start.sh
40
 
41
  # Hugging Face Spaces requires port 7860
42
  EXPOSE 7860
 
45
  ENV PORT=7860
46
  ENV FLASK_ENV=production
47
  ENV PYTHONUNBUFFERED=1
48
+ ENV FLASK_APP=web_app:create_app
49
 
50
+ # Run the startup script (initializes DB then starts gunicorn)
51
+ CMD ["bash", "start.sh"]
start.sh ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/bin/bash
2
+ set -e
3
+
4
+ echo "=== Starting AI Learning Path Generator ==="
5
+
6
+ # Set Flask app for migrations
7
+ export FLASK_APP=web_app:create_app
8
+
9
+ # Initialize database if it doesn't exist
10
+ echo "Initializing database..."
11
+ python -c "
12
+ from web_app import create_app
13
+ from web_app.models import db
14
+
15
+ app = create_app()
16
+ with app.app_context():
17
+ db.create_all()
18
+ print('Database tables created successfully!')
19
+ "
20
+
21
+ echo "Starting gunicorn server..."
22
+ exec gunicorn run:app --bind 0.0.0.0:7860 --workers 2 --timeout 120