Testys commited on
Commit
328c2ba
1 Parent(s): 2333542

Adding Database migration to the Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +8 -4
Dockerfile CHANGED
@@ -1,4 +1,5 @@
1
- FROM python:3.10.12
 
2
 
3
  # Create a non-root user
4
  RUN useradd -m -u 1000 user
@@ -14,10 +15,13 @@ RUN pip install --no-cache-dir --upgrade -r requirements.txt
14
  COPY . .
15
 
16
  # Create and set permissions for the cache directory
17
- RUN mkdir /.cache && chown -R user:user /.cache && chmod -R 777 /.cache
 
 
 
18
 
19
  # Switch to the non-root user
20
  USER user
21
 
22
- # Run the application
23
- CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860"]
 
1
+ # Use a lightweight Python image
2
+ FROM python:3.10.12-slim
3
 
4
  # Create a non-root user
5
  RUN useradd -m -u 1000 user
 
15
  COPY . .
16
 
17
  # Create and set permissions for the cache directory
18
+ RUN mkdir /.cache && chown -R user:user /.cache && chmod -R u+w,go-w /.cache
19
+
20
+ # Set up the environment variables for Alembic
21
+ ENV ALEMBIC_CONFIG=alembic.ini
22
 
23
  # Switch to the non-root user
24
  USER user
25
 
26
+ # Run the application, including the migration step
27
+ CMD ["bash", "-c", "alembic upgrade head && uvicorn main:app --host 0.0.0.0 --port 7860"]