1 #!/usr/bin/env bash 2 # Copyright 2016 The TensorFlow Authors. All Rights Reserved. 3 # 4 # Licensed under the Apache License, Version 2.0 (the "License"); 5 # you may not use this file except in compliance with the License. 6 # You may obtain a copy of the License at 7 # 8 # http://www.apache.org/licenses/LICENSE-2.0 9 # 10 # Unless required by applicable law or agreed to in writing, software 11 # distributed under the License is distributed on an "AS IS" BASIS, 12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 # See the License for the specific language governing permissions and 14 # limitations under the License. 15 # ============================================================================== 16 # 17 # Builds the test server for distributed (GRPC) TensorFlow 18 # 19 # Usage: build_server.sh <docker_image_name> <whl_file_location> [--test] 20 # 21 # Arguments: 22 # docker_image_name: Name of the docker image to build. 23 # E.g.: tensorflow/tf_grpc_test_server:0.11.0rc1 24 # 25 # whl_file_location: URL from which the TensorFlow whl file will be downloaded. 26 # E.g.: https://ci.tensorflow.org/view/Nightly/job/nightly-matrix-cpu/TF_BUILD_IS_OPT=OPT,TF_BUILD_IS_PIP=PIP,TF_BUILD_PYTHON_VERSION=PYTHON2,label=cpu-slave/lastSuccessfulBuild/artifact/pip_test/whl/tensorflow-0.11.0rc1-cp27-none-linux_x86_64.whl 27 # E.g.: /path/to/folder/tensorflow-0.11.0rc1-cp27-none-linux_x86_64.whl 28 # 29 # The optional flag --test lets the script to use the Dockerfile for the 30 # testing GRPC server. Without the flag, the script will build the non-test 31 # GRPC server. 32 # 33 # Note that the Dockerfile is located in ./server/ but the docker build should 34 # use the current directory as the context. 35 36 37 # Helper functions 38 die() { 39 echo $@ 40 exit 1 41 } 42 43 # Check arguments 44 if [[ $# -lt 2 ]]; then 45 die "Usage: $0 <docker_image_name> <whl_location> [--test]" 46 fi 47 48 DOCKER_IMG_NAME=$1 49 WHL_FILE_LOCATION=$2 50 shift 2 51 52 # Current script directory 53 DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" 54 55 BUILD_DIR=$(mktemp -d) 56 echo "" 57 echo "Using whl file URL: ${WHL_FILE_LOCATION}" 58 echo "Building in temporary directory: ${BUILD_DIR}" 59 60 cp -r ${DIR}/* "${BUILD_DIR}"/ || \ 61 die "Failed to copy files to ${BUILD_DIR}" 62 63 DOCKER_FILE="${BUILD_DIR}/server/Dockerfile" 64 if [[ $1 == "--test" ]]; then 65 DOCKER_FILE="${BUILD_DIR}/server/Dockerfile.test" 66 fi 67 echo "Using Docker file: ${DOCKER_FILE}" 68 69 if [[ $WHL_FILE_LOCATION =~ 'http://' || $WHL_FILE_LOCATION =~ 'https://' ]]; then 70 # Download whl file into the build context directory. 71 wget -P "${BUILD_DIR}" "${WHL_FILE_LOCATION}" || \ 72 die "Failed to download tensorflow whl file from URL: ${WHL_FILE_LOCATION}" 73 else 74 cp "${WHL_FILE_LOCATION}" "${BUILD_DIR}" 75 fi 76 77 # Download whl file into the build context directory. 78 79 if [[ ! -f "${DOCKER_FILE}" ]]; then 80 die "ERROR: Unable to find dockerfile: ${DOCKER_FILE}" 81 fi 82 echo "Dockerfile: ${DOCKER_FILE}" 83 84 # Call docker build 85 docker build --no-cache -t "${DOCKER_IMG_NAME}" \ 86 -f "${DOCKER_FILE}" "${BUILD_DIR}" || \ 87 die "Failed to build docker image: ${DOCKER_IMG_NAME}" 88 89 # Clean up docker build context directory. 90 rm -rf "${BUILD_DIR}" 91