Pārlūkot izejas kodu

Merge pull request #661 from MayeulChassagnard/ContinuousIntegration

ENH: Add Continous Integration Support
Jean-Christophe Fillion-Robin 8 gadi atpakaļ
vecāks
revīzija
1dc6c81ab6

+ 80 - 0
CMake/CircleCI/CircleCI_CTK_Docker.cmake

@@ -0,0 +1,80 @@
+##############################################################################
+#
+# Library:   CTK
+#
+# Copyright 2010 Kitware Inc. 28 Corporate Drive,
+# Clifton Park, NY, 12065, USA.
+#
+# All rights reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#       http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+##############################################################################
+
+
+set( CTK_SOURCE_DIR "/usr/src/CTK" )
+set( CTK_BINARY_DIR "/usr/src/CTK-build" )
+
+set( CTEST_SOURCE_DIRECTORY "${CTK_SOURCE_DIR}" )
+set( CTEST_BINARY_DIRECTORY "${CTK_BINARY_DIR}/CTK-build" )
+
+#############
+
+set( SITE_CTEST_MODE "Experimental" ) # Experimental, Continuous, or Nightly
+
+set( CTEST_CMAKE_GENERATOR "Unix Makefiles" ) # Ninja or Unix Makefiles
+
+set( CTK_GIT_REPOSITORY "https://github.com/commontk/CTK.git" )
+
+# Follow format for caps and components as given on CTK dashboard
+set( CTEST_SITE "CircleCI_CTK" )
+
+# Follow format for caps and components as given on CTK dashboard
+set( SITE_PLATFORM "Ubuntu-64" )
+
+# Use SITE_BUILD_TYPE specified by circle.yml
+set( SITE_BUILD_TYPE "$ENV{SITE_BUILD_TYPE}" )
+if( NOT( (SITE_BUILD_TYPE MATCHES "Debug") OR (SITE_BUILD_TYPE MATCHES "Release") ) )
+  set( SITE_BUILD_TYPE "Debug" ) # Release, Debug
+endif( NOT( (SITE_BUILD_TYPE MATCHES "Debug") OR (SITE_BUILD_TYPE MATCHES "Release") ) )
+
+# Named SITE_BUILD_NAME
+string( SUBSTRING $ENV{CIRCLE_SHA1} 0 7 commit )
+set( what $ENV{CIRCLE_BRANCH} )
+set( SITE_BUILD_NAME_SUFFIX _${commit}_${what} )
+
+set( SITE_BUILD_NAME "CircleCI-${SITE_PLATFORM}-${SITE_BUILD_TYPE}${SITE_BUILD_NAME_SUFFIX}" )
+
+set( CTEST_BUILD_NAME "${SITE_BUILD_NAME}-BuildTest-${SITE_CTEST_MODE}" )
+
+###################
+
+set( CTEST_CONFIGURATION_TYPE "${SITE_BUILD_TYPE}")
+set( CMAKE_BUILD_TYPE "${SITE_BUILD_TYPE}")
+set( BUILD_TESTING ON )
+set( CTK_BUILD_EXAMPLES OFF )
+
+
+###################
+
+
+ctest_start( "${SITE_CTEST_MODE}" )
+
+ctest_configure( BUILD "${CTK_BINARY_DIR}"
+    SOURCE "${CTK_SOURCE_DIR}" )
+
+ctest_build( BUILD ${CTK_BINARY_DIR} )
+
+ctest_test( BUILD ${CTEST_BINARY_DIRECTORY} )
+
+ctest_submit()

+ 8 - 0
CMake/CircleCI/Dockerfile

@@ -0,0 +1,8 @@
+FROM thewtex/opengl:v0.1.0
+MAINTAINER Insight Software Consortium <community@itk.org>
+
+RUN apt-get update && apt-get install -y \
+  qt4-dev-tools \
+  cmake
+
+ENV APP "sudo chown -R user.user /usr/src/ && /usr/src/CTK/CMake/CircleCI/test.sh"

