From 06464412c7ec9a1e0ed3a2b11b34ea9c5e5bb442 Mon Sep 17 00:00:00 2001 From: Mohsen Rezaei Date: Fri, 6 Mar 2020 19:42:17 -0800 Subject: [PATCH] added starter CentOS 7 dockerfiles --- .../tools/docker/centos7/Dockerfile | 44 +++++++ .../tools/docker/centos7/Dockerfile.devel | 110 ++++++++++++++++++ .../tools/docker/centos7/README.md | 3 + 3 files changed, 157 insertions(+) create mode 100644 tensorflow_serving/tools/docker/centos7/Dockerfile create mode 100644 tensorflow_serving/tools/docker/centos7/Dockerfile.devel create mode 100644 tensorflow_serving/tools/docker/centos7/README.md diff --git a/tensorflow_serving/tools/docker/centos7/Dockerfile b/tensorflow_serving/tools/docker/centos7/Dockerfile new file mode 100644 index 00000000000..347e192c89c --- /dev/null +++ b/tensorflow_serving/tools/docker/centos7/Dockerfile @@ -0,0 +1,44 @@ +# This file is based on Google TensorFlow Serving Dockerfile file with +# modifications needed to build the project for CentOS7. +# Original file is licenced under Apache Licence, Version 2.0: +# https://github.com/tensorflow/serving/blob/master/tensorflow_serving/tools/docker/Dockerfile +ARG TF_SERVING_VERSION=latest +ARG TF_SERVING_BUILD_IMAGE=tf-serving-centos7-devel:${TF_SERVING_VERSION} + +FROM ${TF_SERVING_BUILD_IMAGE} as build_image +FROM centos:7.7.1908 + +ARG TF_SERVING_VERSION_GIT_BRANCH=master +ARG TF_SERVING_VERSION_GIT_COMMIT=head + +LABEL tensorflow_serving_github_branchtag=${TF_SERVING_VERSION_GIT_BRANCH} +LABEL tensorflow_serving_github_commit=${TF_SERVING_VERSION_GIT_COMMIT} + +RUN yum update -y + +# Install TF Serving pkg +COPY --from=build_image /usr/local/bin/tensorflow_model_server /usr/bin/tensorflow_model_server + +# Expose ports +# gRPC +EXPOSE 8500 + +# REST +EXPOSE 8501 + +# Set where models should be stored in the container +ENV MODEL_BASE_PATH=/models +RUN mkdir -p ${MODEL_BASE_PATH} + +# The only required piece is the model name in order to differentiate endpoints +ENV MODEL_NAME=model + +# 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\ +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 + +ENTRYPOINT ["/usr/bin/tf_serving_entrypoint.sh"] diff --git a/tensorflow_serving/tools/docker/centos7/Dockerfile.devel b/tensorflow_serving/tools/docker/centos7/Dockerfile.devel new file mode 100644 index 00000000000..3f9f930a06e --- /dev/null +++ b/tensorflow_serving/tools/docker/centos7/Dockerfile.devel @@ -0,0 +1,110 @@ +# This file is based on Google TensorFlow Serving Dockerfile.devel file with +# Modifications needed to build the project for CentOS 7. +# Original file is licenced under Apache Licence, Version 2.0: +# https://github.com/tensorflow/serving/blob/master/tensorflow_serving/tools/docker/Dockerfile.devel + +FROM centos:7.7.1908 as base_build + +# Set locale +ENV LANG en_US.UTF-8 + +ARG TF_SERVING_VERSION_GIT_BRANCH=master +# Picking latest working revision until official Dockerfile.devel is fixed. +ARG TF_SERVING_VERSION_GIT_COMMIT=4de4c7b6d2f5932f8f2be939335e38c94f1f2dac + +LABEL tensorflow_serving_github_branchtag=${TF_SERVING_VERSION_GIT_BRANCH} +LABEL tensorflow_serving_github_commit=${TF_SERVING_VERSION_GIT_COMMIT} + +# Enable SCL CentOS 7 repo and install build packages +RUN yum install -y centos-release-scl && yum update -y && yum install -y \ + which \ + devtoolset-8-gcc \ + devtoolset-8-gcc-c++ \ + devtoolset-8-make \ + patch \ + automake \ + ca-certificates \ + curl \ + git \ + libtool \ + mlocate \ + java-1.8.0-openjdk-devel \ + swig \ + unzip \ + wget \ + zip + +# Note: This is for python2 which soon to be unsupported +RUN curl -fSsL -O https://bootstrap.pypa.io/get-pip.py && \ + python get-pip.py && \ + rm -f get-pip.py + +RUN pip --no-cache-dir install \ + future>=0.17.1 \ + grpcio \ + h5py \ + keras_applications>=1.0.8 \ + keras_preprocessing>=1.1.0 \ + mock \ + numpy \ + requests \ + --ignore-installed setuptools \ + --ignore-installed six + +# Set up Bazel +ENV BAZEL_VERSION 0.24.1 +WORKDIR / +RUN mkdir /bazel && \ + cd /bazel && \ + curl -H "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.133 Safari/537.36" -fSsL -O https://github.com/bazelbuild/bazel/releases/download/$BAZEL_VERSION/bazel-$BAZEL_VERSION-installer-linux-x86_64.sh && \ + curl -H "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.133 Safari/537.36" -fSsL -o /bazel/LICENSE.txt https://raw.githubusercontent.com/bazelbuild/bazel/master/LICENSE && \ + chmod +x bazel-*.sh && \ + ./bazel-$BAZEL_VERSION-installer-linux-x86_64.sh && \ + cd / && \ + rm -f /bazel/bazel-$BAZEL_VERSION-installer-linux-x86_64.sh + +# Download TF Serving sources (optionally at specific commit). +WORKDIR /tensorflow-serving +RUN git clone --branch=${TF_SERVING_VERSION_GIT_BRANCH} https://github.com/tensorflow/serving . && \ + git remote add upstream https://github.com/tensorflow/serving.git && \ + if [ "${TF_SERVING_VERSION_GIT_COMMIT}" != "head" ]; then git checkout ${TF_SERVING_VERSION_GIT_COMMIT} ; fi + + +FROM base_build as binary_build +# Build, and install TensorFlow Serving +# Example: '--local_ram_resources=HOST_RAM*.5, --local_cpu_resources=HOST_CPUS-1' +ARG TF_SERVING_BUILD_OPTIONS="--config=nativeopt --local_ram_resources=HOST_RAM*.5 --discard_analysis_cache --nokeep_state_after_build --notrack_incremental_state" +RUN echo "Building with build options: ${TF_SERVING_BUILD_OPTIONS}" +ARG TF_SERVING_BAZEL_OPTIONS="" +RUN echo "Building with Bazel options: ${TF_SERVING_BAZEL_OPTIONS}" + +# CentOS 7: Here and in the next RUN added command to enable devtoolset-8 env. +RUN source /opt/rh/devtoolset-8/enable && \ + bazel build --color=yes --curses=yes \ + ${TF_SERVING_BAZEL_OPTIONS} \ + --verbose_failures \ + --output_filter=DONT_MATCH_ANYTHING \ + ${TF_SERVING_BUILD_OPTIONS} \ + tensorflow_serving/model_servers:tensorflow_model_server && \ + cp bazel-bin/tensorflow_serving/model_servers/tensorflow_model_server \ + /usr/local/bin/ + +# Build and install TensorFlow Serving API +RUN source /opt/rh/devtoolset-8/enable && \ + bazel build --color=yes --curses=yes \ + ${TF_SERVING_BAZEL_OPTIONS} \ + --verbose_failures \ + --output_filter=DONT_MATCH_ANYTHING \ + ${TF_SERVING_BUILD_OPTIONS} \ + tensorflow_serving/tools/pip_package:build_pip_package && \ + bazel-bin/tensorflow_serving/tools/pip_package/build_pip_package \ + /tmp/pip && \ + pip --no-cache-dir install --upgrade \ + /tmp/pip/tensorflow_serving_api-*.whl && \ + rm -rf /tmp/pip + +FROM binary_build as clean_build +# Clean up Bazel cache when done. +RUN bazel clean --expunge --color=yes && \ + rm -rf /root/.cache +CMD ["/bin/bash"] diff --git a/tensorflow_serving/tools/docker/centos7/README.md b/tensorflow_serving/tools/docker/centos7/README.md new file mode 100644 index 00000000000..914aaa49866 --- /dev/null +++ b/tensorflow_serving/tools/docker/centos7/README.md @@ -0,0 +1,3 @@ +Files for using the [Docker](http://www.docker.com) container system. +Please see [Docker instructions](https://github.com/tensorflow/serving/blob/master/tensorflow_serving/g3doc/docker.md) +for more info.