FROM mcr.microsoft.com/playwright/python:v1.40.0-jammy # Set environment variables ENV PYTHONDONTWRITEBYTECODE 1 ENV PYTHONUNBUFFERED 1 ENV PORT 7860 # Create a non-root user RUN useradd -m -u 1000 user # Install system dependencies as root RUN apt-get update && apt-get install -y \ xvfb \ libnss3 \ libatk-bridge2.0-0 \ libgtk-3-0 \ libasound2 \ && rm -rf /var/lib/apt/lists/* # Set working directory WORKDIR /app # Copy requirements and install dependencies COPY --chown=user requirements.txt . RUN pip install --no-cache-dir -r requirements.txt RUN playwright install chromium # Switch to the non-root user USER user ENV PATH="/home/user/.local/bin:$PATH" # Copy the rest of the application code COPY --chown=user . . # Expose the port EXPOSE 7860 # Command to run the application CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "7860", "--workers", "1"]