From 25cadc04ba9c5b94865595a0d32bedb733191b5c Mon Sep 17 00:00:00 2001 From: Brian Atkinson Date: Mon, 13 Jan 2020 15:35:12 -0800 Subject: [PATCH] Add a simple script and config for building RBE images with Cloud Build. PiperOrigin-RevId: 289534328 Change-Id: I3abdea849f07896c67e284a291eac66f569e8237 --- tensorflow/tools/ci_build/build_rbe.sh | 51 ++++++++++ .../tools/ci_build/ci_rbe_docker_build.sh | 98 ------------------- tensorflow/tools/ci_build/cloudbuild.yaml | 8 ++ 3 files changed, 59 insertions(+), 98 deletions(-) create mode 100755 tensorflow/tools/ci_build/build_rbe.sh delete mode 100755 tensorflow/tools/ci_build/ci_rbe_docker_build.sh create mode 100644 tensorflow/tools/ci_build/cloudbuild.yaml diff --git a/tensorflow/tools/ci_build/build_rbe.sh b/tensorflow/tools/ci_build/build_rbe.sh new file mode 100755 index 00000000000..3fd9babb53f --- /dev/null +++ b/tensorflow/tools/ci_build/build_rbe.sh @@ -0,0 +1,51 @@ +#!/bin/bash + +# Copyright 2020 The TensorFlow Authors. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============================================================================== +# Script for helping to record method for building the RBE docker images. +# +# The first argument to the script is expected to be the name of the docker file +# to build. Example: +# +# $ ./build_rbe.sh Dockerfile.rbe.ubuntu16.04-manylinux2010 + +function main() { + set -eu + + cd "${0%/*}" + + local DOCKERFILE="$(basename "$1")" + if [[ ! -e "$DOCKERFILE" ]]; then + echo "$DOCKERFILE does not exist in $PWD" >> /dev/stderr + exit 1 + fi + + local IMAGE_NAME_SUFFIX="${1#Dockerfile.rbe.}" + if [[ "$IMAGE_NAME_SUFFIX" == "$DOCKERFILE" ]]; then + echo 'File must start with "Dockerfile.rbe."' >> /dev/stderr + exit 1 + fi + + local ARGS=( + --config=cloudbuild.yaml + --machine-type=n1-highcpu-32 + --substitutions=_DOCKERFILE="$1",_IMAGE_NAME="nosla-$IMAGE_NAME_SUFFIX" + --timeout=1h + ) + + gcloud --project=tensorflow-testing builds submit "${ARGS[@]}" . +} + +main "$@" diff --git a/tensorflow/tools/ci_build/ci_rbe_docker_build.sh b/tensorflow/tools/ci_build/ci_rbe_docker_build.sh deleted file mode 100755 index cd811de6bdf..00000000000 --- a/tensorflow/tools/ci_build/ci_rbe_docker_build.sh +++ /dev/null @@ -1,98 +0,0 @@ -#!/usr/bin/env bash -# Copyright 2016 The TensorFlow Authors. All Rights Reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# ============================================================================== -# Build TensorFlow Docker images for remote build -# -# Usage: -# ci_rbe_docker_build.sh -c # docker image for cpu build -# ci_rbe_docker_build.sh -g # docker image for gpu build - -function main { - cpu_build=false - gpu_build=false - publish=false - - script_dir=$(dirname "$(readlink -f "$0")") - cd $script_dir - - set_script_flags $@ - - build_tf_image - - if [ "$publish" = true ] ; then - publish_tf_image - fi -} - - -function set_script_flags { - OPTIND=1 # Reset for getopts, just in case. - while getopts "cf:ghn" opt; do - case "$opt" in - c) - cpu_build=true - ;; - g) - gpu_build=true - ;; - h) - print_usage - ;; - p) - publish=true - ;; - *) - print_usage "ERROR: unknown option" - ;; - esac - done - [[ "$cpu_build" = true ]] || [[ "$gpu_build" = true ]] || print_usage "ERROR: must specify build at least for one build type: cpu or gpu" - -} - - -function print_usage { - echo "Usage: $(basename $0) -c | -g [options]" - echo " -c build image for CPU build (base image debian8-clang)" - echo " -g build image for GPU build (base image nvidia-clang)" - echo "[option] is one of" - echo " -n not publish the locally-built image to GCR;" - echo " the build process will publish image to GCR by default" - echo " -h display help messages" - if [[ -n $1 ]]; then - echo $1 - fi - exit 1 -} - -function build_tf_image { - if [ "$cpu_build" = true ] ; then - dockerfile="Dockerfile.rbe.cpu" - tf_image="tensorflow-rbe-cpu" - else - dockerfile="Dockerfile.rbe.gpu" - tf_image="tensorflow-rbe-gpu" - fi - - docker build -f $dockerfile -t $tf_image . -} - -function publish_tf_image { - gcr_tf_image="gcr.io/tensorflow/${tf_image}" - docker tag $tf_image $gcr_tf_image - gcloud docker -- push $gcr_tf_image -} - -main $@ diff --git a/tensorflow/tools/ci_build/cloudbuild.yaml b/tensorflow/tools/ci_build/cloudbuild.yaml new file mode 100644 index 00000000000..77748837dd2 --- /dev/null +++ b/tensorflow/tools/ci_build/cloudbuild.yaml @@ -0,0 +1,8 @@ +steps: +- name: 'gcr.io/cloud-builders/docker' + args: ['build', '-f', '$_DOCKERFILE', '-t', 'gcr.io/$PROJECT_ID/$_IMAGE_NAME', '.'] +substitutions: + _DOCKERFILE: '' + _IMAGE_NAME: '' +images: +- 'gcr.io/$PROJECT_ID/$_IMAGE_NAME'