JeorgeC commited on
Commit
1c5882a
·
verified ·
1 Parent(s): 3ed5087

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +25 -5
Dockerfile CHANGED
@@ -1,18 +1,38 @@
 
1
  FROM python:3.10-slim
2
 
 
3
  WORKDIR /app
4
 
5
- # Copy requirements first for better caching
 
 
 
 
 
6
  COPY requirements.txt .
7
 
8
- # Install dependencies
9
- RUN pip install --no-cache-dir -r requirements.txt
 
10
 
11
  # Copy application code
12
  COPY . .
13
 
 
 
 
 
14
  # Expose port 7860 (Hugging Face Spaces default)
15
  EXPOSE 7860
16
 
17
- # Run the application
18
- CMD ["python", "app.py"]
 
 
 
 
 
 
 
 
 
1
+ # Use Python 3.10 slim image for better performance
2
  FROM python:3.10-slim
3
 
4
+ # Set working directory
5
  WORKDIR /app
6
 
7
+ # Install system dependencies for better stability
8
+ RUN apt-get update && apt-get install -y \
9
+ gcc \
10
+ && rm -rf /var/lib/apt/lists/*
11
+
12
+ # Copy requirements first for better Docker layer caching
13
  COPY requirements.txt .
14
 
15
+ # Install Python dependencies with no cache to reduce image size
16
+ RUN pip install --no-cache-dir --upgrade pip && \
17
+ pip install --no-cache-dir -r requirements.txt
18
 
19
  # Copy application code
20
  COPY . .
21
 
22
+ # Create a non-root user for security
23
+ RUN useradd -m -u 1000 appuser && chown -R appuser:appuser /app
24
+ USER appuser
25
+
26
  # Expose port 7860 (Hugging Face Spaces default)
27
  EXPOSE 7860
28
 
29
+ # Add health check
30
+ HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
31
+ CMD curl -f http://localhost:7860/health || exit 1
32
+
33
+ # Set environment variables for better Python behavior
34
+ ENV PYTHONUNBUFFERED=1
35
+ ENV PYTHONDONTWRITEBYTECODE=1
36
+
37
+ # Run the application with proper signal handling
38
+ CMD ["python", "-u", "app.py"]