SyedFarooqAlii commited on
Commit
c89b543
·
1 Parent(s): a426a46
Files changed (1) hide show
  1. Dockerfile +36 -4
Dockerfile CHANGED
@@ -1,12 +1,44 @@
 
1
  FROM python:3.11-slim
2
 
3
- WORKDIR /app
 
 
 
 
4
 
 
 
 
 
 
 
 
 
 
 
 
 
5
  COPY requirements.txt .
6
- RUN pip install --no-cache-dir -r requirements.txt
7
 
 
 
 
 
 
8
  COPY . .
9
 
10
- EXPOSE 7860
 
 
 
 
 
 
 
 
 
 
11
 
12
- CMD ["uvicorn", "api:app", "--host", "0.0.0.0", "--port", "7860"]
 
 
1
+ # Use Python 3.11 slim image as base
2
  FROM python:3.11-slim
3
 
4
+ # Set environment variables
5
+ ENV PYTHONDONTWRITEBYTECODE=1 \
6
+ PYTHONUNBUFFERED=1 \
7
+ PYTHONPATH=/app \
8
+ PORT=7860
9
 
10
+ # Set work directory
11
+ WORKDIR /
12
+
13
+ # Install system dependencies
14
+ RUN apt-get update \
15
+ && apt-get install -y --no-install-recommends \
16
+ build-essential \
17
+ gcc \
18
+ curl \
19
+ && rm -rf /var/lib/apt/lists/*
20
+
21
+ # Copy requirements first to leverage Docker cache
22
  COPY requirements.txt .
 
23
 
24
+ # Install Python dependencies
25
+ RUN pip install --no-cache-dir --upgrade pip \
26
+ && pip install --no-cache-dir -r requirements.txt
27
+
28
+ # Copy the rest of the application
29
  COPY . .
30
 
31
+ # Create a non-root user and set permissions
32
+ RUN adduser --disabled-password --gecos '' appuser \
33
+ && chown -R appuser:appuser /app
34
+ USER appuser
35
+
36
+ # Expose port (Hugging Face typically uses port 7860 or 8080)
37
+ EXPOSE $PORT
38
+
39
+ # Health check endpoint
40
+ HEALTHCHECK --interval=30s --timeout=30s --start-period=5s --retries=3 \
41
+ CMD curl -f http://localhost:$PORT/health || exit 1
42
 
43
+ # Run the application with uvicorn directly for better production performance
44
+ CMD ["sh", "-c", "uvicorn api:app --host 0.0.0.0 --port $PORT"]