-
-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathDockerfile
More file actions
104 lines (91 loc) · 3.95 KB
/
Copy pathDockerfile
File metadata and controls
104 lines (91 loc) · 3.95 KB
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# Overridable so the INSTALL_INTEL_GPU build can pin an older Debian. The
# default stays on the floating tag (currently trixie) because the arm64 Coral
# runtime installed below is a trixie .deb; INSTALL_INTEL_GPU needs
# intel-opencl-icd, which trixie dropped, so that build must pass
# --build-arg BASE_IMAGE=python:3.11-slim-bookworm. The two are mutually
# exclusive, which is harmless in practice: Intel iGPU builds are never arm64.
ARG BASE_IMAGE=python:3.11-slim
FROM ${BASE_IMAGE}
ENV PYTHONDONTWRITEBYTECODE=1 \
PYTHONUNBUFFERED=1 \
PIP_DISABLE_PIP_VERSION_CHECK=1 \
PIP_NO_CACHE_DIR=1
WORKDIR /app
# Minimal runtime libs for opencv-python on slim images + feranick's maintained
# Coral Edge TPU runtime for Debian trixie (arm64)
# See: https://github.com/feranick/libedgetpu/releases
ARG TARGETARCH
RUN apt-get update \
&& apt-get install -y --no-install-recommends \
libgl1 \
libglib2.0-0 \
curl \
wget \
libusb-1.0-0 \
&& if [ "${TARGETARCH}" = "arm64" ]; then \
wget -q https://github.com/feranick/libedgetpu/releases/download/16.0TF2.19.1-1/libedgetpu1-std_16.0tf2.19.1-1.trixie_arm64.deb; \
dpkg -i libedgetpu1-std_16.0tf2.19.1-1.trixie_arm64.deb; \
rm libedgetpu1-std_16.0tf2.19.1-1.trixie_arm64.deb; \
fi \
&& rm -rf /var/lib/apt/lists/*
# Which ONNX Runtime wheel to install. These are mutually exclusive drop-in
# replacements for each other, so pick exactly one:
# onnxruntime CPU only (default)
# onnxruntime-openvino Intel CPU / iGPU / NPU via the OpenVINO provider
# onnxruntime-gpu NVIDIA CUDA
# Usage: docker build --build-arg ONNXRUNTIME_PACKAGE=onnxruntime-openvino ...
ARG ONNXRUNTIME_PACKAGE=onnxruntime
# Core Python deps (ONNX is now the default backend)
COPY Pipfile Pipfile.lock ./
RUN python -m pip install --upgrade pip \
&& python -m pip install \
fastapi \
uvicorn \
python-multipart \
pydantic \
pydantic-settings \
pillow \
exceptiongroup \
"numpy<2.0" \
"$ONNXRUNTIME_PACKAGE" \
opencv-python \
scipy \
shapely
# Install tflite-runtime for Coral Edge TPU support
# Compatible with feranick's libedgetpu 16.0TF2.19.1-1
RUN pip install tflite-runtime==2.14.0
# Optional: Intel GPU userspace driver, required for OpenVINO's GPU device.
# The OpenVINO wheel ships the GPU plugin but still needs the host OpenCL
# driver to see /dev/dri; without it OpenVINO silently falls back to CPU.
# Usage: docker build --build-arg INSTALL_INTEL_GPU=1 ...
ARG INSTALL_INTEL_GPU=0
RUN if [ "$INSTALL_INTEL_GPU" = "1" ]; then \
apt-get update \
&& { apt-get install -y --no-install-recommends intel-opencl-icd clinfo \
|| { echo "ERROR: intel-opencl-icd is not in this base image's repos."; \
echo "Debian trixie dropped it — build with"; \
echo " --build-arg BASE_IMAGE=python:3.11-slim-bookworm"; \
exit 1; }; } \
&& rm -rf /var/lib/apt/lists/*; \
fi
# Optional: install tensorflow for tflite backend support
# Usage: docker build --build-arg INSTALL_TENSORFLOW=1 ...
ARG INSTALL_TENSORFLOW=0
RUN if [ "$INSTALL_TENSORFLOW" = "1" ]; then python -m pip install tensorflow; fi
# Optional: install moondream (torch + transformers) for VLM backend
# Usage: docker build --build-arg INSTALL_MOONDREAM=1 ...
ARG INSTALL_MOONDREAM=0
RUN if [ "$INSTALL_MOONDREAM" = "1" ]; then \
python -m pip install \
"transformers>=4.51.1,<5.0" \
"torch>=2.7.0" \
"accelerate>=1.10.0"; \
fi
COPY . .
# Optionally bake the TFLite model (only useful if tensorflow is installed)
# Usage: docker build --build-arg DOWNLOAD_DEFAULT_MODEL=1 ...
ARG DOWNLOAD_DEFAULT_MODEL=0
RUN if [ "$DOWNLOAD_DEFAULT_MODEL" = "1" ]; then python scripts/download_model.py; fi
EXPOSE 8000
# .env is optional; Unraid can mount it to /app/.env
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000"]