forked from opendatahub-io/MLServer
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
92 lines (76 loc) · 2.95 KB
/
Dockerfile
File metadata and controls
92 lines (76 loc) · 2.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
ARG BUILDER_BASE_IMAGE="python:3.12-slim"
ARG RUNTIME_BASE_IMAGE="registry.access.redhat.com/ubi9/ubi-minimal"
ARG RUNTIMES="lightgbm onnx sklearn xgboost"
FROM ${BUILDER_BASE_IMAGE} AS wheel-builder
ARG RUNTIMES
ARG POETRY_VERSION="2.1.1"
WORKDIR /opt/mlserver
COPY ./hack/build-wheels.sh ./hack/build-wheels.sh
COPY ./mlserver ./mlserver
COPY ./runtimes ./runtimes
COPY \
pyproject.toml \
poetry.lock \
README.md \
./
# Install Poetry, build wheels and export constraints.txt file
RUN pip install poetry==$POETRY_VERSION && \
pip install poetry-plugin-export && \
./hack/build-wheels.sh /opt/mlserver/dist "$RUNTIMES" && \
poetry export --with all-runtimes \
--without-hashes \
--format constraints.txt \
-o /opt/mlserver/dist/constraints.txt
FROM ${RUNTIME_BASE_IMAGE}
ARG RUNTIMES
ARG PYTHON_VERSION=3.12
# Set a few default environment variables, including `LD_LIBRARY_PATH`
# (required to use GKE's injected CUDA libraries).
# NOTE: When updating between major Python versions, update the PYTHON_VERSION ARG above.
ENV MLSERVER_MODELS_DIR=/mnt/models \
MLSERVER_ENV_TARBALL=/mnt/models/environment.tar.gz \
MLSERVER_PATH=/opt/mlserver \
PATH=/opt/mlserver/.local/bin:$PATH \
LD_LIBRARY_PATH=/usr/local/nvidia/lib64:/usr/local/lib/python${PYTHON_VERSION}/site-packages/nvidia/nccl/lib/:$LD_LIBRARY_PATH \
HF_HOME=/opt/mlserver/.cache \
NUMBA_CACHE_DIR=/opt/mlserver/.cache
# Install some base dependencies required for some libraries
RUN microdnf update -y && \
microdnf install -y \
tar \
gzip \
libgomp \
mesa-libGL \
glib2-devel \
shadow-utils \
python${PYTHON_VERSION} \
python${PYTHON_VERSION}-devel \
python${PYTHON_VERSION}-pip \
gcc && \
microdnf clean all
WORKDIR /opt/mlserver
# Create user and fix permissions
# NOTE: We need to make /opt/mlserver world-writable so that the image is
# compatible with random UIDs.
RUN mkdir -p $MLSERVER_PATH && \
useradd -u 1000 -s /bin/bash mlserver -d $MLSERVER_PATH && \
chown -R 1000:0 $MLSERVER_PATH && \
chmod -R 776 $MLSERVER_PATH
COPY --from=wheel-builder /opt/mlserver/dist ./dist
RUN ln -sf /usr/bin/python${PYTHON_VERSION} /usr/bin/python3 && \
ln -sf /usr/bin/python${PYTHON_VERSION} /usr/bin/python && \
ln -sf /usr/bin/pip${PYTHON_VERSION} /usr/bin/pip3 && \
ln -sf /usr/bin/pip${PYTHON_VERSION} /usr/bin/pip &&\
pip install --upgrade pip wheel setuptools && \
for _runtime in $RUNTIMES; do \
_wheel="./dist/mlserver_$_runtime-"*.whl; \
echo "--> Installing $_wheel..."; \
pip install $_wheel --constraint ./dist/constraints.txt; \
done && \
pip install $(ls "./dist/mlserver-"*.whl) --constraint ./dist/constraints.txt && \
rm -rf /root/.cache/pip
COPY ./licenses/license.txt .
COPY ./licenses/license.txt /licenses/
USER 1000
# MLServer starts
CMD ["/bin/sh", "-c", "mlserver start $MLSERVER_MODELS_DIR"]