# Dockerfile for Hugging Face Spaces deployment # AikoDiary Backend - Mental Health Journaling API FROM python:3.10-slim # Install system dependencies for OpenCV and other packages RUN apt-get update && apt-get install -y \ libgl1 \ libglib2.0-0 \ libsm6 \ libxext6 \ libxrender-dev \ libgomp1 \ && rm -rf /var/lib/apt/lists/* # Set working directory WORKDIR /app # Create a non-root user for security (required by HF Spaces) RUN useradd -m -u 1000 user USER user ENV HOME=/home/user \ PATH=/home/user/.local/bin:$PATH # Copy requirements first for better caching COPY --chown=user:user 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 --chown=user:user . . # Hugging Face Spaces uses port 7860 ENV PORT=7860 EXPOSE 7860 # Set environment variables for production ENV PYTHONUNBUFFERED=1 ENV FLASK_ENV=production # Health check HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \ CMD python -c "import requests; requests.get('http://localhost:7860/health')" || exit 1 # Run the application with gunicorn for production CMD ["gunicorn", "--bind", "0.0.0.0:7860", "--workers", "2", "--timeout", "120", "app:app"]