FROM python:3.11-slim # Set working directory WORKDIR /app # Install system dependencies RUN apt-get update && apt-get install -y \ curl \ wget \ gnupg \ chromium \ chromium-sandbox \ fonts-liberation \ fonts-noto \ fonts-noto-cjk \ libasound2 \ libatk-bridge2.0-0 \ libatk1.0-0 \ libcups2 \ libdbus-1-3 \ libdrm2 \ libgbm1 \ libgtk-3-0 \ libnspr4 \ libnss3 \ libxcomposite1 \ libxdamage1 \ libxfixes3 \ libxkbcommon0 \ libxrandr2 \ xdg-utils \ && rm -rf /var/lib/apt/lists/* # Install Node.js 20 RUN curl -fsSL https://deb.nodesource.com/setup_20.x | bash - && \ apt-get install -y nodejs && \ rm -rf /var/lib/apt/lists/* # Create user (required for HF Spaces) RUN useradd -m -u 1000 user # Copy dependency files COPY --chown=user requirements.txt package.json ./ # Install Python and Node dependencies RUN pip install --no-cache-dir -r requirements.txt RUN npm install # Copy application files and the startup script COPY --chown=user app.py puppeteer_pdf.js ./ COPY --chown=user start.sh ./ # Make scripts executable RUN chmod +x puppeteer_pdf.js RUN chmod +x start.sh # Set permissions RUN mkdir -p /tmp && chmod 777 /tmp # Switch to user USER user # Environment variables ENV HOME=/home/user \ PATH=/home/user/.local/bin:$PATH \ PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=true \ PUPPETEER_EXECUTABLE_PATH=/usr/bin/chromium \ PYTHONUNBUFFERED=1 # Expose port EXPOSE 7860 # Start application using the script CMD ["./start.sh"]