File size: 2,133 Bytes
05b3396
e8051be
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
FROM python:3.10-slim

# Set working directory
WORKDIR /app

# Install system dependencies for multi-format document processing
RUN apt-get update && apt-get install -y \
    curl \
    libgl1-mesa-glx \
    libglib2.0-0 \
    libsm6 \
    libxext6 \
    libxrender-dev \
    libgomp1 \
    libgstreamer1.0-0 \
    libavcodec-dev \
    libavformat-dev \
    libswscale-dev \
    && rm -rf /var/lib/apt/lists/*

# Create cache directories with proper permissions before copying files
RUN mkdir -p /app/.cache/huggingface && \
    mkdir -p /app/.cache/sentence_transformers && \
    chmod -R 777 /app/.cache

# Set environment variables for HuggingFace cache (before installing packages)
ENV HF_HOME=/app/.cache/huggingface
ENV TRANSFORMERS_CACHE=/app/.cache/huggingface
ENV SENTENCE_TRANSFORMERS_HOME=/app/.cache/sentence_transformers
ENV HF_HUB_CACHE=/app/.cache/huggingface

# Copy requirements first for better Docker layer caching
COPY requirements.txt .

# Install Python dependencies
RUN pip install --no-cache-dir -r requirements.txt

# Copy application files AND folder structure
COPY *.py ./
COPY *.sh ./
COPY requirements.txt ./
COPY *.md ./
COPY api/ ./api/
COPY config/ ./config/
COPY LLM/ ./LLM/
COPY RAG/ ./RAG/
COPY logger/ ./logger/
COPY preprocessing/ ./preprocessing/

# Set up directories and permissions during build (when we have root access)
RUN mkdir -p /app/.cache/huggingface && \
    mkdir -p /app/.cache/sentence_transformers && \
    chmod -R 777 /app/.cache && \
    chmod +x startup.sh && \
    if [ -d "RAG/rag_embeddings" ]; then \
        find RAG/rag_embeddings -name "*.lock" -delete 2>/dev/null || true; \
        find RAG/rag_embeddings -name "*.db-shm" -delete 2>/dev/null || true; \
        find RAG/rag_embeddings -name "*.db-wal" -delete 2>/dev/null || true; \
        chmod -R 755 RAG/rag_embeddings; \
    fi

# Expose port
EXPOSE 7860

# Set environment variables
ENV HOST=0.0.0.0
ENV PORT=7860

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

# Run the application
CMD ["bash", "startup.sh"]