FROM python:3.11-slim ENV PYTHONUNBUFFERED=1 \ PYTHONDONTWRITEBYTECODE=1 \ PIP_NO_CACHE_DIR=1 \ DEBIAN_FRONTEND=noninteractive \ REDIS_URL=redis://localhost:6379/0 # System dependencies for the conversion tools: # redis-server -> Celery broker/result backend (runs inside the container) # tesseract-ocr -> OCR / image-to-text # libreoffice -> Word/Excel/PPT -> PDF (provides `soffice`) # poppler-utils -> PDF -> image (pdf2image) # ghostscript -> PDF compression # calibre -> eBook conversions (provides `ebook-convert`) # pandoc -> Word -> txt/html/markdown conversions # libgl1/glib -> opencv + mediapipe runtime RUN apt-get update && apt-get install -y --no-install-recommends \ redis-server \ tesseract-ocr \ libreoffice \ poppler-utils \ ghostscript \ calibre \ pandoc \ supervisor \ libgl1 \ libglib2.0-0 \ fonts-dejavu \ fonts-liberation \ curl \ && rm -rf /var/lib/apt/lists/* WORKDIR /app # Install CPU-only torch/torchvision first so pip does NOT pull the # multi-GB CUDA build that the default PyPI index would resolve to. RUN pip install --no-cache-dir torch torchvision \ --index-url https://download.pytorch.org/whl/cpu COPY requirements.txt . RUN pip install --no-cache-dir -r requirements.txt # Pre-download the lightweight rembg model at build time so the background-removal # workers never block on a runtime model fetch (which hangs on HF's network). # Best-effort: if the build network can't fetch the model, don't fail the image — # the worker just falls back to a runtime fetch. ENV U2NET_HOME=/app/.u2net RUN mkdir -p /app/.u2net \ && (python -c "from rembg import new_session; new_session('u2netp')" || echo "rembg prebake skipped") \ && chmod -R 777 /app/.u2net COPY backend/ ./backend/ COPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf # Runtime working dirs (gitignored, so they don't exist in the build context). # 777 because model libs (rembg/easyocr) and uploads need to write at runtime. RUN mkdir -p backend/uploads backend/outputs backend/temp \ && chmod -R 777 backend/uploads backend/outputs backend/temp EXPOSE 7860 # Run DB migrations once, then hand off to supervisord which runs # redis + the web server + the celery worker together. CMD ["/bin/bash", "-c", "cd /app/backend && alembic upgrade head; cd /app && exec supervisord -c /etc/supervisor/conf.d/supervisord.conf"]