# Use an official Python runtime as a parent image FROM python:3.10-slim # Set environment variables ENV PYTHONDONTWRITEBYTECODE 1 ENV PYTHONUNBUFFERED 1 ENV PORT 7860 # Install system dependencies for OpenCV and runtime RUN apt-get update && apt-get install -y \ libgl1 \ libglib2.0-0 \ libsm6 \ libxext6 \ && apt-get clean && rm -rf /var/lib/apt/lists/* # Set the working directory in the container WORKDIR /app # Copy the requirements file into the container COPY requirements.txt . # Install gunicorn for production RUN pip install --no-cache-dir gunicorn # Install any needed packages specified in requirements.txt RUN pip install --no-cache-dir -r requirements.txt # Copy the rest of the application code into the container COPY . . # Ensure upload directory exists and has permissions RUN mkdir -p uploads/face_encodings && chmod -R 777 uploads # Create a non-root user (Hugging Face requirement) RUN useradd -m -u 1000 user USER user ENV HOME=/home/user \ PATH=/home/user/.local/bin:$PATH WORKDIR $HOME/app COPY --chown=user . $HOME/app # Expose the port the app runs on EXPOSE 7860 # Define the command to run the application CMD ["gunicorn", "--bind", "0.0.0.0:7860", "app:app", "--timeout", "120"]