FROM python:3.11-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/* # Set environment variables ENV PYTHONUNBUFFERED=1 \ PYTHONDONTWRITEBYTECODE=1 \ PIP_NO_CACHE_DIR=1 \ PIP_DISABLE_PIP_VERSION_CHECK=1 \ TRANSFORMERS_CACHE=/app/.cache \ HF_HOME=/app/.cache # Copy requirements first (for caching) COPY requirements.txt . # Upgrade pip and install dependencies RUN pip install --upgrade pip setuptools wheel && \ pip install --no-cache-dir -r requirements.txt # Copy project files COPY step2_load_model.py step3_encode_dataset.py step5_api.py ./ COPY dataset ./dataset COPY startup.sh ./ # Create necessary directories RUN mkdir -p models artifacts .cache # Make startup script executable RUN chmod +x startup.sh # Pre-download model and encode dataset (optional, comment out if build times out) # RUN python step2_load_model.py && python step3_encode_dataset.py # Expose port EXPOSE 7860 # Health check with longer startup period HEALTHCHECK --interval=30s --timeout=10s --start-period=300s --retries=3 \ CMD curl -f http://localhost:7860/health || exit 1 # Run the API CMD ["./startup.sh"]