khalednabawi11 commited on
Commit
f54c96f
·
verified ·
1 Parent(s): b78871c

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +20 -15
Dockerfile CHANGED
@@ -1,6 +1,9 @@
1
  FROM python:3.9-slim
2
 
3
- # Set working directory
 
 
 
4
  WORKDIR /code
5
 
6
  # Install system dependencies
@@ -10,25 +13,27 @@ RUN apt-get update && apt-get install -y \
10
  curl \
11
  && rm -rf /var/lib/apt/lists/*
12
 
13
-
14
- RUN mkdir -p /code/models/.cache/huggingface
15
-
16
- # Copy requirements and install
17
- COPY app/requirements.txt .
18
  RUN pip install --no-cache-dir -r requirements.txt
19
 
20
- # Copy the entire app folder
21
- COPY app/ ./app/
 
 
 
 
 
22
 
23
- # Set the working directory to app/
24
- WORKDIR /code/app
 
25
 
26
  # Expose the port
27
  EXPOSE 7860
28
 
29
- # Environment variables (optional)
30
- ENV HOST=0.0.0.0
31
- ENV PORT=7860
32
 
33
- # Run the FastAPI app
34
- CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860"]
 
1
  FROM python:3.9-slim
2
 
3
+ # Create a non-root user
4
+ RUN useradd -m appuser
5
+
6
+ # Set the working directory
7
  WORKDIR /code
8
 
9
  # Install system dependencies
 
13
  curl \
14
  && rm -rf /var/lib/apt/lists/*
15
 
16
+ # Copy requirements file and install Python dependencies
17
+ COPY requirements.txt .
 
 
 
18
  RUN pip install --no-cache-dir -r requirements.txt
19
 
20
+ # Copy the application code
21
+ COPY app /code/app
22
+ COPY main.py .
23
+
24
+ # Create models and cache directories and set correct permissions
25
+ RUN mkdir -p /code/models/.cache/huggingface && \
26
+ chown -R appuser:appuser /code/models
27
 
28
+ # Set environment variables
29
+ ENV HOST=0.0.0.0
30
+ ENV PORT=7860
31
 
32
  # Expose the port
33
  EXPOSE 7860
34
 
35
+ # Switch to the non-root user
36
+ USER appuser
 
37
 
38
+ # Command to run the FastAPI app
39
+ CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "7860"]