-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathDockerfile
More file actions
60 lines (53 loc) · 2.26 KB
/
Dockerfile
File metadata and controls
60 lines (53 loc) · 2.26 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
# Build an image that can serve mlflow models.
FROM ubuntu:18.04
RUN apt-get -y update
RUN apt-get install -y --no-install-recommends \
wget \
curl \
nginx \
ca-certificates \
bzip2 \
build-essential \
cmake \
openjdk-8-jdk \
git-core \
maven \
&& rm -rf /var/lib/apt/lists/*
# Setup miniconda
RUN curl -L https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh >> miniconda.sh
RUN bash ./miniconda.sh -b -p /miniconda && rm ./miniconda.sh
ENV PATH="/miniconda/bin:$PATH"
ENV JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64
ENV GUNICORN_CMD_ARGS="--timeout 60 -k gevent"
# Set up the program in the image
WORKDIR /opt/mlflow
RUN pip install mlflow==1.26.1
RUN mvn --batch-mode dependency:copy -Dartifact=org.mlflow:mlflow-scoring:1.26.1:pom -DoutputDirectory=/opt/java
RUN mvn --batch-mode dependency:copy -Dartifact=org.mlflow:mlflow-scoring:1.26.1:jar -DoutputDirectory=/opt/java/jars
RUN cp /opt/java/mlflow-scoring-1.26.1.pom /opt/java/pom.xml
RUN cd /opt/java && mvn --batch-mode dependency:copy-dependencies -DoutputDirectory=/opt/java/jars
ARG MODEL_PATH
COPY $MODEL_PATH/model /opt/ml/model
RUN echo 'import yaml\n\
with open(r"/opt/ml/model/conda.yaml") as file:\n\
f = yaml.load(file, Loader=yaml.FullLoader)\n\
for index, item in enumerate(f["dependencies"]):\n\
if type(item) is dict and item.get("pip") != None:\n\
f["dependencies"][index]["pip"].append("protobuf==3.19.4")\n\
with open(r"/opt/ml/model/conda.yaml", "w") as file:\n\
yaml.dump(f, file)' >> /tmp/update_conda_yaml.py
RUN python /tmp/update_conda_yaml.py
RUN python -c \
'from mlflow.models.container import _install_pyfunc_deps;\
_install_pyfunc_deps(\
"/opt/ml/model", \
install_mlflow=False, \
enable_mlserver=False, \
env_manager="conda")'
ENV MLFLOW_DISABLE_ENV_CREATION="true"
ENV ENABLE_MLSERVER="False"
# granting read/write access and conditional execution authority to all child directories
# and files to allow for deployment to AWS Sagemaker Serverless Endpoints
# (see https://docs.aws.amazon.com/sagemaker/latest/dg/serverless-endpoints.html)
RUN chmod o+rwX /opt/mlflow/
ENTRYPOINT ["python", "-c", "from mlflow.models import container as C;C._serve('conda')"]