File size: 2,517 Bytes
82a25a8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8dc56de
82a25a8
 
 
 
 
 
 
 
8dc56de
82a25a8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1b505f3
 
6316f15
 
1b505f3
6316f15
 
1b505f3
 
82a25a8
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
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"]