+ 5 - 0
CMake/CircleCI/build.sh

@@ -0,0 +1,5 @@
+#!/bin/sh
+
+script_dir="`cd $(dirname $0); pwd`"
+
+docker build -t commontk/ctk-test:opengl $script_dir

+ 8 - 0
CMake/CircleCI/push.sh

@@ -0,0 +1,8 @@
+#!/bin/sh
+
+die() {
+  echo "Error: $@" 1>&2
+  exit 1;
+}
+
+docker push commontk/ctk-test:opengl

+ 5 - 0
CMake/CircleCI/run.sh

@@ -0,0 +1,5 @@
+#!/bin/sh
+
+script_dir="`cd $(dirname $0); pwd`"
+
+$script_dir/run_opengl.sh -i commontk/ctk-test:opengl -p 6081 -r --env="CIRCLE_SHA1=$1" -r --env="CIRCLE_BRANCH=$2" -r --env="SITE_BUILD_TYPE=$3"

+ 150 - 0
CMake/CircleCI/run_opengl.sh

@@ -0,0 +1,150 @@
+#!/bin/bash
+
+container=opengl
+image=thewtex/opengl
+port=6080
+extra_run_args=""
+quiet=""
+
+show_help() {
+cat << EOF
+Usage: ${0##*/} [-h] [-q] [-c CONTAINER] [-i IMAGE] [-p PORT] [-r DOCKER_RUN_FLAGS]
+
+This script is a convenience script to run Docker images based on
+thewtex/opengl. It:
+
+- Makes sure docker is available
+- On Windows and Mac OSX, creates a docker machine if required
+- Informs the user of the URL to access the container with a web browser
+- Stops and removes containers from previous runs to avoid conflicts
+- Mounts the present working directory to /home/user/work on Linux and Mac OSX
+- Prints out the graphical app output log following execution
+- Exits with the same return code as the graphical app
+
+Options:
+
+  -h             Display this help and exit.
+  -c             Container name to use (default ${container}).
+  -i             Image name (default ${image}).
+  -p             Port to expose HTTP server (default ${port}). If an empty
+                 string, the port is not exposed.
+  -r             Extra arguments to pass to 'docker run'. E.g.
+                 --env="APP=glxgears"
+  -q             Do not output informational messages.
+EOF
+}
+
+while [ $# -gt 0 ]; do
+	case "$1" in
+		-h)
+			show_help
+			exit 0
+			;;
+		-c)
+			container=$2
+			shift
+			;;
+		-i)
+			image=$2
+			shift
+			;;
+		-p)
+			port=$2
+			shift
+			;;
+		-r)
+			extra_run_args="$extra_run_args $2"
+			shift
+			;;
+		-q)
+			quiet=1
+			;;
+		*)
+			show_help >&2
+			exit 1
+			;;
+	esac
+	shift
+done
+
+
+which docker 2>&1 >/dev/null
+if [ $? -ne 0 ]; then
+	echo "Error: the 'docker' command was not found.  Please install docker."
+	exit 1
+fi
+
+os=$(uname)
+if [ "${os}" != "Linux" ]; then
+	vm=$(docker-machine active 2> /dev/null || echo "default")
+	if ! docker-machine inspect "${vm}" &> /dev/null; then
+		if [ -z "$quiet" ]; then
+			echo "Creating machine ${vm}..."
+		fi
+		docker-machine -D create -d virtualbox --virtualbox-memory 2048 ${vm}
+	fi
+	docker-machine start ${vm} > /dev/null
+    eval $(docker-machine env $vm --shell=sh)
+fi
+
+ip=$(docker-machine ip ${vm} 2> /dev/null || echo "localhost")
+url="http://${ip}:$port"
+
+cleanup() {
+	docker stop $container >/dev/null
+	docker rm $container >/dev/null
+}
+
+running=$(docker ps -a -q --filter "name=${container}")
+if [ -n "$running" ]; then
+	if [ -z "$quiet" ]; then
+		echo "Stopping and removing the previous session..."
+		echo ""
+	fi
+	cleanup
+fi
+
+if [ -z "$quiet" ]; then
+	echo ""
+	echo "Setting up the graphical application container..."
+	echo ""
+	if [ -n "$port" ]; then
+		echo "Point your web browser to ${url}"
+		echo ""
+	fi
+fi
+
+pwd_dir="`cd $(dirname $0)/../..; pwd`"
+mount_local=""
+if [ "${os}" = "Linux" ] || [ "${os}" = "Darwin" ]; then
+	mount_local=" -v ${pwd_dir}:/usr/src/CTK "
+fi
+port_arg=""
+if [ -n "$port" ]; then
+	port_arg="-p $port:6080"
+fi
+
+docker run \
+  -d \
+  --name $container \
+  ${mount_local} \
+  $port_arg \
+  $extra_run_args \
+  $image >/dev/null
+
+print_app_output() {
+	docker cp $container:/var/log/supervisor/graphical-app-launcher.log - \
+		| tar xO
+	result=$(docker cp $container:/tmp/graphical-app.return_code - \
+		| tar xO)
+	cleanup
+	exit $result
+}
+
+trap "docker stop $container >/dev/null && print_app_output" SIGINT SIGTERM
+
+docker wait $container >/dev/null
+
+print_app_output
+
+# vim: noexpandtab shiftwidth=4 tabstop=4 softtabstop=0

