IL_CMS_Tools / Dockerfile
sahil-12kumar's picture
Update Dockerfile
5458a04 verified
Raw History Blame Contribute Delete
2.52 kB
# IL Web App — Hugging Face Spaces (Docker SDK) image.
# Single persistent process (Flask threaded) so the in-memory job state used by
# the uploader/tagger/PPT background threads stays valid.
FROM python:3.11-slim
# IL_USAGE_SOURCE labels this process in the shared usage table. Without it
# il_shared_usage falls back to "local", so Space runs were indistinguishable
# from a developer's laptop in the dashboard and on /history.
ENV PORT=7860 \
PYTHONUNBUFFERED=1 \
PIP_NO_CACHE_DIR=1 \
IL_USAGE_SOURCE=space
WORKDIR /app
# Install system deps needed by Chromium first (fast, small layer).
RUN apt-get update -qq && \
apt-get install -y --no-install-recommends \
libnss3 libatk-bridge2.0-0 libx11-xcb1 libxcomposite1 \
libxdamage1 libxrandr2 libgbm1 libasound2t64 libpango-1.0-0 \
libcairo2 libatspi2.0-0 libgtk-3-0 libdrm2 libxshmfence1 \
fonts-liberation libappindicator3-1 xdg-utils wget && \
rm -rf /var/lib/apt/lists/*
# Install Python deps first for better layer caching.
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
# Chromium browser for the tagger and PPT MathJax rendering.
# The OS deps above satisfy --with-deps so this is fast (browser binary only).
RUN playwright install --with-deps chromium
# App source (secrets/token files are excluded via .dockerignore).
#
# NOTE: this image has no Microsoft Office, so Word equations convert only because
# backend/vendor/OMML2MML.XSL is committed and lands here via this COPY (see
# backend/vendor/README.md). Parsing is server-side, so Office on the SME's laptop
# does not help. Without the file the uploader flags every .docx equation as
# unconvertible rather than storing "[FORMULA]" in the CMS, blocking papers that
# contain maths.
COPY . .
EXPOSE 7860
# gunicorn, not `python app.py` — app.run() is Werkzeug's development server.
#
# --workers 1 is REQUIRED, not a tuning choice: the uploader/tagger/PPT job
# stores and the CMS credential store all live in process memory, so a second
# worker would serve requests that can't see the first worker's jobs or logins.
# Scale with --threads instead. --timeout 300 covers long parse/upload requests.
# --chdir backend: the Flask app and its sibling modules live in backend/ (with
# frontend/ and database/ resolved relative to it), so import from there.
CMD ["gunicorn", "--workers", "1", "--threads", "8", "--timeout", "300", \
"--chdir", "backend", \
"--access-logfile", "-", "--bind", "0.0.0.0:7860", "app:app"]