FROM python:3.11-slim # Install system dependencies, headless LibreOffice, and common fonts RUN apt-get update && apt-get install -y --no-install-recommends \ libreoffice-writer \ libreoffice-calc \ libreoffice-impress \ libreoffice-java-common \ python3-uno \ fonts-liberation \ fonts-dejavu \ procps \ && rm -rf /var/lib/apt/lists/* # Set up a non-root user for Hugging Face Spaces compliance RUN useradd -m -u 1000 user USER user ENV HOME=/home/user \ PATH=/home/user/.local/bin:$PATH # Map the system UNO python packages into our pythonpath runtime environment ENV PYTHONPATH=/usr/lib/python3/dist-packages:$PYTHONPATH WORKDIR /app # Install Python requirements COPY --chown=user requirements.txt . RUN pip install --no-cache-dir --user -r requirements.txt # Copy backend application COPY --chown=user app.py . # Pre-build workspace folders RUN mkdir -p /home/user/uploads /home/user/outputs # Hugging Face default application interface port EXPOSE 7860 # We run the unoserver background listener explicitly using python3 to avoid binary mismatches, # and use an ampersand (&) instead of --daemon so it logs errors properly if it fails. # We explicitly separate the listener port (2002) and the internal LibreOffice control port (2003) CMD ["bash", "-c", "python3 -m unoserver.server --interface 127.0.0.1 --port 2002 --uno-port 2003 & sleep 4 && gunicorn --bind 0.0.0.0:7860 --workers 4 --timeout 120 app:app"]