# ── Vibhu Solutions AI Agent — HuggingFace Spaces Dockerfile ── FROM python:3.11-slim # Python flags: unbuffered logs, no .pyc files ENV PYTHONUNBUFFERED=1 \ PYTHONDONTWRITEBYTECODE=1 # Create non-root user (HuggingFace Spaces requires UID 1000) RUN useradd -m -u 1000 user WORKDIR /app # Install system dependencies as root RUN apt-get update && apt-get install -y \ build-essential \ curl \ && rm -rf /var/lib/apt/lists/* # Upgrade pip, then install Python dependencies (system-wide as root) COPY requirements.txt . RUN pip install --upgrade pip && \ pip install --no-cache-dir -r requirements.txt # Copy project files directly owned by user (faster than separate chown step) COPY --chown=user:user . . # Give user write access to the workdir so ingest.py can create faiss_db/ RUN chown user:user /app # Switch to non-root user BEFORE ingest so: # 1. HuggingFace model cache lands in /home/user/.cache (accessible at runtime) # 2. faiss_db/ is created & owned by user (writable at runtime) USER user ENV HOME=/home/user \ HF_HOME=/home/user/.cache/huggingface \ PORT=7860 # Build FAISS vector index from knowledge base RUN python ingest.py EXPOSE 7860 # Health check — verifies the server is up and responding HEALTHCHECK --interval=30s --timeout=10s --start-period=45s --retries=3 \ CMD curl -f http://localhost:7860/health || exit 1 # Start the AI Agent CMD ["python", "app.py"]