HonestAI / Dockerfile
JatsTheAIGen's picture
Security Enhancements: Production WSGI, Rate Limiting, Security Headers, Secure Logging
79ea999
raw
history blame
1.4 kB
# Dockerfile for Hugging Face Spaces
# Based on HF Spaces Docker SDK documentation: https://huggingface.co/docs/hub/spaces-sdks-docker
FROM python:3.10-slim
# Set working directory
WORKDIR /app
# Install system dependencies
RUN apt-get update && apt-get install -y \
gcc \
g++ \
cmake \
libopenblas-dev \
libomp-dev \
curl \
&& rm -rf /var/lib/apt/lists/*
# Copy requirements file first (for better caching)
COPY requirements.txt .
# Install Python dependencies
RUN pip install --no-cache-dir --upgrade pip && \
pip install --no-cache-dir -r requirements.txt
# Copy application code
COPY . .
# Expose port 7860 (HF Spaces standard)
EXPOSE 7860
# Set environment variables
ENV PYTHONUNBUFFERED=1
ENV PORT=7860
# Set OMP_NUM_THREADS to valid integer (not empty string)
ENV OMP_NUM_THREADS=4
ENV MKL_NUM_THREADS=4
ENV DB_PATH=/tmp/sessions.db
ENV FAISS_INDEX_PATH=/tmp/embeddings.faiss
ENV LOG_DIR=/tmp/logs
ENV RATE_LIMIT_ENABLED=true
# Health check
HEALTHCHECK --interval=30s --timeout=30s --start-period=120s --retries=3 \
CMD curl -f http://localhost:7860/api/health || exit 1
# Run with Gunicorn production WSGI server (replaces Flask dev server)
CMD ["gunicorn", "--bind", "0.0.0.0:7860", "--workers", "4", "--threads", "2", "--timeout", "120", "--access-logfile", "-", "--error-logfile", "-", "--log-level", "info", "flask_api_standalone:app"]