# ============================================================================== # CropAI Hugging Face Spaces Production Dockerfile # Optimized for Hugging Face Spaces Free Tier (2 vCPU, 16 GB RAM, Port 7860) # User UID 1000 required by Hugging Face Spaces security sandbox # ============================================================================== FROM python:3.11-slim # Create Hugging Face default non-root user (UID 1000) RUN useradd -m -u 1000 user WORKDIR /app ENV PYTHONUNBUFFERED=1 \ PYTHONDONTWRITEBYTECODE=1 \ PORT=7860 \ HOST=0.0.0.0 \ APP_ENV=production # Install OS libraries for Pillow and native builds RUN apt-get update && apt-get install -y --no-install-recommends \ build-essential \ libjpeg-dev \ zlib1g-dev \ curl \ && rm -rf /var/lib/apt/lists/* # Install Python packages COPY backend/requirements.txt /app/requirements.txt RUN pip install --no-cache-dir --upgrade pip && \ pip install --no-cache-dir -r /app/requirements.txt # Copy entire backend source code COPY backend /app/backend # Grant ownership to non-root user RUN chown -R user:user /app USER user EXPOSE 7860 # Healthcheck HEALTHCHECK --interval=30s --timeout=10s --start-period=15s --retries=3 \ CMD curl -f http://localhost:7860/health || exit 1 # Start FastAPI application on Port 7860 CMD ["uvicorn", "backend.main:app", "--host", "0.0.0.0", "--port", "7860"]