# Use an official Python runtime with Playwright dependencies already installed FROM mcr.microsoft.com/playwright/python:v1.43.0-jammy # 1. We start as root to install packages and copy files USER root WORKDIR /app # Copy requirements and install COPY requirements.txt . RUN pip install --no-cache-dir -r requirements.txt RUN pip install gunicorn # Ensure playwright browsers are installed RUN playwright install chromium # Copy all application files COPY . . # Ensure output directory exists and is writable RUN mkdir -p /app/lead_gen/output && chmod 777 -R /app/lead_gen/output # Give ownership of /app to UID 1000 (The user Hugging Face Forces) RUN chown -R 1000:1000 /app # 2. Switch to the non-root user (UID 1000) required by Hugging Face # In this Playwright base image, UID 1000 already belongs to 'pwuser', so we don't need useradd. USER 1000 # Set environment variables for the Hugging Face Space port (7860) ENV PYTHONUNBUFFERED=1 ENV PORT=7860 # Expose the mandatory Hugging Face port EXPOSE 7860 # Switch to the app's python directory WORKDIR /app/lead_gen # Start Gunicorn binding to port 7860 CMD ["gunicorn", "--bind", "0.0.0.0:7860", "--workers", "2", "--threads", "4", "--worker-class", "gthread", "--timeout", "120", "wsgi:app"]