From 9723a796d3ccdf3d898ae0612f48a4ec1fa91d4f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Andr=C3=A9?= Date: Wed, 7 Jan 2015 15:30:47 +0900 Subject: [PATCH] Improvements to build-all-docker-images script Trap interrupt signal so that the build-all-docker-images script is stopped on Ctrl-C, and not only the current build. Additionally, the script now prints a summary of changes on exit. Change-Id: I3f6ef97d776c7799c73bc709070d97d37406637a --- tools/build-all-docker-images | 41 +++++++++++++++++++++++------------ 1 file changed, 27 insertions(+), 14 deletions(-) diff --git a/tools/build-all-docker-images b/tools/build-all-docker-images index 285a218cd6..0f2ba03cb6 100755 --- a/tools/build-all-docker-images +++ b/tools/build-all-docker-images @@ -47,7 +47,7 @@ function requires_build { function build_image { local dir=$1 - if [[ -x "$dir/build" ]]; then + if [ -x "$dir/build" ]; then printf "\n" info "Building image in $dir" if $dir/build $ARGS; then @@ -55,6 +55,7 @@ function build_image { status[$image]="rebuilt" else warn "Failed to build image in $dir" + status[$image]="fail" fi fi } @@ -63,11 +64,9 @@ function init_image { local img_dir=$1 set_defaults - [ -f $TOPDIR/.buildconf ] && . $TOPDIR/.buildconf + [ -f $TOPDIR/.buildconf ] && . $TOPDIR/.buildconf [ -f $img_dir/.buildconf ] && . $img_dir/.buildconf - if [ ! -z $FORCE_NAMESPACE ]; then - NAMESPACE=$FORCE_NAMESPACE - fi + [ -n $FORCE_NAMESPACE ] && NAMESPACE=$FORCE_NAMESPACE local image="${NAMESPACE:+${NAMESPACE}/}${PREFIX}${img_dir##*/}" local base_image=$(cat $img_dir/Dockerfile | gawk 'match($0, /^\s*FROM\s+(\S+)/, matches) {print matches[1]}' ) @@ -81,17 +80,34 @@ function init_image { function process_image { local image=$1 - if [ ${dependency[$image]} ]; then + if [ -n ${dependency[$image]} ]; then process_image ${dependency[$image]} fi if requires_build $image; then build_image ${img_dirs[$image]} fi - if [ -z ${status[$image]} ]; then - status[$image]="processed" + if [ -z "${status[$image]}" ]; then + status[$image]="up-to-date" fi } +function print_summary { + printf "\nSummary\n=======\n" + for image in "${!status[@]}"; do + case "${status[$image]}" in + ("fail") warn "Failed to process $image" ;; + ("rebuilt") success "Rebuilt $image" ;; + (*) info "$image: ${status[$image]}" ;; + esac + done +} + +function interrupted { + info "Interrupted..." + print_summary + exit 1 +} + function usage () { read -r -d '' HELP <