Add ci script for building docker image (#3181)

* Add ci script for building docker image

diff --git a/scripts/ci/README.md b/scripts/ci/README.md
index 413183f..7876f5a 100644
--- a/scripts/ci/README.md
+++ b/scripts/ci/README.md
@@ -12,11 +12,11 @@
 set -o pipefail
 
 # Install bazel (linux build) because CI hosts may not have it installed
-sh scripts/ci/setup_bazel.sh linux
+bash scripts/ci/setup_bazel.sh linux
 
 # Build v0.20.1-incubating packages for centos7 and put in artifacts folder
 HERON_BUILD_USER=release-agent
-sh scripts/ci/build_release_packages.sh v0.20.1-incubating centos7 artifacts
+bash scripts/ci/build_release_packages.sh v0.20.1-incubating centos7 artifacts
 
 ```
 
@@ -30,8 +30,30 @@
 set -e
 set -o pipefail
 
+# Install bazel (linux build) because CI hosts may not have it installed
+bash scripts/ci/setup_bazel.sh linux
+
 # Build v0.20.1-incubating artifacts and put in artifacts folder
 HERON_BUILD_USER=release-agent
-sh scripts/ci/build_maven_artifacts.sh v0.20.1-incubating artifacts
+bash scripts/ci/build_maven_artifacts.sh v0.20.1-incubating artifacts
+
+```
+
+## Build docker image
+
+The docker image includes Heron core, tools and examples.
+
+Example:
+
+```bash
+set -e
+set -o pipefail
+
+# Install bazel (linux build) because CI hosts may not have it installed
+bash scripts/ci/setup_bazel.sh linux
+
+# Build v0.20.1-incubating artifacts and put in artifacts folder
+HERON_BUILD_USER=release-agent
+bash scripts/ci/build_docker_image.sh v0.20.1-incubating debian9 artifacts
 
 ```
diff --git a/scripts/ci/build_docker_image.sh b/scripts/ci/build_docker_image.sh
new file mode 100644
index 0000000..c43fa90
--- /dev/null
+++ b/scripts/ci/build_docker_image.sh
@@ -0,0 +1,66 @@
+#!/bin/bash
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you 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 docker image to be released
+# parameters:
+# 1. version tag, e.g. v0.20.1-incubating
+# 2. build os, e.g. debian9, centos7
+# 3. output dir
+
+# Related environment variables
+# HERON_BUILD_USER
+# HERON_BUILD_HOST
+
+set -e
+set -o pipefail
+
+if [ "$#" -ne 3 ]; then
+    echo "ERROR: Wrong number of arguments. Usage '$0 VERSION_TAG BUILD_OS OUTPUT_DIR'"
+    exit 1
+fi
+VERSION_TAG=$1
+BUILD_OS=$2
+OUTPUT_DIR=$3
+
+TEMP_RELEASE_DIR=~/heron-release
+
+# Clear out the pex cache
+rm -rf /var/lib/jenkins/.pex/build/*
+
+
+# Build with docker
+chmod +x scripts/release/status.sh
+chmod +x heron/downloaders/src/shell/heron-downloader.sh
+chmod +x heron/tools/apiserver/src/shell/heron-apiserver.sh
+
+bash scripts/release/status.sh
+
+# Create a temporary directory for generated files
+mkdir -p $TEMP_RELEASE_DIR
+rm -f $TEMP_RELEASE_DIR/*.*
+
+# Build artifacts and the docker image
+./docker/scripts/build-artifacts.sh $BUILD_OS $VERSION_TAG $TEMP_RELEASE_DIR
+./docker/scripts/build-docker.sh $BUILD_OS $VERSION_TAG $TEMP_RELEASE_DIR
+
+# Cherry-pick files to output dir
+mkdir -p $OUTPUT_DIR
+cp ${TEMP_RELEASE_DIR}/heron-docker-${VERSION_TAG}-${BUILD_OS}.tar.gz $OUTPUT_DIR
+
+# Remove temporary directory
+rm -rf $TEMP_RELEASE_DIR
diff --git a/scripts/ci/build_maven_artifacts.sh b/scripts/ci/build_maven_artifacts.sh
index 3dc263e..fdf469c 100644
--- a/scripts/ci/build_maven_artifacts.sh
+++ b/scripts/ci/build_maven_artifacts.sh
@@ -58,10 +58,10 @@
 cd $BASE_DIR
 
 echo "Build directories for jars ... "
-mkdir $OUTPUT_DIR/$VERSION_TAG/heron-api
-mkdir $OUTPUT_DIR/$VERSION_TAG/heron-spi
-mkdir $OUTPUT_DIR/$VERSION_TAG/heron-simulator
-mkdir $OUTPUT_DIR/$VERSION_TAG/heron-storm
+mkdir -p $OUTPUT_DIR/$VERSION_TAG/heron-api
+mkdir -p $OUTPUT_DIR/$VERSION_TAG/heron-spi
+mkdir -p $OUTPUT_DIR/$VERSION_TAG/heron-simulator
+mkdir -p $OUTPUT_DIR/$VERSION_TAG/heron-storm
 
 echo "Copy heron-api artifacts ... "
 cp ./release/heron-api-$VERSION_TAG.pom $OUTPUT_DIR/$VERSION_TAG/heron-api/
@@ -89,5 +89,5 @@
 
 
 echo "Compress all artifacts into a bundle file ..."
-tar -czf "${VERSION_TAG}_artifacts.tar.gz" $OUTPUT_DIR
-mv "${VERSION_TAG}_artifacts.tar.gz" $OUTPUT_DIR
+tar -czf "heron-artifacts-${VERSION_TAG}.tar.gz" $OUTPUT_DIR
+mv "heron-artifacts-${VERSION_TAG}.tar.gz" $OUTPUT_DIR
diff --git a/scripts/ci/build_release_packages.sh b/scripts/ci/build_release_packages.sh
index 3e10362..1e38cf0 100644
--- a/scripts/ci/build_release_packages.sh
+++ b/scripts/ci/build_release_packages.sh
@@ -37,7 +37,7 @@
 BUILD_OS=$2
 OUTPUT_DIR=$3
 
-HERON_BUILD_VERSION=$VERSION_TAG
+TEMP_RELEASE_DIR=~/heron-release
 
 # Clear out the pex cache
 rm -rf /var/lib/jenkins/.pex/build/*
@@ -50,12 +50,15 @@
 
 bash scripts/release/status.sh
 
-# Create a temporary director for generated files
-mkdir -p ~/heron-release
-rm -f ~/heron-release/*.*
-./docker/scripts/build-artifacts.sh $BUILD_OS $VERSION_TAG ~/heron-release
+# Create a temporary directory for generated files
+mkdir -p $TEMP_RELEASE_DIR
+rm -f $TEMP_RELEASE_DIR/*.*
+./docker/scripts/build-artifacts.sh $BUILD_OS $VERSION_TAG $TEMP_RELEASE_DIR
 
 # Cherry-pick files to output dir
 mkdir -p $OUTPUT_DIR
-cp ~/heron-release/heron-${VERSION_TAG}-${BUILD_OS}.tar.gz $OUTPUT_DIR
-cp ~/heron-release/heron-install-${VERSION_TAG}-${BUILD_OS}.sh $OUTPUT_DIR
+cp $TEMP_RELEASE_DIR/heron-${VERSION_TAG}-${BUILD_OS}.tar.gz $OUTPUT_DIR
+cp $TEMP_RELEASE_DIR/heron-install-${VERSION_TAG}-${BUILD_OS}.sh $OUTPUT_DIR
+
+# Remove temporary directory
+rm -rf $TEMP_RELEASE_DIR