+ 19 - 0
CMake/CircleCI/test.sh

@@ -0,0 +1,19 @@
+#!/bin/bash
+
+# This is a script to build the modules and run the test suite in the base
+# Docker container.
+
+die() {
+  echo "Error: $@" 1>&2
+  exit 1;
+}
+
+mkdir /usr/src/CTK-build
+cd /usr/src/CTK-build || die "Could not cd into the build directory"
+
+mkdir /usr/src/CTK-build/CTK-build
+cd /usr/src/CTK-build/CTK-build || die "Could not cd into the build directory"
+
+ctest \
+  -S /usr/src/CTK/CMake/CircleCI/CircleCI_CTK_Docker.cmake \
+  -VV || die "ctest failed"

+ 3 - 1
Libs/Core/Testing/Cpp/CMakeLists.txt

@@ -137,7 +137,9 @@ SIMPLE_TEST( ctkAbstractLibraryFactoryTest1 $<TARGET_FILE:CTKDummyPlugin> )
 SIMPLE_TEST( ctkAbstractObjectFactoryTest1 )
 SIMPLE_TEST( ctkAbstractPluginFactoryTest1 $<TARGET_FILE:CTKDummyPlugin> )
 SIMPLE_TEST( ctkAbstractQObjectFactoryTest1 )
-SIMPLE_TEST( ctkBackTraceTest )
+if(CMAKE_BUILD_TYPE MATCHES "Debug")
+  SIMPLE_TEST( ctkBackTraceTest )
+endif()
 if(HAVE_BFD)
   SIMPLE_TEST( ctkBinaryFileDescriptorTest1 $<TARGET_FILE:ctkBinaryFileDescriptorTestHelper> )
 endif()

+ 6 - 0
README

@@ -1,3 +1,9 @@
+Common Toolkit
+==============
+
+.. image:: https://circleci.com/gh/commontk/CTK.svg?style=svg
+    :target: http://my.cdash.org/index.php?project=CTK
+
 The Common Toolkit is a community effort to provide support code for medical image analysis,
 surgical navigation, and related projects.
 

+ 12 - 0
circle.yml

@@ -0,0 +1,12 @@
+machine:
+  services:
+    - docker
+
+dependencies:
+  override:
+    - docker info
+    - docker pull commontk/ctk-test:opengl
+
+test:
+  override:
+    - ~/CTK/CMake/CircleCI/run.sh $CIRCLE_SHA1 $CIRCLE_BRANCH $SITE_BUILD_TYPE