#!/bin/bash read -rd "\000" helpmessage < Distribution to build packages for (default: debian7) --command Build command to execute (default: use built-in Docker image command) --debug Output debug information (default: false) WORKSPACE=path Path to the Arvados source tree to build packages from EOF if ! [[ -n "$WORKSPACE" ]]; then echo >&2 "$helpmessage" echo >&2 echo >&2 "Error: WORKSPACE environment variable not set" echo >&2 exit 1 fi if ! [[ -d "$WORKSPACE" ]]; then echo >&2 "$helpmessage" echo >&2 echo >&2 "Error: $WORKSPACE is not a directory" echo >&2 exit 1 fi PARSEDOPTS=$(getopt --name "$0" --longoptions \ help,debug,target:,command: \ -- "" "$@") if [ $? -ne 0 ]; then exit 1 fi TARGET=debian7 COMMAND= DEBUG= eval set -- "$PARSEDOPTS" while [ $# -gt 0 ]; do case "$1" in --help) echo >&2 "$helpmessage" echo >&2 exit 1 ;; --target) TARGET="$2"; shift ;; --debug) DEBUG=" --debug" ;; --command) COMMAND="$2"; shift ;; --) if [ $# -gt 1 ]; then echo >&2 "$0: unrecognized argument '$2'. Try: $0 --help" exit 1 fi ;; esac shift done set -e if [[ "$COMMAND" != "" ]]; then COMMAND="/usr/local/rvm/bin/rvm-exec default bash /jenkins/$COMMAND --target $TARGET$DEBUG" 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 } # 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 .. run_docker $TARGET exit $FINAL_EXITCODE