# Multi-stage build for optimized image size FROM python:3.11-slim as builder # Set working directory WORKDIR /app # Install system dependencies for building RUN apt-get update && apt-get install -y \ gcc \ g++ \ && rm -rf /var/lib/apt/lists/* # Copy requirements (Linux-compatible version) COPY requirements-docker.txt ./requirements.txt # Upgrade pip and install Python dependencies RUN pip install --upgrade pip RUN pip install --no-cache-dir --user -r requirements.txt # Final stage FROM python:3.11-slim # Set environment variables ENV PYTHONDONTWRITEBYTECODE=1 \ PYTHONUNBUFFERED=1 \ PATH=/root/.local/bin:$PATH # Set working directory WORKDIR /app # Install runtime dependencies RUN apt-get update && apt-get install -y \ curl \ && rm -rf /var/lib/apt/lists/* # Copy Python packages from builder COPY --from=builder /root/.local /root/.local # Copy application code COPY app/ ./app/ COPY main.py . COPY requirements-docker.txt ./requirements.txt # Copy models configuration file COPY models_config.yaml . # Create directories for models and cache (will be mounted as volumes) RUN mkdir -p /app/models /app/.cache/huggingface # Set Hugging Face cache directory ENV HF_HOME=/app/.cache/huggingface ENV TRANSFORMERS_CACHE=/app/.cache/huggingface ENV SENTENCE_TRANSFORMERS_HOME=/app/.cache/huggingface # Health check HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \ CMD curl -f http://localhost:5200/health || exit 1 # Expose port EXPOSE 5200 # Run the application CMD ["python", "main.py"]