cleans up debian/changelog generation per tomclegg's comment
[arvados.git] / jenkins / run-build-packages-one-target.sh
index ea0718e0e2b05fd8cd61d27ebdc6982e178958f1..95977030fcec0ed01aad02a965c98aa0cac6151a 100755 (executable)
@@ -10,11 +10,19 @@ Syntax:
     Distribution to build packages for (default: debian7)
 --command
     Build command to execute (default: use built-in Docker image command)
+--test-packages
+    Run package install test script "test-packages-$target.sh"
+--debug
+    Output debug information (default: false)
+--only-test
+    Test only a specific package
 
 WORKSPACE=path         Path to the Arvados source tree to build packages from
 
 EOF
 
+set -e
+
 if ! [[ -n "$WORKSPACE" ]]; then
   echo >&2 "$helpmessage"
   echo >&2
@@ -32,7 +40,7 @@ if ! [[ -d "$WORKSPACE" ]]; then
 fi
 
 PARSEDOPTS=$(getopt --name "$0" --longoptions \
-    help,target:,command: \
+    help,debug,test-packages,target:,command:,only-test: \
     -- "" "$@")
 if [ $? -ne 0 ]; then
     exit 1
@@ -40,6 +48,7 @@ fi
 
 TARGET=debian7
 COMMAND=
+DEBUG=
 
 eval set -- "$PARSEDOPTS"
 while [ $# -gt 0 ]; do
@@ -52,9 +61,18 @@ while [ $# -gt 0 ]; do
         --target)
             TARGET="$2"; shift
             ;;
+        --only-test)
+            packages="$2"; shift
+            ;;
+        --debug)
+            DEBUG=" --debug"
+            ;;
         --command)
             COMMAND="$2"; shift
             ;;
+        --test-packages)
+            test_packages=1
+            ;;
         --)
             if [ $# -gt 1 ]; then
                 echo >&2 "$0: unrecognized argument '$2'. Try: $0 --help"
@@ -67,38 +85,98 @@ done
 
 set -e
 
-if [[ "$COMMAND" != "" ]]; then
-  COMMAND="/usr/local/rvm/bin/rvm-exec default bash /jenkins/$COMMAND --target $TARGET"
+if [[ -n "$test_packages" ]]; then
+    if [[ -n "$(find $WORKSPACE/packages/$TARGET -name *.rpm)" ]] ; then
+        createrepo $WORKSPACE/packages/$TARGET
+    fi
+
+    if [[ -n "$(find $WORKSPACE/packages/$TARGET -name *.deb)" ]] ; then
+        (cd $WORKSPACE/packages/$TARGET
+         dpkg-scanpackages .  2> >(grep -v 'warning' 1>&2) | gzip -c > Packages.gz
+        )
+    fi
+
+    COMMAND="/jenkins/package-testing/test-packages-$TARGET.sh"
+    IMAGE="arvados/package-test:$TARGET"
+else
+    IMAGE="arvados/build:$TARGET"
+    if [[ "$COMMAND" != "" ]]; then
+        COMMAND="/usr/local/rvm/bin/rvm-exec default bash /jenkins/$COMMAND --target $TARGET$DEBUG"
+    fi
 fi
 
-FINAL_EXITCODE=0
 JENKINS_DIR=$(dirname "$(readlink -e "$0")")
 
-run_docker() {
-    local tag=$1; shift
-    if docker run -v "$JENKINS_DIR:/jenkins" -v "$WORKSPACE:/arvados" \
-          --env ARVADOS_DEBUG=1 "arvados/build:$tag" $COMMAND; then
-        # Success - nothing more to do.
-        true
-    else
-        FINAL_EXITCODE=$?
-        echo "ERROR: $tag build failed with exit status $FINAL_EXITCODE." >&2
-    fi
-}
+if [[ -n "$test_packages" ]]; then
+    pushd "$JENKINS_DIR/package-test-dockerfiles"
+else
+    pushd "$JENKINS_DIR/package-build-dockerfiles"
+    make "$TARGET/generated"
+fi
 
-# In case it's needed, build the container. This costs just a few
-# seconds when the container already exist, so it's not a big deal to
-# do it on each run.
-cd "$JENKINS_DIR/dockerfiles"
 echo $TARGET
 cd $TARGET
-time docker build -t arvados/build:$TARGET .
-cd ..
+time docker build --tag=$IMAGE .
+popd
+
+if test -z "$packages" ; then
+    packages="arvados-api-server
+        arvados-data-manager
+        arvados-docker-cleaner
+        arvados-git-httpd
+        arvados-node-manager
+        arvados-src
+        arvados-workbench
+        crunchstat
+        keepproxy
+        keep-rsync
+        keepstore
+        keep-web
+        libarvados-perl"
+
+    case "$TARGET" in
+        centos6)
+            packages="$packages python27-python-arvados-fuse
+                  python27-python-arvados-python-client"
+        ;;
+        *)
+            packages="$packages python-arvados-fuse
+                  python-arvados-python-client"
+            ;;
+    esac
+fi
 
-run_docker $TARGET
+FINAL_EXITCODE=0
 
-#for dockerfile_path in $(find -name Dockerfile); do
-#    run_docker "$(basename $(dirname "$dockerfile_path"))"
-#done
+package_fails=""
+
+if [[ -n "$test_packages" ]]; then
+    for p in $packages ; do
+        if docker run --rm -v "$JENKINS_DIR:/jenkins" -v "$WORKSPACE:/arvados" \
+               --env ARVADOS_DEBUG=1 \
+               --env "TARGET=$TARGET" \
+               --env "WORKSPACE=/arvados" \
+               "$IMAGE" $COMMAND $p ; then
+            true
+        else
+            FINAL_EXITCODE=$?
+            package_fails="$package_fails $p"
+            echo "ERROR: $tag test failed with exit status $FINAL_EXITCODE." >&2
+        fi
+    done
+else
+    if docker run --rm -v "$JENKINS_DIR:/jenkins" -v "$WORKSPACE:/arvados" \
+           --env ARVADOS_DEBUG=1 "$IMAGE" $COMMAND ; then
+        echo
+        echo "Build packages for $TARGET succeeded." >&2
+    else
+        FINAL_EXITCODE=$?
+        echo "ERROR: $tag build failed with exit status $FINAL_EXITCODE." >&2
+    fi
+fi
+
+if test -n "$package_fails" ; then
+    echo "Failed package tests:$package_fails" >&2
+fi
 
 exit $FINAL_EXITCODE