1- FROM pytorch/pytorch:2.4.0-cuda11.8-cudnn9-runtime
2- COPY --from=ghcr.io/astral-sh/uv:latest /uv /uvx /bin/
3-
4- RUN apt-get update
5- RUN apt-get install --fix-missing -y -q --no-install-recommends libgomp1 ffmpeg libsm6 pdftohtml libxext6 git ninja-build g++ qpdf pandoc curl
6-
7-
8- RUN apt-get install -y ocrmypdf
9- RUN apt-get install -y tesseract-ocr-fra
10- RUN apt-get install -y tesseract-ocr-spa
11- RUN apt-get install -y tesseract-ocr-deu
12- RUN apt-get install -y tesseract-ocr-ara
13- RUN apt-get install -y tesseract-ocr-mya
14- RUN apt-get install -y tesseract-ocr-hin
15- RUN apt-get install -y tesseract-ocr-tam
16- RUN apt-get install -y tesseract-ocr-tha
17- RUN apt-get install -y tesseract-ocr-chi-sim
18- RUN apt-get install -y tesseract-ocr-tur
19- RUN apt-get install -y tesseract-ocr-ukr
20- RUN apt-get install -y tesseract-ocr-ell
21- RUN apt-get install -y tesseract-ocr-rus
22- RUN apt-get install -y tesseract-ocr-kor
23- RUN apt-get install -y tesseract-ocr-kor-vert
24-
25-
26- RUN mkdir -p /app/src
27- RUN mkdir -p /app/models
28-
29- RUN addgroup --system python && adduser --system --group python
30- RUN chown -R python:python /app
31- USER python
1+ ARG BUILDER_IMAGE=nvidia/cuda:12.6.0-cudnn-devel-ubuntu24.04
2+ ARG TORCH_INDEX_URL=https://download.pytorch.org/whl/cu126
3+ ARG FORCE_CUDA=1
4+ ARG TORCH_CUDA_ARCH_LIST="6.1;7.0;7.5;8.0;8.6;8.9;9.0"
5+
6+ FROM ${BUILDER_IMAGE} AS builder
7+
8+ COPY --from=ghcr.io/astral-sh/uv:latest /uv /uvx /usr/local/bin/
329
33- ENV VIRTUAL_ENV=/app/.venv
34- RUN python -m venv $VIRTUAL_ENV
35- ENV PATH= "$VIRTUAL_ENV/bin:$PATH"
10+ ARG TORCH_INDEX_URL
11+ ARG FORCE_CUDA
12+ ARG TORCH_CUDA_ARCH_LIST
3613
37- COPY requirements.txt requirements.txt
38- RUN uv pip install --upgrade pip
39- RUN uv pip install \
40- -r requirements.txt \
41- --extra-index-url https://download.pytorch.org/whl/cu128 \
42- --index-strategy unsafe-best-match
14+ ENV VIRTUAL_ENV=/app/.venv \
15+ PATH="/app/.venv/bin:$PATH" \
16+ DEBIAN_FRONTEND=noninteractive \
17+ PIP_DISABLE_PIP_VERSION_CHECK=1 \
18+ FORCE_CUDA=${FORCE_CUDA} \
19+ TORCH_CUDA_ARCH_LIST=${TORCH_CUDA_ARCH_LIST}
20+
21+ RUN apt-get update && \
22+ apt-get install -y --no-install-recommends \
23+ ca-certificates \
24+ python3.12 \
25+ python3.12-venv \
26+ python3.12-dev \
27+ git \
28+ ninja-build \
29+ g++ \
30+ && rm -rf /var/lib/apt/lists/*
4331
4432WORKDIR /app
4533
46- RUN cd src; git clone https://github.com/facebookresearch/detectron2;
47- RUN cd src/detectron2; git checkout b599f139756bd3646a26a909caf86a1a159e53a7; python setup.py build develop
48- RUN uv pip install pycocotools==2.0.11
34+ RUN python3.12 -m venv "$VIRTUAL_ENV"
4935
50- COPY ./start.sh ./start.sh
51- COPY ./src/. ./src
52- COPY ./models/. ./models/
53- RUN python src/download_models.py
36+ COPY requirements.txt .
37+
38+ RUN uv pip install --no-cache --python "$VIRTUAL_ENV/bin/python" \
39+ --extra-index-url "${TORCH_INDEX_URL}" \
40+ --index-strategy unsafe-best-match \
41+ -r requirements.txt
42+
43+ RUN git init /tmp/detectron2 && \
44+ cd /tmp/detectron2 && \
45+ git remote add origin https://github.com/facebookresearch/detectron2 && \
46+ git fetch --depth 1 origin b599f139756bd3646a26a909caf86a1a159e53a7 && \
47+ git checkout FETCH_HEAD && \
48+ uv pip install --no-cache --no-build-isolation \
49+ --python "$VIRTUAL_ENV/bin/python" . && \
50+ rm -rf /tmp/detectron2
51+
52+ RUN uv pip install --no-cache --python "$VIRTUAL_ENV/bin/python" pycocotools==2.0.11
53+
54+
55+ FROM ubuntu:24.04 AS runtime
5456
55- ENV PYTHONPATH "${PYTHONPATH}:/app/src"
56- ENV TRANSFORMERS_VERBOSITY=error
57- ENV TRANSFORMERS_NO_ADVISORY_WARNINGS=1
57+ ENV VIRTUAL_ENV=/app/.venv \
58+ PATH="/app/.venv/bin:$PATH" \
59+ HF_HOME=/app/models/.cache/huggingface \
60+ PYTHONPATH=/app/src \
61+ PYTHONUNBUFFERED=1 \
62+ TRANSFORMERS_VERBOSITY=error \
63+ TRANSFORMERS_NO_ADVISORY_WARNINGS=1 \
64+ DEBIAN_FRONTEND=noninteractive \
65+ NVIDIA_VISIBLE_DEVICES=all \
66+ NVIDIA_DRIVER_CAPABILITIES=compute,utility
67+
68+ RUN apt-get update && \
69+ apt-get install -y --no-install-recommends \
70+ adduser \
71+ ca-certificates \
72+ python3.12 \
73+ ffmpeg \
74+ libgomp1 \
75+ libsm6 \
76+ libxext6 \
77+ ocrmypdf \
78+ pandoc \
79+ pdftohtml \
80+ qpdf \
81+ tesseract-ocr-ara \
82+ tesseract-ocr-chi-sim \
83+ tesseract-ocr-deu \
84+ tesseract-ocr-ell \
85+ tesseract-ocr-fra \
86+ tesseract-ocr-hin \
87+ tesseract-ocr-kor \
88+ tesseract-ocr-kor-vert \
89+ tesseract-ocr-mya \
90+ tesseract-ocr-rus \
91+ tesseract-ocr-spa \
92+ tesseract-ocr-tam \
93+ tesseract-ocr-tha \
94+ tesseract-ocr-tur \
95+ tesseract-ocr-ukr \
96+ && rm -rf /var/lib/apt/lists/*
97+
98+ RUN mkdir -p /app/src /app/models && \
99+ addgroup --system python && \
100+ adduser --system --group --home /app python && \
101+ chown -R python:python /app
102+
103+ WORKDIR /app
104+
105+ COPY --from=builder --chown=python:python /app/.venv /app/.venv
106+ COPY --chown=python:python --chmod=755 ./start.sh ./start.sh
107+ COPY --chown=python:python ./src/download_models.py ./src/download_models.py
108+ COPY --chown=python:python ./src/configuration.py ./src/configuration.py
109+
110+ USER python
111+
112+ RUN python src/download_models.py
113+ COPY --chown=python:python ./src/. ./src
0 commit comments