Преглед изворни кода

ENH: Improve Continuous Integration Support with graphical display

This new version use the opengl docker image based on (https://github.com/thewtex/docker-opengl)
mayeul пре 9 година
родитељ
комит
e97e00f314

+ 4 - 8
CMake/CircleCI/Dockerfile

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

+ 1 - 1
CMake/CircleCI/build.sh

@@ -2,4 +2,4 @@
 
 script_dir="`cd $(dirname $0); pwd`"
 
-docker build -t commontk/ctk-test $script_dir
+docker build -t commontk/ctk-test:opengl $script_dir

+ 1 - 1
CMake/CircleCI/push.sh

@@ -5,4 +5,4 @@ die() {
   exit 1;
 }
 
-docker push commontk/ctk-test
+docker push commontk/ctk-test:opengl

+ 1 - 5
CMake/CircleCI/run.sh

@@ -2,8 +2,4 @@
 
 script_dir="`cd $(dirname $0); pwd`"
 
-docker run \
-  --rm \
-  -v $script_dir/../..:/usr/src/CTK \
-    commontk/ctk-test \
-/usr/src/CTK/CMake/CircleCI/test.sh
+$script_dir/run_opengl.sh -i commontk/ctk-test:opengl -p 6081 "$@"

+ 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="$(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
+echo "avant"
+print_app_output
+echo "apres"
+# vim: noexpandtab shiftwidth=4 tabstop=4 softtabstop=0

+ 1 - 1
CMake/CircleCI/test.sh

@@ -18,5 +18,5 @@ cmake \
 
 make -j3 || die "examples build failed"
 
-cd CTK-build
+cd /usr/src/CTK-build/CTK-build || die "Could not cd into the build directory"
 ctest -VV -D Experimental || die "ctest failed"

+ 2 - 2
circle.yml

@@ -5,8 +5,8 @@ machine:
 dependencies:
   override:
     - docker info
-    - docker pull commontk/ctk-test
+    - docker pull commontk/ctk-test:opengl
 
 test:
   override:
-    - docker run -v ~/CTK:/usr/src/CTK -v ~/CTK-build:/usr/src/CTK-build commontk/ctk-test /usr/src/CTK/CMake/CircleCI/test.sh
+    - ~/CTK/CMake/CircleCI/run.sh