From d0e0e9c5720926a68b2f8deb1a1756a0753789d6 Mon Sep 17 00:00:00 2001 From: "Liu, Jianjun" Date: Wed, 18 Sep 2019 03:37:14 +0000 Subject: [PATCH] add tensorflow-serving container Signed-off-by: Liu, Jianjun --- .travis.yml | 1 + tensorflow-serving/Dockerfile | 54 +++++++++++ tensorflow-serving/README.md | 101 ++++++++++++++++++++ tensorflow-serving/tf_serving_entrypoint.sh | 6 ++ 4 files changed, 162 insertions(+) create mode 100644 tensorflow-serving/Dockerfile create mode 100644 tensorflow-serving/README.md create mode 100644 tensorflow-serving/tf_serving_entrypoint.sh diff --git a/.travis.yml b/.travis.yml index 959fea6..796a886 100644 --- a/.travis.yml +++ b/.travis.yml @@ -31,6 +31,7 @@ env: - DOCKERFILE_DIR=redis - DOCKERFILE_DIR=ruby - DOCKERFILE_DIR=tensorflow + - DOCKERFILE_DIR=tensorflow-serving - DOCKERFILE_DIR=tomcat - DOCKERFILE_DIR=wordpress diff --git a/tensorflow-serving/Dockerfile b/tensorflow-serving/Dockerfile new file mode 100644 index 0000000..f0f1474 --- /dev/null +++ b/tensorflow-serving/Dockerfile @@ -0,0 +1,54 @@ +FROM clearlinux:latest AS builder +MAINTAINER jianjun.liu@intel.com + +ARG swupd_args +# Move to latest Clear Linux release to ensure +# that the swupd command line arguments are +# correct +RUN swupd update --no-boot-update $swupd_args + +# Grab os-release info from the minimal base image so +# that the new content matches the exact OS version +COPY --from=clearlinux/os-core:latest /usr/lib/os-release / + +# Install additional content in a target directory +# using the os version from the minimal base +RUN source /os-release && \ + mkdir /install_root \ + && swupd os-install -V ${VERSION_ID} \ + --path /install_root --statedir /swupd-state \ + --bundles=os-core,tensorflow-serving --no-boot-update + +# For some Host OS configuration with redirect_dir on, +# extra data are saved on the upper layer when the same +# file exists on different layers. To minimize docker +# image size, remove the overlapped files before copy. +RUN mkdir /os_core_install +COPY --from=clearlinux/os-core:latest / /os_core_install/ +RUN cd / && \ + find os_core_install | sed -e 's/os_core_install/install_root/' | xargs rm -d &> /dev/null || true + +FROM clearlinux/os-core:latest + +COPY --from=builder /install_root / + +# 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 + +# Copy the script that runs the model server so we can use environment variables +RUN mkdir -p /usr/local/bin +COPY tf_serving_entrypoint.sh /usr/local/bin/ +RUN chmod +x /usr/local/bin/tf_serving_entrypoint.sh + +ENTRYPOINT ["tf_serving_entrypoint.sh"] diff --git a/tensorflow-serving/README.md b/tensorflow-serving/README.md new file mode 100644 index 0000000..afa09a9 --- /dev/null +++ b/tensorflow-serving/README.md @@ -0,0 +1,101 @@ +# Clear Linux* OS `tensorflow-serving` container image + + +## What is this image? + +`clearlinux/tensorflow-serving` is a Docker image with `tensorflow-serving` running on top of the +[official clearlinux base image](https://hub.docker.com/_/clearlinux). + + +> [Tensorflow-serving](https://www.tensorflow.org/serving) is a flexible, +> high-performance serving system for machine learning models. + +For other Clear Linux* OS +based container images, see: https://hub.docker.com/u/clearlinux + +## Why use a clearlinux based image? + + +> [Clear Linux* OS](https://clearlinux.org/) is an open source, rolling release +> Linux distribution optimized for performance and security, from the Cloud to +> the Edge, designed for customization, and manageability. + +Clear Linux* OS based container images use: +* Optimized libraries that are compiled with latest compiler versions and + flags. +* Software packages that follow upstream source closely and update frequently. +* An aggressive security model and best practices for CVE patching. +* A multi-staged build approach to keep a reduced container image size. +* The same container syntax as the official images to make getting started + easy. + +To learn more about Clear Linux* OS, visit: https://clearlinux.org. + + +## Deployment: + +### Deploy with Docker +The easiest way to get started with this image is by simply pulling it from +Docker Hub. + +*Note: This container uses the same syntax as the [official tensorflow-serving image](https://hub.docker.com/_/tensorflow-serving). + + +1. Pull the image from Docker Hub: + ``` + docker pull clearlinux/tensorflow-serving + ``` + +2. Download a tensorflow-serving repo and setup the location of demo models + ``` + git clone https://github.com/tensorflow/serving + TESTDATA="$(pwd)/serving/tensorflow_serving/servables/tensorflow/testdata" + ``` +3. Start a container using the examples below: + + ``` + docker run -t --rm -p 8501:8501 \ + -v "$TESTDATA/saved_model_half_plus_two_cpu:/models/half_plus_two" \ + -e MODEL_NAME=half_plus_two \ + clearlinux/tensorflow-serving & + ``` +4. Query the model using the predict API and the return => { "predictions": [2.5, 3.0, 4.5] } + + ``` + curl -d '{"instances": [1.0, 2.0, 5.0]}' \ + -X POST http://localhost:8501/v1/models/half_plus_two:predict + ``` + +## Build and modify: + +The Dockerfiles for all Clear Linux* OS based container images are available at +https://github.com/clearlinux/dockerfiles. These can be used to build and +modify the container images. + +1. Clone the clearlinux/dockerfiles repository. + ``` + git clone https://github.com/clearlinux/dockerfiles.git + ``` + +2. Change to the directory of the application: + ``` + cd tensorflow-serving/ + ``` + +3. Build the container image: + ``` + docker build -t clearlinux/tensorflow-serving . + ``` + + Refer to the Docker documentation for [default build arguments](https://docs.docker.com/engine/reference/builder/#arg). + Additionally: + + - `swupd_args` - specifies arguments to pass to the Clear Linux* OS software + manager. See the [swupd man pages](https://github.com/clearlinux/swupd-client/blob/master/docs/swupd.1.rst#options) + for more information. + + +## Licenses + +All licenses for the Clear Linux* Project and distributed software can be found +at https://clearlinux.org/terms-and-policies diff --git a/tensorflow-serving/tf_serving_entrypoint.sh b/tensorflow-serving/tf_serving_entrypoint.sh new file mode 100644 index 0000000..5742f08 --- /dev/null +++ b/tensorflow-serving/tf_serving_entrypoint.sh @@ -0,0 +1,6 @@ +#!/bin/bash + + +tensorflow_model_server --port=8500 --rest_api_port=8501 \ + --model_name=${MODEL_NAME} --model_base_path=${MODEL_BASE_PATH}/${MODEL_NAME} \ + "$@"