# Use a compatible Python base image FROM python:3.9-slim-bookworm # Set the working directory inside the container WORKDIR /app # Update package lists and install all system dependencies RUN apt-get update && apt-get install -y --no-install-recommends \ wget \ fontconfig \ libjpeg62-turbo \ libxext6 \ xfonts-75dpi \ xfonts-base \ libxrender1 \ libssl3 \ && apt-get clean \ && rm -rf /var/lib/apt/lists/* # Download and install the wkhtmltox package RUN wget https://github.com/wkhtmltopdf/packaging/releases/download/0.12.6.1-3/wkhtmltox_0.12.6.1-3.bookworm_amd64.deb && \ dpkg -i wkhtmltox_0.12.6.1-3.bookworm_amd64.deb && \ rm wkhtmltox_0.12.6.1-3.bookworm_amd64.deb # Create non-root user as required by HF Spaces RUN useradd -m -u 1000 user # Copy application files (before switching user) COPY requirements.txt . RUN pip install --no-cache-dir -r requirements.txt # Switch to non-root user and set environment USER user ENV HOME=/home/user \ PATH=/home/user/.local/bin:$PATH # Copy app code with proper ownership COPY --chown=1000:1000 app.py . # Expose the port EXPOSE 7860 # Run with gunicorn CMD ["gunicorn", "--bind", "0.0.0.0:7860", "app:app"]