Spaces:
Sleeping
Sleeping
| # Multi-stage Dockerfile for RAG Terminal Application | |
| # Optimized for production deployment with CPU-only PyTorch | |
| # Stage 1: Builder - Install dependencies | |
| FROM python:3.12-slim AS builder | |
| # Set working directory | |
| WORKDIR /app | |
| # Install system dependencies for PDF processing | |
| RUN apt-get update && apt-get install -y --no-install-recommends \ | |
| build-essential \ | |
| && rm -rf /var/lib/apt/lists/* | |
| # Copy requirements file | |
| COPY requirements.txt . | |
| # Create virtual environment and install Python dependencies | |
| RUN python -m venv /opt/venv | |
| ENV PATH="/opt/venv/bin:$PATH" | |
| # Install dependencies with CPU-only PyTorch to save space | |
| RUN pip install --no-cache-dir --upgrade pip && \ | |
| pip install --no-cache-dir -r requirements.txt && \ | |
| pip install --no-cache-dir torch --index-url https://download.pytorch.org/whl/cpu | |
| # Stage 2: Runtime - Create minimal production image | |
| FROM python:3.12-slim | |
| # Set working directory | |
| WORKDIR /app | |
| # Install runtime dependencies only | |
| RUN apt-get update && apt-get install -y --no-install-recommends \ | |
| curl \ | |
| && rm -rf /var/lib/apt/lists/* | |
| # Copy virtual environment from builder | |
| COPY --from=builder /opt/venv /opt/venv | |
| ENV PATH="/opt/venv/bin:$PATH" | |
| # Copy application code | |
| COPY ./app/ . | |
| # Create directories for data persistence | |
| RUN mkdir -p ./rag_data ./.embedding_cache | |
| # Set environment variables | |
| ENV PYTHONUNBUFFERED=1 | |
| ENV GRADIO_SERVER_NAME=0.0.0.0 | |
| ENV GRADIO_SERVER_PORT=7860 | |
| # Expose Gradio port | |
| EXPOSE 7860 | |
| # Health check | |
| HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \ | |
| CMD curl -f http://localhost:7860/ || exit 1 | |
| # Default command: run the RAG application | |
| CMD ["python", "app.py"] | |