# Use official Python image FROM python:3.9-slim # Set working directory WORKDIR /app # Install system dependencies RUN apt-get update && apt-get install -y \ build-essential \ && rm -rf /var/lib/apt/lists/* # Create a non-root user RUN useradd -m -u 1000 user # Create cache directory with proper permissions RUN mkdir -p /home/user/.cache/huggingface && \ chown -R user:user /home/user/.cache # Set environment variables ENV PYTHONPATH=/app ENV PORT=8000 ENV TRANSFORMERS_CACHE=/home/user/.cache/huggingface ENV HF_HOME=/home/user/.cache/huggingface # Copy requirements first to leverage Docker cache COPY requirements.txt . RUN pip install --no-cache-dir -r requirements.txt # Copy the rest of the application COPY --chown=user:user . . # Create necessary directories RUN mkdir -p src/web && \ chown -R user:user /app # Switch to non-root user USER user # Expose the FastAPI port EXPOSE 8000 # Command to run the FastAPI application CMD ["uvicorn", "src.api.app:app", "--host", "0.0.0.0", "--port", "8000"]