From 984848632f6d553a26661058c9b3561303e8d747 Mon Sep 17 00:00:00 2001 From: Ward Vandewege Date: Tue, 3 Jun 2014 11:25:10 -0400 Subject: [PATCH] Initial commit of the scripts used in our Jenkins pipelines. --- jenkins/run-build-packages.sh | 177 ++++++++++++++++++++++++++ jenkins/run-deploy.sh | 113 +++++++++++++++++ jenkins/run-tapestry-tests.sh | 54 ++++++++ jenkins/run-tests.sh | 233 ++++++++++++++++++++++++++++++++++ 4 files changed, 577 insertions(+) create mode 100755 jenkins/run-build-packages.sh create mode 100755 jenkins/run-deploy.sh create mode 100755 jenkins/run-tapestry-tests.sh create mode 100755 jenkins/run-tests.sh diff --git a/jenkins/run-build-packages.sh b/jenkins/run-build-packages.sh new file mode 100755 index 0000000..78ee2ee --- /dev/null +++ b/jenkins/run-build-packages.sh @@ -0,0 +1,177 @@ +#!/bin/bash + +EXITCODE=0 +CALL_PRM=0 + +APTUSER=$1 +APTSERVER=$2 + +if [[ "$APTUSER" == '' ]]; then + echo "Syntax: $0 " + exit 1 +fi + +if [[ "$APTSERVER" == '' ]]; then + echo "Syntax: $0 " + exit 1 +fi + +source /etc/profile.d/rvm.sh +echo $WORKSPACE + +# Build arvados GEM +echo "Build and publish ruby gem" +cd "$WORKSPACE" +cd sdk/ruby +# clean up old gems +rm -f arvados-*gem +gem build arvados.gemspec +# publish new gem +gem push arvados-*gem + +# Build arvados-cli GEM +echo "Build and publish ruby gem" +cd "$WORKSPACE" +cd sdk/cli +# clean up old gems +rm -f arvados-cli*gem +gem build arvados-cli.gemspec +# publish new gem +gem push arvados-cli*gem + +# Build arvados-python-client Python package +echo "Build and publish arvados-python-client package" +cd "$WORKSPACE" + +GIT_HASH=`git log --format=format:%ct.%h -n1 .` + +cd sdk/python + +# We mess with this file below, reset it here +git checkout setup.py + +# Make sure only to use sdist - that's the only format pip can deal with (sigh) +python setup.py egg_info -b ".$GIT_HASH" sdist upload + +cd ../../services/fuse + +# We mess with this file below, reset it here +git checkout setup.py + +# Make sure only to use sdist - that's the only format pip can deal with (sigh) +python setup.py egg_info -b ".$GIT_HASH" sdist upload + +# Build debs for everything + +build_and_scp_deb () { + PACKAGE=$1 + PACKAGE_NAME=$2 + # Put spaces in $3 and you will regret it. Despite the use of arrays below. + # Because, bash sucks. + VENDOR=${3// /_} + PACKAGE_TYPE=$4 + EXTRA_ARGUMENTS=$5 + + if [[ "$PACKAGE_NAME" == "" ]]; then + PACKAGE_NAME=$PACKAGE + fi + + if [[ "$PACKAGE_TYPE" == "" ]]; then + PACKAGE_TYPE='python' + fi + + COMMAND_ARR=("fpm" "-s" "$PACKAGE_TYPE" "-t" "deb") + + if [[ "$PACKAGE_NAME" != "$PACKAGE" ]]; then + COMMAND_ARR+=('-n' "$PACKAGE_NAME") + fi + + if [[ "$VENDOR" != "" ]]; then + COMMAND_ARR+=('--vendor' "$VENDOR") + fi + for a in $EXTRA_ARGUMENTS; do + COMMAND_ARR+=("$a") + done + + COMMAND_ARR+=("$PACKAGE") + + FPM_RESULTS=$(${COMMAND_ARR[@]}) + FPM_EXIT_CODE=$? + echo ${COMMAND_ARR[@]} + if [[ ! $FPM_RESULTS =~ "File already exists" ]]; then + if [[ "$FPM_EXIT_CODE" != "0" ]]; then + echo "Error building debian package for $1:\n $FPM_RESULTS" + else + scp -P2222 $PACKAGE_NAME*.deb $APTUSER@$APTSERVER:tmp/ + CALL_PRM=1 + fi + else + echo "Debian package for $1 exists, not rebuilding" + fi +} + +if [[ ! -d "$WORKSPACE/debs" ]]; then + mkdir -p $WORKSPACE/debs +fi + +# Make sure our destination directory on $APTSERVER exists - prm can delete it when invoked improperly +ssh -p2222 $APTUSER@$APTSERVER mkdir tmp + +# Keep +cd $WORKSPACE/services/keep +./go.sh install keep +cd $WORKSPACE/debs +build_and_scp_deb $WORKSPACE/services/keep/bin/keep=/usr/bin/keep keep 'Curoverse, Inc.' 'dir' "-v 0.1.$GIT_HASH" + +# Keep proxy + +# First build the keepclient library +cd $WORKSPACE/sdk/go +./go.sh install arvados.org/keepclient + +# Then keepproxy +cd $WORKSPACE/services/keep +./go.sh install arvados.org/keepproxy +cd $WORKSPACE/debs +build_and_scp_deb $WORKSPACE/services/keep/bin/keepproxy=/usr/bin/keepproxy keepproxy 'Curoverse, Inc.' 'dir' "-v 0.1.$GIT_HASH" + +# The Python SDK +cd $WORKSPACE/sdk/python +sed -i'' -e "s:version='0.1':version='0.1.$GIT_HASH':" setup.py + +cd $WORKSPACE/debs + +# Please resist the temptation to add --no-python-fix-name to the fpm call here +# (which would remove the python- prefix from the package name), because this +# package is a dependency of arvados-fuse, and fpm can not omit the python- +# prefix from only one of the dependencies of a package... Maybe I could +# whip up a patch and send it upstream, but that will be for another day. Ward, +# 2014-05-15 +build_and_scp_deb $WORKSPACE/sdk/python python-arvados-python-client 'Curoverse, Inc.' 'python' "-v 0.1.${GIT_HASH}" + +# The FUSE driver +cd $WORKSPACE/services/fuse +sed -i'' -e "s:version='0.1':version='0.1.$GIT_HASH':" setup.py + + +cd $WORKSPACE/debs + +# Please seem comment about --no-python-fix-name above; we stay consistent and do +# not omit the python- prefix first. +build_and_scp_deb $WORKSPACE/services/fuse python-arvados-fuse 'Curoverse, Inc.' 'python' "-v 0.1.${GIT_HASH}" + +# A few dependencies +build_and_scp_deb python-gflags +build_and_scp_deb pyvcf +build_and_scp_deb google-api-python-client +build_and_scp_deb httplib2 +build_and_scp_deb ws4py +build_and_scp_deb virtualenv + +# Finally, publish the packages, if necessary +if [[ "$CALL_PRM" != "0" ]]; then + ssh -p2222 $APTUSER@$APTSERVER -t "cd /var/www/$APTSERVER; /usr/local/rvm/bin/rvm default do prm --type deb -p . --component main --release wheezy --arch amd64 -d /home/$APTUSER/tmp/ --gpg 1078ECD7" +else + echo "No new packages generated. No PRM run necessary." +fi + diff --git a/jenkins/run-deploy.sh b/jenkins/run-deploy.sh new file mode 100755 index 0000000..c23aefc --- /dev/null +++ b/jenkins/run-deploy.sh @@ -0,0 +1,113 @@ +#!/bin/bash + +IDENTIFIER=$1 +DEPLOY_REPO=$2 + +if [[ "$IDENTIFIER" == '' ]]; then + echo "Syntax: $0 " + exit 1 +fi + +if [[ "$DEPLOY_REPO" == '' ]]; then + echo "Syntax: $0 " + exit 1 +fi + +EXITCODE=0 + +COLUMNS=80 + +title () { + printf "\n%*s\n\n" $(((${#title}+$COLUMNS)/2)) "********** $1 **********" +} + +# We only install capistrano in dev mode +export RAILS_ENV=development + +source /etc/profile.d/rvm.sh +echo $WORKSPACE + +# Weirdly, jenkins/rvm ties itself in a knot. +rvm use default + +# Just say what version of ruby we're running +ruby --version + +function ensure_symlink() { + if [[ ! -L $WORKSPACE/$1 ]]; then + ln -s $WORKSPACE/$DEPLOY_REPO/$1 $WORKSPACE/$1 + fi +} + +# Check out/update the $DEPLOY_REPO repository +if [[ ! -d $DEPLOY_REPO ]]; then + mkdir $DEPLOY_REPO + git clone git@git.curoverse.com:$DEPLOY_REPO.git +else + cd $DEPLOY_REPO + git pull +fi + +# Make sure the necessary symlinks are in place +cd "$WORKSPACE" +ensure_symlink "apps/workbench/Capfile.workbench.$IDENTIFIER" +ensure_symlink "apps/workbench/config/deploy.common.rb" +ensure_symlink "apps/workbench/config/deploy.curoverse.rb" +ensure_symlink "apps/workbench/config/deploy.workbench.$IDENTIFIER.rb" + +ensure_symlink "services/api/Capfile.$IDENTIFIER" +ensure_symlink "services/api/config/deploy.common.rb" +ensure_symlink "services/api/config/deploy.$IDENTIFIER.rb" + +# Deploy API server +title "Deploying API server" +cd "$WORKSPACE" +cd services/api + +bundle install --deployment + +# make sure we do not print the output of config:check +sed -i'' -e "s/RAILS_ENV=production #{rake} config:check/RAILS_ENV=production QUIET=true #{rake} config:check/" $WORKSPACE/$DEPLOY_REPO/services/api/config/deploy.common.rb + +bundle exec cap deploy -f Capfile.$IDENTIFIER + +ECODE=$? + +# restore unaltered deploy.common.rb +cd $WORKSPACE/$DEPLOY_REPO +git checkout services/api/config/deploy.common.rb + +if [[ "$ECODE" != "0" ]]; then + title "!!!!!! DEPLOYING API SERVER FAILED !!!!!!" + EXITCODE=$(($EXITCODE + $ECODE)) + exit $EXITCODE +fi + +title "Deploying API server complete" + +# Deploy Workbench +title "Deploying workbench" +cd "$WORKSPACE" +cd apps/workbench +bundle install --deployment + +# make sure we do not print the output of config:check +sed -i'' -e "s/RAILS_ENV=production #{rake} config:check/RAILS_ENV=production QUIET=true #{rake} config:check/" $WORKSPACE/$DEPLOY_REPO/apps/workbench/config/deploy.common.rb + +bundle exec cap deploy -f Capfile.workbench.$IDENTIFIER + +ECODE=$? + +# restore unaltered deploy.common.rb +cd $WORKSPACE/$DEPLOY_REPO +git checkout apps/workbench/config/deploy.common.rb + +if [[ "$ECODE" != "0" ]]; then + title "!!!!!! DEPLOYING WORKBENCH FAILED !!!!!!" + EXITCODE=$(($EXITCODE + $ECODE)) + exit $EXITCODE +fi + +title "Deploying workbench complete" + +exit $EXITCODE diff --git a/jenkins/run-tapestry-tests.sh b/jenkins/run-tapestry-tests.sh new file mode 100755 index 0000000..851a81d --- /dev/null +++ b/jenkins/run-tapestry-tests.sh @@ -0,0 +1,54 @@ +#!/bin/bash + +EXITCODE=0 + +COLUMNS=80 + +title () { + printf "\n%*s\n\n" $(((${#title}+$COLUMNS)/2)) "********** $1 **********" +} + +source /etc/profile.d/rvm.sh + +# This shouldn't really be necessary... but the jenkins/rvm integration seems a +# bit wonky occasionally. +rvm use ree + +echo $WORKSPACE + +# Tapestry +title "Starting tapestry tests" +cd "$WORKSPACE" + +# There are a few submodules +git submodule init && git submodule update + +# Use sqlite for testing +sed -i'' -e "s:mysql:sqlite3:" Gemfile + +# Tapestry is not set up yet to use --deployment +#bundle install --deployment +bundle install + +rm -f config/database.yml +rm -f config/environments/test.rb +cp $HOME/tapestry/test.rb config/environments/ +cp $HOME/tapestry/database.yml config/ + +export RAILS_ENV=test + +bundle exec rake db:drop +bundle exec rake db:create +bundle exec rake db:setup +bundle exec rake test + +ECODE=$? + +if [[ "$ECODE" != "0" ]]; then + title "!!!!!! TAPESTRY TESTS FAILED !!!!!!" + EXITCODE=$(($EXITCODE + $ECODE)) +fi + +title "Tapestry tests complete" + +exit $EXITCODE diff --git a/jenkins/run-tests.sh b/jenkins/run-tests.sh new file mode 100755 index 0000000..52fee76 --- /dev/null +++ b/jenkins/run-tests.sh @@ -0,0 +1,233 @@ +#!/bin/bash + +EXITCODE=0 + +COLUMNS=80 + +ARVADOS_API_HOST=qr1hi.arvadosapi.com + +title () { + printf "\n%*s\n\n" $(((${#title}+$COLUMNS)/2)) "********** $1 **********" +} + +source /etc/profile.d/rvm.sh +echo $WORKSPACE + +# DOCS +title "Starting DOC build" +cd "$WORKSPACE" +cd doc +bundle install --deployment +rm -rf .site +# Make sure python-epydoc is installed or the next line won't do much good! +PYTHONPATH=$WORKSPACE/sdk/python/ bundle exec rake generate baseurl=file://$WORKSPACE/doc/.site/ arvados_workbench_host=workbench.$ARVADOS_API_HOST arvados_api_host=$ARVADOS_API_HOST + +ECODE=$? + +if [[ "$ECODE" != "0" ]]; then + title "!!!!!! DOC BUILD FAILED !!!!!!" + EXITCODE=$(($EXITCODE + $ECODE)) +fi + +title "DOC build complete" + +# DOC linkchecker +title "Starting DOC linkchecker" +cd "$WORKSPACE" +cd doc +bundle exec rake linkchecker baseurl=file://$WORKSPACE/doc/.site/ + +ECODE=$? + +if [[ "$ECODE" != "0" ]]; then + title "!!!!!! DOC LINKCHECKER FAILED !!!!!!" + EXITCODE=$(($EXITCODE + $ECODE)) +fi + +title "DOC linkchecker complete" + +# API SERVER +title "Starting API server tests" +cd "$WORKSPACE" +cd services/api +bundle install --deployment + +rm -f config/database.yml +rm -f config/environments/test.rb +cp config/environments/test.rb.example config/environments/test.rb + +# Get test database config +cp $HOME/arvados-api-server/database.yml config/ +# Get test application.yml file +cp $HOME/arvados-api-server/application.yml config/ + +# Fill in a random secret_token and blob_signing_key for testing +SECRET_TOKEN=`echo 'puts rand(2**512).to_s(36)' |ruby` +BLOB_SIGNING_KEY=`echo 'puts rand(2**512).to_s(36)' |ruby` + +sed -i'' -e "s:SECRET_TOKEN:$SECRET_TOKEN:" config/application.yml +sed -i'' -e "s:BLOB_SIGNING_KEY:$BLOB_SIGNING_KEY:" config/application.yml + +export RAILS_ENV=test + +# Set up empty git repo (for git tests) +GITDIR=$WORKSPACE/tmpgit +rm -rf $GITDIR +mkdir $GITDIR +sed -i'' -e "s:/var/cache/git:$GITDIR:" config/application.default.yml + +rm -rf $GITDIR +mkdir -p $GITDIR/test +cd $GITDIR/test +/usr/bin/git init +/usr/bin/git config user.email "jenkins@ci.curoverse.com" +/usr/bin/git config user.name "Jenkins, CI" +touch tmp +/usr/bin/git add tmp +/usr/bin/git commit -m 'initial commit' + +cd "$WORKSPACE" +cd services/api + +bundle exec rake db:drop +bundle exec rake db:create +bundle exec rake db:setup +bundle exec rake test + +ECODE=$? + +if [[ "$ECODE" != "0" ]]; then + title "!!!!!! API SERVER TESTS FAILED !!!!!!" + EXITCODE=$(($EXITCODE + $ECODE)) +fi + +title "API server tests complete" + +# Keep +title "Starting Keep tests" +cd "$WORKSPACE" +cd services/keep/src/keep +GOPATH=$HOME/gocode go test + +ECODE=$? + +if [[ "$ECODE" != "0" ]]; then + title "!!!!!! Keep TESTS FAILED !!!!!!" + EXITCODE=$(($EXITCODE + $ECODE)) +fi + +title "Keep tests complete" + +# WORKBENCH +title "Starting workbench tests" +cd "$WORKSPACE" +cd apps/workbench +bundle install --deployment + +echo $PATH + + +bundle exec rake test + +ECODE=$? + +if [[ "$ECODE" != "0" ]]; then + title "!!!!!! WORKBENCH TESTS FAILED !!!!!!" + EXITCODE=$(($EXITCODE + $ECODE)) +fi + +title "Workbench tests complete" + +# Python SDK +title "Starting Python SDK tests" +cd "$WORKSPACE" +cd sdk/cli +bundle install --deployment + +# Set up Python SDK and dependencies + +cd "$WORKSPACE" +cd sdk/python + +VENVDIR=$(mktemp -d) +virtualenv --setuptools --system-site-packages "$VENVDIR" +"$VENVDIR/bin/pip" install -e . +GOPATH="$HOME/gocode" "$VENVDIR/bin/python" -m unittest discover tests + +ECODE=$? + +if [[ "$ECODE" != "0" ]]; then + title "!!!!!! Python SDK TESTS FAILED !!!!!!" + EXITCODE=$(($EXITCODE + $ECODE)) +fi + +"$VENVDIR/bin/python" setup.py egg_info -b ".$(git log --format=format:%ct.%h -n1 .)" sdist rotate --keep=1 +"$VENVDIR/bin/pip" install dist/arvados-python-client-0.1.*.tar.gz + +ECODE=$? + +if [[ "$ECODE" != "0" ]]; then + title "!!!!!! Python SDK install FAILED !!!!!!" + EXITCODE=$(($EXITCODE + $ECODE)) +fi + +cd "$WORKSPACE" +cd services/fuse + +# We reuse $VENVDIR from the Python SDK tests above +"$VENVDIR/bin/pip" install -e . +GOPATH="$HOME/gocode" "$VENVDIR/bin/python" -m unittest discover tests + +ECODE=$? + +if [[ "$ECODE" != "0" ]]; then + title "!!!!!! Fuse TESTS FAILED !!!!!!" + EXITCODE=$(($EXITCODE + $ECODE)) +fi + +"$VENVDIR/bin/python" setup.py egg_info -b ".$(git log --format=format:%ct.%h -n1 .)" sdist rotate --keep=1 +"$VENVDIR/bin/pip" install dist/arvados_fuse-0.1.*.tar.gz + +ECODE=$? + +if [[ "$ECODE" != "0" ]]; then + title "!!!!!! Fuse install FAILED !!!!!!" + EXITCODE=$(($EXITCODE + $ECODE)) +fi + +title "Python SDK tests complete" + +# Clean up $VENVDIR +rm -rf "$VENVDIR" + +# The CLI SDK tests require a working API server, so let's skip those for now. +exit $EXITCODE + +# CLI SDK +title "Starting SDK CLI tests" +cd "$WORKSPACE" +cd sdk/cli +bundle install --deployment + +# Set up Python SDK and dependencies +cd ../python +rm -rf $HOME/lib/python +mkdir $HOME/lib/python +PYTHONPATH="$HOME/lib/python" easy_install --install-dir=$HOME/lib/python --upgrade google-api-python-client +PYTHONPATH="$HOME/lib/python" python setup.py install --home=$HOME + +cd ../cli +mkdir -p /tmp/keep +export KEEP_LOCAL_STORE=/tmp/keep +PYTHONPATH="$HOME/lib/python" bundle exec rake test + +ECODE=$? + +if [[ "$ECODE" != "0" ]]; then + title "!!!!!! SDK CLI TESTS FAILED !!!!!!" + EXITCODE=$(($EXITCODE + $ECODE)) +fi + +title "SDK CLI tests complete" + +exit $EXITCODE -- 2.30.2