Really-amin commited on
Commit
2cb9811
·
verified ·
1 Parent(s): 568293e

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +37 -15
Dockerfile CHANGED
@@ -7,18 +7,22 @@ FROM python:3.10-slim AS builder
7
  RUN apt-get update && apt-get install -y \
8
  build-essential \
9
  gcc \
 
 
10
  && rm -rf /var/lib/apt/lists/*
11
 
12
- # Upgrade pip
13
- RUN pip install --upgrade pip
14
 
15
  # Create virtual environment
16
  RUN python -m venv /opt/venv
17
  ENV PATH="/opt/venv/bin:$PATH"
18
 
19
  # Copy requirements and install dependencies
20
- WORKDIR /app
21
  COPY requirements.txt .
 
 
22
  RUN pip install --no-cache-dir -r requirements.txt
23
 
24
  # ────────────────
@@ -31,12 +35,26 @@ RUN groupadd -g 1000 appuser && useradd -r -u 1000 -g appuser appuser
31
 
32
  # Install runtime dependencies
33
  RUN apt-get update && apt-get install -y \
 
34
  poppler-utils \
35
  tesseract-ocr \
36
- libgl1 \
 
 
 
 
 
 
 
 
 
37
  curl \
 
 
38
  sqlite3 \
39
- && rm -rf /var/lib/apt/lists/*
 
 
40
 
41
  # Copy virtual environment from builder
42
  COPY --from=builder /opt/venv /opt/venv
@@ -53,6 +71,7 @@ RUN mkdir -p \
53
  /app/logs \
54
  /app/uploads \
55
  /app/backups \
 
56
  /tmp/app_fallback \
57
  && chown -R appuser:appuser /app \
58
  && chown -R appuser:appuser /tmp/app_fallback \
@@ -74,19 +93,22 @@ ENV HF_HOME=/app/cache
74
  ENV LOG_LEVEL=INFO
75
  ENV ENVIRONMENT=production
76
  ENV PYTHONUNBUFFERED=1
 
 
 
77
 
78
- # Switch to non-root user
79
  USER appuser
80
 
81
- # Expose port (this is for documentation, the actual port is set in CMD)
82
  EXPOSE 8000
83
 
84
- # Health check (pointing to the correct health endpoint from main.py)
85
- HEALTHCHECK --interval=30s --timeout=10s --start-period=40s --retries=3 \
86
- CMD curl -fs http://localhost:${PORT:-8000}/api/health || exit 1
 
 
 
87
 
88
- # --- ✅ FIX: Default CMD با قابلیت خواندن پورت از متغیرهای محیطی ---
89
- # دستور قبلی که پورت را روی 8000 ثابت کرده بود حذف شد.
90
- # دستور جدید از متغیر محیطی $PORT که توسط هاگینگ فیس داده می‌شود استفاده می‌کند.
91
- # اگر $PORT وجود نداشت (مثلا در اجرای لوکال)، از پورت 8000 به عنوان پیش‌فرض استفاده می‌کند.
92
- CMD ["sh", "-c", "uvicorn app.main:app --host 0.0.0.0 --port ${PORT:-8000} --workers 1"]
 
7
  RUN apt-get update && apt-get install -y \
8
  build-essential \
9
  gcc \
10
+ g++ \
11
+ pkg-config \
12
  && rm -rf /var/lib/apt/lists/*
13
 
14
+ # Upgrade pip and install wheel
15
+ RUN pip install --upgrade pip setuptools wheel
16
 
17
  # Create virtual environment
18
  RUN python -m venv /opt/venv
19
  ENV PATH="/opt/venv/bin:$PATH"
20
 
21
  # Copy requirements and install dependencies
22
+ WORKDIR /build
23
  COPY requirements.txt .
24
+
25
+ # Install Python packages
26
  RUN pip install --no-cache-dir -r requirements.txt
27
 
28
  # ────────────────
 
35
 
36
  # Install runtime dependencies
37
  RUN apt-get update && apt-get install -y \
38
+ # OCR and PDF processing
39
  poppler-utils \
40
  tesseract-ocr \
41
+ tesseract-ocr-eng \
42
+ tesseract-ocr-fas \
43
+ # Graphics libraries
44
+ libgl1-mesa-glx \
45
+ libglib2.0-0 \
46
+ libsm6 \
47
+ libxext6 \
48
+ libxrender-dev \
49
+ libgomp1 \
50
+ # Network tools
51
  curl \
52
+ wget \
53
+ # Database
54
  sqlite3 \
55
+ # Clean up
56
+ && rm -rf /var/lib/apt/lists/* \
57
+ && apt-get clean
58
 
59
  # Copy virtual environment from builder
60
  COPY --from=builder /opt/venv /opt/venv
 
71
  /app/logs \
72
  /app/uploads \
73
  /app/backups \
74
+ /app/frontend \
75
  /tmp/app_fallback \
76
  && chown -R appuser:appuser /app \
77
  && chown -R appuser:appuser /tmp/app_fallback \
 
93
  ENV LOG_LEVEL=INFO
94
  ENV ENVIRONMENT=production
95
  ENV PYTHONUNBUFFERED=1
96
+ ENV REDIS_HOST=redis
97
+ ENV REDIS_PORT=6379
98
+ ENV REDIS_URL=redis://redis:6379/0
99
 
100
+ # Switch to non-root user BEFORE any file operations
101
  USER appuser
102
 
103
+ # Expose port
104
  EXPOSE 8000
105
 
106
+ # Optimized health check
107
+ HEALTHCHECK --interval=45s --timeout=30s --start-period=180s --retries=10 \
108
+ CMD curl -fs http://localhost:8000/ping || exit 1
109
+
110
+ # Pre-create directories as appuser
111
+ RUN mkdir -p /app/data /app/logs /app/cache /app/uploads /app/backups
112
 
113
+ # Default CMD with better error handling and faster startup
114
+ CMD ["sh", "-c", "python -c 'import os; os.makedirs(\"/app/data\", exist_ok=True); os.makedirs(\"/app/logs\", exist_ok=True); print(\"=== Application Startup at $(date) ===\")' && uvicorn app.main:app --host 0.0.0.0 --port 8000 --workers 1 --log-level info"]