| # Dockerfile for Bhagwad Gita RAG Chatbot on Hugging Face Spaces | |
| # Based on: https://huggingface.co/docs/hub/spaces-sdks-docker | |
| FROM python:3.9-slim | |
| # Set up a new user named "user" with user ID 1000 (HF Spaces requirement) | |
| RUN useradd -m -u 1000 user | |
| # Switch to the "user" user | |
| USER user | |
| # Set home to the user's home directory | |
| ENV HOME=/home/user \ | |
| PATH=/home/user/.local/bin:$PATH | |
| # Set the working directory to the user's home directory | |
| WORKDIR $HOME/app | |
| # Try and run pip command after setting the user to avoid permission issues | |
| RUN pip install --no-cache-dir --upgrade pip | |
| # Copy requirements first for better caching | |
| COPY --chown=user requirements.txt . | |
| # Install Python dependencies | |
| RUN pip install --no-cache-dir -r requirements.txt | |
| # Copy the current directory contents into the container | |
| COPY --chown=user . . | |
| # Create data directory and ensure proper permissions | |
| RUN mkdir -p dataset && chmod 755 dataset | |
| # Expose the port that HF Spaces expects (7860) | |
| EXPOSE 7860 | |
| # Set environment variables for HF Spaces | |
| ENV API_HOST=0.0.0.0 | |
| ENV API_PORT=7860 | |
| ENV ENVIRONMENT=production | |
| # Health check | |
| HEALTHCHECK --interval=30s --timeout=30s --start-period=5s --retries=3 \ | |
| CMD curl -f http://localhost:7860/health || exit 1 | |
| # Start the FastAPI application on port 7860 (HF Spaces requirement) | |
| CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"] | |