e
File size: 2,187 Bytes
28cfd30
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# ──────────────────────────────────────────────────────────────────
#  Eatlytic 2.0  β€”  Multi-stage Docker build
#  New in v2: reportlab (PDF export), twilio (WhatsApp bot),
#             Hindi OCR model pre-download, /health endpoint
# ──────────────────────────────────────────────────────────────────

# ── Stage 1: Builder ───────────────────────────────────────────────
FROM python:3.11-slim AS builder

WORKDIR /app
RUN apt-get update && apt-get install -y --no-install-recommends build-essential && \
    rm -rf /var/lib/apt/lists/*

COPY requirements.txt .
RUN pip install --no-cache-dir --prefix=/install -r requirements.txt

# ── Stage 2: Runtime ───────────────────────────────────────────────
FROM python:3.11-slim

WORKDIR /app

# Runtime libs required by OpenCV / EasyOCR
RUN apt-get update && apt-get install -y --no-install-recommends \
    libgl1 libglib2.0-0 libsm6 libxext6 libxrender1 libgomp1 curl \
    && rm -rf /var/lib/apt/lists/*

# Copy installed Python packages from builder
COPY --from=builder /install /usr/local

# App source
COPY main.py .
COPY index.html .

# Persistent directories for cache & data
RUN mkdir -p /app/.cache /app/data && chmod 777 /app/.cache /app/data
ENV HF_HOME=/app/.cache
ENV PYTHONUNBUFFERED=1

# Non-root user
RUN useradd -m -u 1000 user && chown -R user:user /app
USER user

# Port
EXPOSE 7860

# Health check β€” hits the /health endpoint every 30s
HEALTHCHECK --interval=30s --timeout=10s --start-period=60s --retries=3 \
    CMD curl -f http://localhost:7860/health || exit 1

# Async-ready startup: 2 workers, async event loop
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860", \
     "--workers", "1", "--loop", "asyncio", "--log-level", "info"]