mike23415 commited on
Commit
429d7e2
·
verified ·
1 Parent(s): 3e7d34e

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +35 -5
Dockerfile CHANGED
@@ -1,20 +1,50 @@
1
  FROM python:3.10-slim
2
 
 
3
  WORKDIR /app
4
 
 
5
  RUN apt-get update && apt-get install -y --no-install-recommends \
6
  gcc \
 
 
 
7
  && rm -rf /var/lib/apt/lists/*
8
 
 
9
  COPY requirements.txt .
10
- RUN pip install --no-cache-dir --upgrade -r requirements.txt
11
 
 
 
 
 
 
12
  COPY . .
13
 
 
14
  RUN useradd -m -u 1000 user
15
- RUN mkdir -p /data/.huggingface && chown -R user:user /data
 
 
 
 
 
16
  USER user
17
- ENV HOME=/home/user PATH=/home/user/.local/bin:$PATH
18
- ENV HF_HOME=/data/.huggingface
19
 
20
- CMD ["gunicorn", "--worker-class", "sync", "--workers", "1", "--bind", "0.0.0.0:7860", "app:app"]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  FROM python:3.10-slim
2
 
3
+ # Set working directory
4
  WORKDIR /app
5
 
6
+ # Install system dependencies
7
  RUN apt-get update && apt-get install -y --no-install-recommends \
8
  gcc \
9
+ g++ \
10
+ git \
11
+ curl \
12
  && rm -rf /var/lib/apt/lists/*
13
 
14
+ # Copy requirements first for better Docker layer caching
15
  COPY requirements.txt .
 
16
 
17
+ # Install Python dependencies
18
+ RUN pip install --no-cache-dir --upgrade pip && \
19
+ pip install --no-cache-dir -r requirements.txt
20
+
21
+ # Copy application code
22
  COPY . .
23
 
24
+ # Create non-root user
25
  RUN useradd -m -u 1000 user
26
+
27
+ # Create necessary directories with proper permissions
28
+ RUN mkdir -p /data/.huggingface /app/data /app/results && \
29
+ chown -R user:user /data /app
30
+
31
+ # Switch to non-root user
32
  USER user
 
 
33
 
34
+ # Set environment variables
35
+ ENV HOME=/home/user \
36
+ PATH=/home/user/.local/bin:$PATH \
37
+ HF_HOME=/data/.huggingface \
38
+ TRANSFORMERS_CACHE=/data/.huggingface \
39
+ PYTHONPATH=/app \
40
+ PYTHONUNBUFFERED=1
41
+
42
+ # Expose port
43
+ EXPOSE 7860
44
+
45
+ # Health check
46
+ HEALTHCHECK --interval=30s --timeout=30s --start-period=60s --retries=3 \
47
+ CMD curl -f http://localhost:7860/ || exit 1
48
+
49
+ # Run the application
50
+ CMD ["gunicorn", "--worker-class", "sync", "--workers", "1", "--bind", "0.0.0.0:7860", "--timeout", "300", "--keep-alive", "2", "app:app"]