FROM python:3.10-slim WORKDIR /app # Install dependencies for Playwright RUN apt-get update && apt-get install -y \ wget \ gnupg \ libglib2.0-0 \ libnss3 \ libnspr4 \ libatk1.0-0 \ libatk-bridge2.0-0 \ libcups2 \ libdrm2 \ libdbus-1-3 \ libxcb1 \ libxkbcommon0 \ libx11-6 \ libxcomposite1 \ libxdamage1 \ libxext6 \ libxfixes3 \ libxrandr2 \ libgbm1 \ libpango-1.0-0 \ libcairo2 \ libasound2 \ libatspi2.0-0 \ && rm -rf /var/lib/apt/lists/* # Create a non-root user and set up cache directories with proper permissions RUN useradd -m -u 1000 user && \ mkdir -p /home/user/.cache/huggingface && \ mkdir -p /home/user/.cache/torch && \ mkdir -p /home/user/.cache/sentence_transformers && \ chown -R user:user /home/user/.cache # Set environment variables for Hugging Face cache ENV HF_HOME=/home/user/.cache/huggingface ENV TRANSFORMERS_CACHE=/home/user/.cache/huggingface ENV SENTENCE_TRANSFORMERS_HOME=/home/user/.cache/sentence_transformers ENV TORCH_HOME=/home/user/.cache/torch # Copy requirements first for better caching COPY requirements.txt . RUN pip install --no-cache-dir -r requirements.txt # Install Playwright browsers RUN playwright install chromium --with-deps # Copy the rest of the application COPY . . # Set environment variables ENV PYTHONUNBUFFERED=1 ENV PORT=7860 # Switch to the non-root user USER user # Expose the port the app runs on EXPOSE 7860 # Command to run the application CMD ["python", "app.py"]