FROM python:3.10-slim # Set working directory WORKDIR /app # Install system dependencies RUN apt-get update && apt-get install -y \ build-essential \ curl \ git \ && rm -rf /var/lib/apt/lists/* # Copy requirements first for better caching COPY requirements.txt . # Install Python dependencies RUN pip install --no-cache-dir --upgrade pip && \ pip install --no-cache-dir -r requirements.txt # Copy application code COPY . . # Create cache directory for models RUN mkdir -p /app/.cache/models # Download the model during build to cache it RUN python -c "from sentence_transformers import CrossEncoder; CrossEncoder('cross-encoder/ms-marco-MiniLM-L-6-v2', cache_folder='/app/.cache/models')" # Create a non-root user to run the application RUN useradd -m -u 1000 appuser && \ chown -R appuser:appuser /app # Switch to non-root user USER appuser # Expose port EXPOSE 8080 # Set environment variables ENV PYTHONUNBUFFERED=1 ENV MODEL_CACHE_DIR=/app/.cache/models # Health check HEALTHCHECK --interval=30s --timeout=10s --start-period=40s --retries=3 \ CMD curl -f http://localhost:8080/health || exit 1 # Run the application CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "8080", "--workers", "1"]