19070: Still trying to fix test_with_arvbox
[arvados.git] / build / run-build-docker-images.sh
index d03169457e7d3a1a33a535e50deed79b3f398828..00ef2de417d77a230d5abad0975c4376317b5872 100755 (executable)
@@ -1,4 +1,7 @@
 #!/bin/bash
+# Copyright (C) The Arvados Authors. All rights reserved.
+#
+# SPDX-License-Identifier: AGPL-3.0
 
 function usage {
     echo >&2
@@ -6,6 +9,7 @@ function usage {
     echo >&2
     echo >&2 "$0 options:"
     echo >&2 "  -t, --tags [csv_tags]         comma separated tags"
+    echo >&2 "  -i, --images [dev,demo]       Choose which images to build (default: dev and demo)"
     echo >&2 "  -u, --upload                  Upload the images (docker push)"
     echo >&2 "  -h, --help                    Display this help and exit"
     echo >&2
@@ -13,10 +17,11 @@ function usage {
 }
 
 upload=false
+images=dev,demo
 
 # NOTE: This requires GNU getopt (part of the util-linux package on Debian-based distros).
-TEMP=`getopt -o hut: \
-    --long help,upload,tags: \
+TEMP=`getopt -o hut:i: \
+    --long help,upload,tags:,images: \
     -n "$0" -- "$@"`
 
 if [ $? != 0 ] ; then echo "Use -h for help"; exit 1 ; fi
@@ -30,6 +35,19 @@ do
             upload=true
             shift
             ;;
+        -i | --images)
+            case "$2" in
+                "")
+                  echo "ERROR: --images needs a parameter";
+                  usage;
+                  exit 1
+                  ;;
+                *)
+                  images=$2;
+                  shift 2
+                  ;;
+            esac
+            ;;
         -t | --tags)
             case "$2" in
                 "")
@@ -64,11 +82,17 @@ title () {
 }
 
 docker_push () {
+    # docker always creates a local 'latest' tag, and we don't want to push that
+    # tag in every case. Remove it.
+    docker rmi $1:latest
+
+    GITHEAD=$(cd $WORKSPACE && git log --format=%H -n1 HEAD)
+
     if [[ ! -z "$tags" ]]
     then
         for tag in $( echo $tags|tr "," " " )
         do
-             $DOCKER tag $1 $1:$tag
+             $DOCKER tag $1:$GITHEAD $1:$tag
         done
     fi
 
@@ -125,39 +149,50 @@ timer_reset
 # clean up the docker build environment
 cd "$WORKSPACE"
 
-tools/arvbox/bin/arvbox rebuild localdemo
-ECODE=$?
+if [[ "$images" =~ demo ]]; then
+  title "Starting arvbox build localdemo"
+
+  tools/arvbox/bin/arvbox build localdemo
+  ECODE=$?
 
-if [[ "$ECODE" != "0" ]]; then
-    title "!!!!!! docker BUILD FAILED !!!!!!"
-    EXITCODE=$(($EXITCODE + $ECODE))
+  if [[ "$ECODE" != "0" ]]; then
+      title "!!!!!! docker BUILD FAILED !!!!!!"
+      EXITCODE=$(($EXITCODE + $ECODE))
+  fi
 fi
 
-tools/arvbox/bin/arvbox build dev
+if [[ "$images" =~ dev ]]; then
+  title "Starting arvbox build dev"
 
-ECODE=$?
+  tools/arvbox/bin/arvbox build dev
 
-if [[ "$ECODE" != "0" ]]; then
-    title "!!!!!! docker BUILD FAILED !!!!!!"
-    EXITCODE=$(($EXITCODE + $ECODE))
+  ECODE=$?
+
+  if [[ "$ECODE" != "0" ]]; then
+      title "!!!!!! docker BUILD FAILED !!!!!!"
+      EXITCODE=$(($EXITCODE + $ECODE))
+  fi
 fi
 
 title "docker build complete (`timer`)"
 
-title "uploading images"
-
-timer_reset
-
-if [[ "$ECODE" != "0" ]]; then
+if [[ "$EXITCODE" != "0" ]]; then
     title "upload arvados images SKIPPED because build failed"
 else
     if [[ $upload == true ]]; then
+        title "uploading images"
+        timer_reset
+
         ## 20150526 nico -- *sometimes* dockerhub needs re-login
         ## even though credentials are already in .dockercfg
         docker login -u arvados
 
-        docker_push arvados/arvbox-dev
-        docker_push arvados/arvbox-demo
+        if [[ "$images" =~ dev ]]; then
+          docker_push arvados/arvbox-dev
+        fi
+        if [[ "$images" =~ demo ]]; then
+          docker_push arvados/arvbox-demo
+        fi
         title "upload arvados images complete (`timer`)"
     else
         title "upload arvados images SKIPPED because no --upload option set"