Kaadan commited on
Commit
18e5c97
·
1 Parent(s): 33c29a9

fix docker injection

Browse files
Dockerfile CHANGED
@@ -52,6 +52,12 @@ ENV DEBUG=False
52
  EXPOSE 7860
53
 
54
  # ----------------------------
55
- # Start FastAPI
56
  # ----------------------------
57
- CMD ["python", "main.py"]
 
 
 
 
 
 
 
52
  EXPOSE 7860
53
 
54
  # ----------------------------
55
+ # Make startup script executable and set it as entrypoint
56
  # ----------------------------
57
+ COPY backend/start.sh /app/start.sh
58
+ RUN chmod +x /app/start.sh
59
+
60
+ # ----------------------------
61
+ # Start FastAPI (runs migrations first)
62
+ # ----------------------------
63
+ CMD ["/app/start.sh"]
backend/Dockerfile CHANGED
@@ -25,8 +25,11 @@ RUN pip install -r requirements.txt
25
  # Copy the rest of the application code
26
  COPY . .
27
 
 
 
 
28
  # Expose the port the app runs on
29
  EXPOSE 8000
30
 
31
- # Run the application
32
- CMD ["python", "main.py"]
 
25
  # Copy the rest of the application code
26
  COPY . .
27
 
28
+ # Make startup script executable
29
+ RUN chmod +x start.sh
30
+
31
  # Expose the port the app runs on
32
  EXPOSE 8000
33
 
34
+ # Run the application (with migrations first)
35
+ CMD ["./start.sh"]
backend/alembic.ini CHANGED
@@ -86,6 +86,7 @@ path_separator = os
86
  # database URL. This is consumed by the user-maintained env.py script only.
87
  # other means of configuring database URLs may be customized within the env.py
88
  # file.
 
89
  sqlalchemy.url = sqlite:///assessment_platform.db
90
 
91
 
 
86
  # database URL. This is consumed by the user-maintained env.py script only.
87
  # other means of configuring database URLs may be customized within the env.py
88
  # file.
89
+ # NOTE: This is overridden by the DATABASE_URL environment variable in env.py
90
  sqlalchemy.url = sqlite:///assessment_platform.db
91
 
92
 
backend/alembic/env.py CHANGED
@@ -1,4 +1,5 @@
1
  from logging.config import fileConfig
 
2
 
3
  from sqlalchemy import engine_from_config
4
  from sqlalchemy import pool
@@ -7,7 +8,6 @@ from alembic import context
7
 
8
  # Import our models
9
  import sys
10
- import os
11
  sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
12
 
13
  from models import Base # Import the Base from our models __init__ file
@@ -16,6 +16,11 @@ from models import Base # Import the Base from our models __init__ file
16
  # access to the values within the .ini file in use.
17
  config = context.config
18
 
 
 
 
 
 
19
  # Interpret the config file for Python logging.
20
  # This line sets up loggers basically.
21
  if config.config_file_name is not None:
 
1
  from logging.config import fileConfig
2
+ import os
3
 
4
  from sqlalchemy import engine_from_config
5
  from sqlalchemy import pool
 
8
 
9
  # Import our models
10
  import sys
 
11
  sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
12
 
13
  from models import Base # Import the Base from our models __init__ file
 
16
  # access to the values within the .ini file in use.
17
  config = context.config
18
 
19
+ # Override the sqlalchemy.url with the DATABASE_URL environment variable if available
20
+ database_url = os.getenv("DATABASE_URL")
21
+ if database_url:
22
+ config.set_main_option("sqlalchemy.url", database_url)
23
+
24
  # Interpret the config file for Python logging.
25
  # This line sets up loggers basically.
26
  if config.config_file_name is not None:
backend/start.sh ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ #!/bin/bash
2
+
3
+ # Run database migrations
4
+ echo "Running database migrations..."
5
+ alembic upgrade head
6
+
7
+ # Start the application
8
+ echo "Starting the application..."
9
+ exec python main.py