From 3a8ec3799a84fb643641ebd5e4f11c2ffd063b84 Mon Sep 17 00:00:00 2001 From: Anthony Yeh Date: Mon, 20 Apr 2015 16:03:01 -0700 Subject: [PATCH] Add Makefile rule to run tests inside Docker. This will let contributors test changes without having to do bootstrap at all. It also makes it easy to test against multiple flavors without having to swap out installed packages. You can even run tests against multiple flavors simultaneously without interfering, if you have enough RAM. --- Makefile | 8 +++++++- docker/test/run.sh | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+), 1 deletion(-) create mode 100755 docker/test/run.sh diff --git a/Makefile b/Makefile index dfc5481cc5..98664faade 100644 --- a/Makefile +++ b/Makefile @@ -4,7 +4,7 @@ MAKEFLAGS = -s -.PHONY: all build test clean unit_test unit_test_cover unit_test_race queryservice_test integration_test bson proto site_test site_integration_test docker_bootstrap +.PHONY: all build test clean unit_test unit_test_cover unit_test_race queryservice_test integration_test bson proto site_test site_integration_test docker_bootstrap docker_test all: build test @@ -185,3 +185,9 @@ proto: # Example: $ make docker_bootstrap flavor=mariadb docker_bootstrap: docker/bootstrap/build.sh $(flavor) + +# This rule loads the working copy of the code into a bootstrap image, +# and then runs the tests inside Docker. +# Example: $ make docker_test flavor=mariadb +docker_test: + docker/test/run.sh $(flavor) diff --git a/docker/test/run.sh b/docker/test/run.sh new file mode 100755 index 0000000000..c69be8a13c --- /dev/null +++ b/docker/test/run.sh @@ -0,0 +1,38 @@ +#!/bin/bash + +flavor=$1 + +if [[ -z "$flavor" ]]; then + echo "Flavor must be specified as first argument." + exit 1 +fi + +if [[ ! -f bootstrap.sh ]]; then + echo "This script should be run from the root of the Vitess source tree - e.g. ~/src/github.com/youtube/vitess" + exit 1 +fi + +# To avoid AUFS permission issues, files must allow access by "other" +chmod -R o=g * + +args="-ti --rm -v /dev/log:/dev/log" +args="$args -v $PWD:/tmp/src" + +# Mount in host VTDATAROOT if one exists, since it might be a RAM disk or SSD. +if [[ -n "$VTDATAROOT" ]]; then + hostdir=`mktemp -d --tmpdir=$VTDATAROOT test.XXX` + testid=`basename $hostdir` + + echo "Mounting host dir $hostdir as VTDATAROOT" + args="$args -v $hostdir:/vt/vtdataroot --name=$testid" +fi + +# Run tests +echo "Running tests in vitess/bootstrap:$flavor image..." +docker run $args vitess/bootstrap:$flavor \ + bash -c 'rm -rf * && cp -R /tmp/src/* . && rm -rf Godeps/_workspace/pkg && make test' + +# Clean up host dir mounted VTDATAROOT +if [[ -n "$hostdir" ]]; then + rm -rf $hostdir +fi