credent007 commited on
Commit
4ff8d3a
·
verified ·
1 Parent(s): dc246d7

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +50 -28
Dockerfile CHANGED
@@ -1,47 +1,69 @@
1
- # Use a slim Python image for a smaller footprint
2
- FROM python:3.11-slim
 
 
3
 
4
- # Set environment variables
5
- # PYTHONDONTWRITEBYTECODE: Prevents Python from writing .pyc files
6
- # PYTHONUNBUFFERED: Ensures logs are sent straight to terminal without buffering
7
  ENV PYTHONDONTWRITEBYTECODE=1 \
8
  PYTHONUNBUFFERED=1 \
9
  PORT=7860
10
 
11
- # Install system dependencies
12
- # Added libmupdf-dev if you decide to use advanced PyMuPDF features,
13
- # though the pip package usually bundles what it needs.
14
- # Install system dependencies
15
- RUN apt-get update && \
16
- apt-get install -y --no-install-recommends \
17
- git \
18
- build-essential \
19
- libgl1 \
20
- libglib2.0-0 \
21
- libsm6 \
22
- libxrender1 \
23
- libxext6 \
24
- && apt-get clean \
25
  && rm -rf /var/lib/apt/lists/*
26
 
27
- # Set the working directory
 
 
28
  WORKDIR /app
29
 
30
- # Install Python dependencies first (leverages Docker layer caching)
 
 
31
  COPY requirements.txt .
32
- RUN pip install --no-cache-dir --upgrade pip && \
33
- pip install --no-cache-dir -r requirements.txt
34
- # Copy the rest of the application code
35
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
36
  COPY . .
37
 
38
- # Create a non-root user for security (Best Practice)
 
 
39
  RUN useradd -m appuser && chown -R appuser /app
40
  USER appuser
41
 
42
- # Expose the designated port
 
 
43
  EXPOSE 7860
44
 
45
- # Run the application
46
- # We use the list form of CMD for better signal handling (CTRL+C)
 
47
  CMD ["sh", "-c", "uvicorn mainapp:app --host 0.0.0.0 --port ${PORT}"]
 
1
+ # =========================================================
2
+ # 1. BASE IMAGE (CUDA + PyTorch preinstalled)
3
+ # =========================================================
4
+ FROM pytorch/pytorch:2.2.0-cuda12.1-cudnn8-runtime
5
 
6
+ # =========================================================
7
+ # 2. ENV VARIABLES
8
+ # =========================================================
9
  ENV PYTHONDONTWRITEBYTECODE=1 \
10
  PYTHONUNBUFFERED=1 \
11
  PORT=7860
12
 
13
+ # =========================================================
14
+ # 3. SYSTEM DEPENDENCIES
15
+ # =========================================================
16
+ RUN apt-get update && apt-get install -y --no-install-recommends \
17
+ git \
18
+ build-essential \
19
+ ninja-build \
20
+ cmake \
21
+ libglib2.0-0 \
22
+ libsm6 \
23
+ libxrender1 \
24
+ libxext6 \
 
 
25
  && rm -rf /var/lib/apt/lists/*
26
 
27
+ # =========================================================
28
+ # 4. WORK DIRECTORY
29
+ # =========================================================
30
  WORKDIR /app
31
 
32
+ # =========================================================
33
+ # 5. COPY REQUIREMENTS FIRST (Docker cache optimization)
34
+ # =========================================================
35
  COPY requirements.txt .
 
 
 
36
 
37
+ # Upgrade pip
38
+ RUN pip install --no-cache-dir --upgrade pip
39
+
40
+ # =========================================================
41
+ # 6. INSTALL PYTHON DEPENDENCIES
42
+ # =========================================================
43
+ RUN pip install --no-cache-dir -r requirements.txt
44
+
45
+ # =========================================================
46
+ # 7. INSTALL FLASH ATTENTION (IMPORTANT)
47
+ # =========================================================
48
+ RUN pip install flash-attn==2.5.8 --no-build-isolation
49
+
50
+ # =========================================================
51
+ # 8. COPY APPLICATION CODE
52
+ # =========================================================
53
  COPY . .
54
 
55
+ # =========================================================
56
+ # 9. CREATE NON-ROOT USER (SECURITY)
57
+ # =========================================================
58
  RUN useradd -m appuser && chown -R appuser /app
59
  USER appuser
60
 
61
+ # =========================================================
62
+ # 10. EXPOSE PORT
63
+ # =========================================================
64
  EXPOSE 7860
65
 
66
+ # =========================================================
67
+ # 11. START APPLICATION
68
+ # =========================================================
69
  CMD ["sh", "-c", "uvicorn mainapp:app --host 0.0.0.0 --port ${PORT}"]