File size: 1,413 Bytes
9f42118
6f3c32c
9f42118
 
 
 
 
 
 
6f3c32c
3b42478
 
9f42118
 
 
6f3c32c
 
9f42118
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
a62f06e
9f42118
 
a62f06e
9f42118
 
a62f06e
9f42118
 
 
6f3c32c
9f42118
 
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
FROM python:3.11-slim

# Set environment variables for cache directories
ENV TRANSFORMERS_CACHE=/tmp/transformers_cache
ENV HF_HOME=/tmp/huggingface_cache
ENV TORCH_HOME=/tmp/torch_cache
ENV PYTHONPATH=/app

# Install system dependencies
RUN apt-get update && apt-get install -y \
    tesseract-ocr \
    tesseract-ocr-eng \
    libtesseract-dev \
    poppler-utils \
    curl \
    && rm -rf /var/lib/apt/lists/*

# Create cache directories with proper permissions
RUN mkdir -p /tmp/transformers_cache /tmp/huggingface_cache /tmp/torch_cache && \
    chmod -R 777 /tmp/transformers_cache /tmp/huggingface_cache /tmp/torch_cache

WORKDIR /app

# Copy requirements and install dependencies
COPY requirements.txt .
RUN pip install --no-cache-dir --upgrade pip && \
    pip install --no-cache-dir -r requirements.txt

# Copy application files
COPY . .

# Set proper permissions for the app directory
RUN chmod -R 755 /app

# Create a non-root user for security
RUN useradd -m -u 1000 appuser && \
    chown -R appuser:appuser /app /tmp/transformers_cache /tmp/huggingface_cache /tmp/torch_cache

# Switch to non-root user
USER appuser

# Expose port
EXPOSE 7860

# Health check
HEALTHCHECK --interval=30s --timeout=30s --start-period=120s --retries=3 \
    CMD curl -f http://localhost:7860/health || exit 1

# Run the application
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860", "--workers", "1"]