-
Notifications
You must be signed in to change notification settings - Fork 452
/
Dockerfile.cpu
130 lines (107 loc) · 4.41 KB
/
Dockerfile.cpu
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
FROM ubuntu:18.04
LABEL maintainer="Amazon AI"
LABEL com.amazonaws.sagemaker.capabilities.accept-bind-to-port=true
ARG PYTHON=python3.7
ARG PYTHON_PIP=python3-pip
ARG PIP=pip3
ARG PYTHON_VERSION=3.7.7
ARG OPENSSL_VERSION=1.1.1g
ARG TFS_SHORT_VERSION=2.2
ARG TFS_URL=https://aws-tensorflow-binaries.s3-us-west-2.amazonaws.com/serving/r2.2_aws/20200611-220145/cpu/py37/tensorflow_model_server
# See http://bugs.python.org/issue19846
ENV LANG=C.UTF-8
# Python won’t try to write .pyc or .pyo files on the import of source modules
ENV PYTHONDONTWRITEBYTECODE=1
ENV PYTHONUNBUFFERED=1
ENV SAGEMAKER_TFS_VERSION="${TFS_SHORT_VERSION}"
ENV PATH="$PATH:/sagemaker"
ENV LD_LIBRARY_PATH='/usr/local/lib:$LD_LIBRARY_PATH'
ENV MODEL_BASE_PATH=/models
# The only required piece is the model name in order to differentiate endpoints
ENV MODEL_NAME=model
ENV DEBIAN_FRONTEND=noninteractive
# nginx + njs
RUN apt-get update \
&& apt-get -y install --no-install-recommends \
curl \
gnupg2 \
ca-certificates \
git \
wget \
vim \
libffi-dev \
build-essential \
zlib1g-dev \
&& curl -s http://nginx.org/keys/nginx_signing.key | apt-key add - \
&& echo 'deb http://nginx.org/packages/ubuntu/ bionic nginx' >> /etc/apt/sources.list \
&& apt-get update \
&& apt-get -y install --no-install-recommends \
nginx \
nginx-module-njs \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*
RUN wget -c https://www.openssl.org/source/openssl-${OPENSSL_VERSION}.tar.gz \
&& apt-get update \
&& apt remove -y --purge openssl \
&& rm -rf /usr/include/openssl \
&& apt-get install -y \
ca-certificates \
&& tar -xzvf openssl-${OPENSSL_VERSION}.tar.gz \
&& cd openssl-${OPENSSL_VERSION} \
&& ./config && make && make test \
&& make install \
&& ldconfig \
&& cd .. && rm -rf openssl-*
# when we remove previous openssl, the ca-certificates pkgs and its symlinks gets deleted
# causing sslcertverificationerror the below steps are to fix that
RUN ln -s /etc/ssl/certs/*.* /usr/local/ssl/certs/
# Install python3.7
RUN wget https://www.python.org/ftp/python/$PYTHON_VERSION/Python-$PYTHON_VERSION.tgz \
&& tar -xvf Python-$PYTHON_VERSION.tgz \
&& cd Python-$PYTHON_VERSION \
&& ./configure && make && make install \
&& make && make install && rm -rf ../Python-$PYTHON_VERSION*
RUN ${PIP} --no-cache-dir install --upgrade \
pip \
setuptools
# cython, falcon, gunicorn, grpc
RUN ${PIP} install --no-cache-dir \
awscli \
cython==0.29.14 \
falcon==2.0.0 \
gunicorn==20.0.4 \
gevent==1.4.0 \
requests==2.22.0 \
grpcio==1.29.0 \
protobuf==3.11.1 \
# using --no-dependencies to avoid installing tensorflow binary
&& ${PIP} install --no-dependencies --no-cache-dir \
tensorflow-serving-api==2.2.0
COPY ./sagemaker /sagemaker
# put tensorflow library (with only error_codes) to python dist-packages
WORKDIR /
RUN cd /usr/local/lib/python3.*/site-packages/ \
&& mv /sagemaker/tensorflow-2.2 ./tensorflow \
# Delete the remaining tensorflow folder to avoid confusing python import
&& rm -rf /sagemaker/tensorflow
# Some TF tools expect a "python" binary
RUN ln -s $(which ${PYTHON}) /usr/local/bin/python \
&& ln -s $(which ${PIP}) /usr/bin/pip
RUN curl https://tensorflow-aws.s3-us-west-2.amazonaws.com/MKL-Libraries/libiomp5.so -o /usr/local/lib/libiomp5.so
RUN curl https://tensorflow-aws.s3-us-west-2.amazonaws.com/MKL-Libraries/libmklml_intel.so -o /usr/local/lib/libmklml_intel.so
RUN curl $TFS_URL -o /usr/bin/tensorflow_model_server \
&& chmod 555 /usr/bin/tensorflow_model_server
# Expose ports
# gRPC and REST
EXPOSE 8500 8501
# Set where models should be stored in the container
RUN mkdir -p ${MODEL_BASE_PATH}
# Create a script that runs the model server so we can use environment variables
# while also passing in arguments from the docker command line
RUN echo '#!/bin/bash \n\n' > /usr/bin/tf_serving_entrypoint.sh \
&& echo '/usr/bin/tensorflow_model_server --port=8500 --rest_api_port=8501 --model_name=${MODEL_NAME} --model_base_path=${MODEL_BASE_PATH}/${MODEL_NAME} "$@"' >> /usr/bin/tf_serving_entrypoint.sh \
&& chmod +x /usr/bin/tf_serving_entrypoint.sh
ADD https://raw.githubusercontent.com/aws/aws-deep-learning-containers-utils/master/deep_learning_container.py /usr/local/bin/deep_learning_container.py
RUN chmod +x /usr/local/bin/deep_learning_container.py
RUN curl https://aws-dlc-licenses.s3.amazonaws.com/tensorflow-2.2/license.txt -o /license.txt
CMD ["/usr/bin/tf_serving_entrypoint.sh"]