forked from SeldonIO/MLServer
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDockerfile
More file actions
160 lines (144 loc) · 6.06 KB
/
Dockerfile
File metadata and controls
160 lines (144 loc) · 6.06 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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
FROM python:3.10-slim AS wheel-builder
SHELL ["/bin/bash", "-l", "-c"]
ARG POETRY_VERSION="1.8.3"
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
# NOTE: Poetry outputs extras within the constraints, which are not supported
# by pip:
# https://github.com/python-poetry/poetry-plugin-export/issues/210
RUN pip install poetry==$POETRY_VERSION && \
./hack/build-wheels.sh /opt/mlserver/dist && \
poetry export --with all-runtimes \
--without-hashes \
--format constraints.txt \
-o /opt/mlserver/dist/constraints.txt && \
sed -i 's/\[.*\]//g' /opt/mlserver/dist/constraints.txt && \
sed -i 's/perf-analyzer==2.59.1/perf-analyzer/g' /opt/mlserver/dist/constraints.txt
RUN cat opt/mlserver/dist/constraints.txt
FROM 724664234782.dkr.ecr.us-east-1.amazonaws.com/docker.io/library/rockylinux:9.3.20231119-minimal
SHELL ["/bin/bash", "-c"]
ARG PYTHON_VERSION=3.10.12
ARG CONDA_VERSION=23.11.0
ARG MINIFORGE_VERSION=${CONDA_VERSION}-0
ARG RUNTIMES="all"
# 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 make sure you update the
# `/opt/conda` path within `LD_LIBRARY_PATH`.
ENV MLSERVER_MODELS_DIR=/mnt/models \
MLSERVER_ENV_TARBALL=/mnt/models/environment.tar.gz \
MLSERVER_PATH=/opt/mlserver \
CONDA_PATH=/opt/conda \
PATH=/opt/mlserver/.local/bin:/opt/conda/bin:$PATH \
LD_LIBRARY_PATH=/usr/local/nvidia/lib64:/opt/conda/lib/python3.10/site-packages/nvidia/cuda_runtime/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
# Install Conda, Python 3.10 and FFmpeg
RUN microdnf install -y wget && \
wget "https://github.com/conda-forge/miniforge/releases/download/${MINIFORGE_VERSION}/Miniforge3-${MINIFORGE_VERSION}-Linux-x86_64.sh" \
-O miniforge3.sh && \
bash "./miniforge3.sh" -b -p $CONDA_PATH && \
rm ./miniforge3.sh && \
echo $PATH && \
conda install --yes \
conda=$CONDA_VERSION \
python=$PYTHON_VERSION \
ffmpeg && \
conda clean -tipy && \
microdnf remove -y wget && \
echo "conda activate base" >> "$CONDA_PATH/etc/profile.d/conda.sh" && \
ln -s "$CONDA_PATH/etc/profile.d/conda.sh" /etc/profile.d/conda.sh && \
echo ". $CONDA_PATH/etc/profile.d/conda.sh" >> ~/.bashrc
RUN mkdir $MLSERVER_PATH
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 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
# NOTE: if runtime is "all" we install mlserver-<version>-py3-none-any.whl
# we have to use this syntax to return the correct file: $(ls ./dist/mlserver-*.whl)
# NOTE: Temporarily excluding mllib from the main image due to:
# CVE-2022-25168
# CVE-2022-42889
# NOTE: Removing explicitly requirements.txt file from spaCy's test
# dependencies causing false positives in Snyk.
RUN . $CONDA_PATH/etc/profile.d/conda.sh && \
pip install --upgrade wheel setuptools && \
if [[ $RUNTIMES == "all" ]]; then \
for _wheel in "./dist/mlserver_"*.whl; do \
if [[ ! $_wheel == *"mllib"* ]]; then \
echo "--> Installing $_wheel..."; \
pip install $_wheel --constraint ./dist/constraints.txt; \
fi \
done \
else \
for _runtime in $RUNTIMES; do \
_wheelName=$(echo $_runtime | tr '-' '_'); \
_wheel="./dist/$_wheelName-"*.whl; \
echo "--> Installing $_wheel..."; \
pip install $_wheel --constraint ./dist/constraints.txt; \
done \
fi && \
pip install $(ls "./dist/mlserver-"*.whl) --constraint ./dist/constraints.txt && \
rm -f /opt/conda/lib/python3.10/site-packages/spacy/tests/package/requirements.txt && \
rm -rf /root/.cache/pip
COPY ./licenses/license.txt .
COPY ./licenses/license.txt /licenses/
COPY \
./hack/build-env.sh \
./hack/generate_dotenv.py \
./hack/activate-env.sh \
./hack/
RUN pip install --upgrade certifi tqdm requests urllib3 && pip install --upgrade aiohttp python-multipart starlette
RUN microdnf upgrade -y && microdnf clean all -y
RUN pip install --upgrade setuptools
RUN pip install protobuf==4.25.8
RUN pip install --upgrade transformers==4.53.0 Brotli==1.2.0 keras==3.12.0 starlette==0.49.1 pip
RUN pip install xgboost
RUN pip install Werkzeug==3.1.4
RUN pip install filelock==3.20.1
# RUN microdnf remove -y python3.9 glib2-devel python-unversioned-command python3-setuptools-wheel python3-libs libX11 libX11-common libX11-xcb libXext mesa-libGL libXfixes libglvnd-glx libXxf86vm
RUN microdnf remove -y python3.9 glib2-devel python-unversioned-command python3-setuptools-wheel python3-libs
#libX11 libX11-common libX11-xcb libXext libXfixes libglvnd-glx libXxf86vm
#Remove force remove rpms since these are dependant on microdnf
#RPM uninstall could not find files to uninstall
RUN rpm -e \
# pcre2 \
# pcre2-devel \
# pcre2-syntax \
# pcre2-utf16 \
# pcre2-utf32 \
microdnf \
openldap \
gawk \
tar \
# This is the os version of python certifi which is managed by pip
ca-certificates \
libzstd \
libyaml \
--nodeps
USER 1000
# We need to build and activate the "hot-loaded" environment before MLServer
# starts
CMD . $CONDA_PATH/etc/profile.d/conda.sh && \
source ./hack/activate-env.sh $MLSERVER_ENV_TARBALL && \
mlserver start $MLSERVER_MODELS_DIR