Add support for ubuntu 18.04 (aka 'bionic') to run_upload_packages.py
[arvados-dev.git] / jenkins / run-deploy.sh
index 8dcf56b52a3ec520e31be5de21c2e54fbd9c8f8b..72cc7448701c3779627a92353986866937233747 100755 (executable)
@@ -1,7 +1,12 @@
 #!/bin/bash
 
+# Copyright (C) The Arvados Authors. All rights reserved.
+#
+# SPDX-License-Identifier: AGPL-3.0
+
 DEBUG=0
 SSH_PORT=22
+PUPPET_CONCURRENCY=5
 
 read -d] -r SCOPES <<EOF
 --scopes
@@ -33,7 +38,9 @@ function usage {
     echo >&2 "   <identifier>                 Arvados cluster name"
     echo >&2
     echo >&2 "$0 options:"
+    echo >&2 "  -n, --node <node>             Single machine to deploy, use fqdn, optional"
     echo >&2 "  -p, --port <ssh port>         SSH port to use (default 22)"
+    echo >&2 "  -c, --concurrency <max>       Maximum concurrency for puppet runs (default 5)"
     echo >&2 "  -d, --debug                   Enable debug output"
     echo >&2 "  -h, --help                    Display this help and exit"
     echo >&2
@@ -45,8 +52,8 @@ function usage {
 
 
 # NOTE: This requires GNU getopt (part of the util-linux package on Debian-based distros).
-TEMP=`getopt -o hdp: \
-    --long help,debug,port: \
+TEMP=`getopt -o hdp:c:n: \
+    --long help,debug,port:,concurrency:,node: \
     -n "$0" -- "$@"`
 
 if [ $? != 0 ] ; then echo "Use -h for help"; exit 1 ; fi
@@ -56,9 +63,15 @@ eval set -- "$TEMP"
 while [ $# -ge 1 ]
 do
     case $1 in
+        -n | --node)
+            NODE="$2"; shift 2
+            ;;
         -p | --port)
             SSH_PORT="$2"; shift 2
             ;;
+        -c | --concurrency)
+            PUPPET_CONCURRENCY="$2"; shift 2
+            ;;
         -d | --debug)
             DEBUG=1
             shift
@@ -180,20 +193,22 @@ function run_command() {
   eval "$return_var=$ECODE"
 }
 
-title "Updating API server"
-SUM_ECODE=0
-run_puppet $IDENTIFIER.arvadosapi.com ECODE
-SUM_ECODE=$(($SUM_ECODE + $ECODE))
-if [ ! "$IDENTIFIER" = "c97qk" ]
-then
-  run_command $IDENTIFIER.arvadosapi.com ECODE "dpkg -L arvados-mailchimp-plugin 2>/dev/null && apt-get install arvados-mailchimp-plugin --reinstall || echo"
+if [[ "$NODE" == "" ]] || [[ "$NODE" == "$IDENTIFIER.arvadosapi.com" ]]; then
+  title "Updating API server"
+  SUM_ECODE=0
+  run_puppet $IDENTIFIER.arvadosapi.com ECODE
   SUM_ECODE=$(($SUM_ECODE + $ECODE))
+
+  if [[ "$SUM_ECODE" != "0" ]]; then
+    title "ERROR: Updating API server FAILED"
+    EXITCODE=$(($EXITCODE + $SUM_ECODE))
+    exit $EXITCODE
+  fi
 fi
 
-if [[ "$SUM_ECODE" != "0" ]]; then
-  title "ERROR: Updating API server FAILED"
-  EXITCODE=$(($EXITCODE + $SUM_ECODE))
-  exit $EXITCODE
+if [[ "$NODE" == "$IDENTIFIER.arvadosapi.com" ]]; then
+       # we are done
+       exit 0
 fi
 
 title "Loading ARVADOS_API_HOST and ARVADOS_API_TOKEN"
@@ -208,8 +223,8 @@ if [[ "$ARVADOS_API_HOST" == "" ]] || [[ "$ARVADOS_API_TOKEN" == "" ]]; then
 fi
 
 title "Gathering list of shell and Keep nodes"
-SHELL_NODES=`ARVADOS_API_HOST=$ARVADOS_API_HOST ARVADOS_API_TOKEN=$ARVADOS_API_TOKEN arv virtual_machine list |jq .items[].hostname -r`
-KEEP_NODES=`ARVADOS_API_HOST=$ARVADOS_API_HOST ARVADOS_API_TOKEN=$ARVADOS_API_TOKEN arv keep_service list |jq .items[].service_host -r`
+SHELL_NODES=`ARVADOS_API_HOST=$ARVADOS_API_HOST ARVADOS_API_TOKEN=$ARVADOS_API_TOKEN rvm-exec default arv virtual_machine list |jq .items[].hostname -r`
+KEEP_NODES=`ARVADOS_API_HOST=$ARVADOS_API_HOST ARVADOS_API_TOKEN=$ARVADOS_API_TOKEN rvm-exec default arv keep_service list |jq .items[].service_host -r`
 
 nodes=""
 for n in workbench manage switchyard $SHELL_NODES $KEEP_NODES; do
@@ -221,60 +236,73 @@ for n in workbench manage switchyard $SHELL_NODES $KEEP_NODES; do
     # e.g. shell
     node=$n.$ARVADOS_API_HOST
   fi
-  # e.g. keep.qr1hi
-  nodes="$nodes ${node%.arvadosapi.com}"
+       if [[ "$NODE" == "" ]] || [[ "$NODE" == "$node" ]]; then
+         # e.g. keep.qr1hi
+         nodes="$nodes ${node%.arvadosapi.com}"
+       fi
 done
 
-## at this point nodes should be an array containing
-## manage.qr1hi,  keep.qr1hi, etc
-## that should be defined in the .ssh/config file
-title "Updating in parallel: $nodes"
-export -f run_puppet
-export -f title
-export SSH_PORT
-export PUPPET_AGENT
-echo $nodes|xargs -d " " -n 1 -P 10 -I {} bash -c "run_puppet {}"
+if [[ "$nodes" != "" ]]; then
+  ## at this point nodes should be an array containing
+  ## manage.qr1hi,  keep.qr1hi, etc
+  ## that should be defined in the .ssh/config file
+  title "Updating in parallel: $nodes"
+  export -f run_puppet
+  export -f title
+  export SSH_PORT
+  export PUPPET_AGENT
+  echo $nodes|xargs -d " " -n 1 -P $PUPPET_CONCURRENCY -I {} bash -c "run_puppet {}"
+fi
 
-title "Locating Arvados Standard Docker images project"
+if [[ "$NODE" == "" ]]; then
+  title "Locating Arvados Standard Docker images project"
 
-JSON_FILTER="[[\"name\", \"=\", \"Arvados Standard Docker Images\"], [\"owner_uuid\", \"=\", \"$IDENTIFIER-tpzed-000000000000000\"]]"
-DOCKER_IMAGES_PROJECT=`ARVADOS_API_HOST=$ARVADOS_API_HOST ARVADOS_API_TOKEN=$ARVADOS_API_TOKEN arv --format=uuid group list --filters="$JSON_FILTER"`
+  JSON_FILTER="[[\"name\", \"=\", \"Arvados Standard Docker Images\"], [\"owner_uuid\", \"=\", \"$IDENTIFIER-tpzed-000000000000000\"]]"
+  DOCKER_IMAGES_PROJECT=`ARVADOS_API_HOST=$ARVADOS_API_HOST ARVADOS_API_TOKEN=$ARVADOS_API_TOKEN arv --format=uuid group list --filters="$JSON_FILTER"`
 
-if [[ "$DOCKER_IMAGES_PROJECT" == "" ]]; then
-  title "Warning: Arvados Standard Docker Images project not found. Creating it."
+  if [[ "$DOCKER_IMAGES_PROJECT" == "" ]]; then
+    title "Warning: Arvados Standard Docker Images project not found. Creating it."
 
-  DOCKER_IMAGES_PROJECT=`ARVADOS_API_HOST=$ARVADOS_API_HOST ARVADOS_API_TOKEN=$ARVADOS_API_TOKEN arv --format=uuid group create --group "{\"owner_uuid\":\"$IDENTIFIER-tpzed-000000000000000\", \"name\":\"Arvados Standard Docker Images\", \"group_class\":\"project\"}"`
-  ARVADOS_API_HOST=$ARVADOS_API_HOST ARVADOS_API_TOKEN=$ARVADOS_API_TOKEN arv link create --link "{\"tail_uuid\":\"$IDENTIFIER-j7d0g-fffffffffffffff\", \"head_uuid\":\"$DOCKER_IMAGES_PROJECT\", \"link_class\":\"permission\", \"name\":\"can_read\" }"
-  if [[ "$?" != "0" ]]; then
-    title "ERROR: could not create standard Docker images project Please create it, cf. http://doc.arvados.org/install/create-standard-objects.html"
-    exit 1
+    DOCKER_IMAGES_PROJECT=`ARVADOS_API_HOST=$ARVADOS_API_HOST ARVADOS_API_TOKEN=$ARVADOS_API_TOKEN arv --format=uuid group create --group "{\"owner_uuid\":\"$IDENTIFIER-tpzed-000000000000000\", \"name\":\"Arvados Standard Docker Images\", \"group_class\":\"project\"}"`
+    ARVADOS_API_HOST=$ARVADOS_API_HOST ARVADOS_API_TOKEN=$ARVADOS_API_TOKEN arv link create --link "{\"tail_uuid\":\"$IDENTIFIER-j7d0g-fffffffffffffff\", \"head_uuid\":\"$DOCKER_IMAGES_PROJECT\", \"link_class\":\"permission\", \"name\":\"can_read\" }"
+    if [[ "$?" != "0" ]]; then
+      title "ERROR: could not create standard Docker images project Please create it, cf. http://doc.arvados.org/install/create-standard-objects.html"
+      exit 1
+    fi
   fi
-fi
 
-title "Found Arvados Standard Docker Images project with uuid $DOCKER_IMAGES_PROJECT"
-GIT_COMMIT=`ssh -o "StrictHostKeyChecking no" shell.$IDENTIFIER "python -c 'import arvados_cwl ; print arvados_cwl.__version__'"`
+  title "Found Arvados Standard Docker Images project with uuid $DOCKER_IMAGES_PROJECT"
+  GIT_COMMIT=`ssh -o "StrictHostKeyChecking no" shell.$IDENTIFIER "python -c 'import arvados_cwl ; print arvados_cwl.__version__'" 2>&1 |grep -v INFO:rdflib:RDFLib`
 
-if [[ "$?" != "0" ]] || [[ "$GIT_COMMIT" == "" ]]; then
-  title "ERROR: unable to get arvados/jobs Docker image git revision"
-  exit 1
-else
-  title "Found git commit for arvados/jobs Docker image: $GIT_COMMIT"
-fi
+  if [[ "$?" != "0" ]] || [[ "$GIT_COMMIT" == "" ]]; then
+    title "ERROR: unable to get arvados/jobs Docker image git revision"
+    exit 1
+  else
+    title "Found git commit for arvados/jobs Docker image: $GIT_COMMIT"
+  fi
 
-run_command shell.$IDENTIFIER ECODE "ARVADOS_API_HOST=$ARVADOS_API_HOST ARVADOS_API_TOKEN=$ARVADOS_API_TOKEN /usr/local/rvm/bin/rvm-exec default arv keep docker" |grep -q $GIT_COMMIT
+  run_command shell.$IDENTIFIER ECODE "ARVADOS_API_HOST=$ARVADOS_API_HOST ARVADOS_API_TOKEN=$ARVADOS_API_TOKEN /usr/local/rvm/bin/rvm-exec default arv keep docker" |grep -q $GIT_COMMIT
 
-if [[ "$?" == "0" ]]; then
-  title "Found latest arvados/jobs Docker image, nothing to upload"
-  # Just in case it isn't yet, tag the image as latest
-  ssh -o "StrictHostKeyChecking no" shell.$IDENTIFIER "ARVADOS_API_HOST=$ARVADOS_API_HOST ARVADOS_API_TOKEN=$ARVADOS_API_TOKEN arv-keepdocker arvados/jobs latest"
-else
-  title "Installing latest arvados/jobs Docker image"
-  ssh -o "StrictHostKeyChecking no" shell.$IDENTIFIER "ARVADOS_API_HOST=$ARVADOS_API_HOST ARVADOS_API_TOKEN=$ARVADOS_API_TOKEN /usr/local/rvm/bin/rvm-exec default arv keep docker --pull --project-uuid=$DOCKER_IMAGES_PROJECT arvados/jobs $GIT_COMMIT"
-  ## adding latest tag too  refs 9254
-  ssh -o "StrictHostKeyChecking no" shell.$IDENTIFIER docker tag -f arvados/jobs:$GIT_COMMIT arvados/jobs:latest
-  ssh -o "StrictHostKeyChecking no" shell.$IDENTIFIER "ARVADOS_API_HOST=$ARVADOS_API_HOST ARVADOS_API_TOKEN=$ARVADOS_API_TOKEN arv-keepdocker --project-uuid=$DOCKER_IMAGES_PROJECT arvados/jobs latest"
-  if [[ "$?" -ne 0 ]]; then
-    title "'git pull' failed exiting..."
-    exit 1
+  if [[ "$?" == "0" ]]; then
+    title "Found latest arvados/jobs Docker image, nothing to upload"
+    # Just in case it isn't yet, tag the image as latest
+    ssh -o "StrictHostKeyChecking no" shell.$IDENTIFIER "ARVADOS_API_HOST=$ARVADOS_API_HOST ARVADOS_API_TOKEN=$ARVADOS_API_TOKEN arv-keepdocker arvados/jobs latest"
+  else
+    title "Installing latest arvados/jobs Docker image"
+    ssh -o "StrictHostKeyChecking no" shell.$IDENTIFIER "ARVADOS_API_HOST=$ARVADOS_API_HOST ARVADOS_API_TOKEN=$ARVADOS_API_TOKEN /usr/local/rvm/bin/rvm-exec default arv keep docker --pull --project-uuid=$DOCKER_IMAGES_PROJECT arvados/jobs $GIT_COMMIT"
+    ssh -o "StrictHostKeyChecking no" shell.$IDENTIFIER docker tag --force >/dev/null 2>&1
+    # docker 1.13 no longer supports --force. Sigh.
+    if [[ "$?" == "125" ]]; then
+      FORCE_TAG=""
+    else
+      FORCE_TAG="--force"
+    fi
+    ## adding latest tag too  refs 9254
+    ssh -o "StrictHostKeyChecking no" shell.$IDENTIFIER docker tag $FORCE_TAG arvados/jobs:$GIT_COMMIT arvados/jobs:latest
+    ssh -o "StrictHostKeyChecking no" shell.$IDENTIFIER "ARVADOS_API_HOST=$ARVADOS_API_HOST ARVADOS_API_TOKEN=$ARVADOS_API_TOKEN arv-keepdocker --project-uuid=$DOCKER_IMAGES_PROJECT arvados/jobs latest"
+    if [[ "$?" -ne 0 ]]; then
+      title "'git pull' failed exiting..."
+      exit 1
+    fi
   fi
 fi