2015-04-21 02:03:01 +03:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
flavor=$1
|
2015-04-21 03:11:45 +03:00
|
|
|
cmd=$2
|
2015-04-22 06:12:20 +03:00
|
|
|
args=
|
2015-04-21 02:03:01 +03:00
|
|
|
|
|
|
|
if [[ -z "$flavor" ]]; then
|
|
|
|
echo "Flavor must be specified as first argument."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2015-04-21 03:11:45 +03:00
|
|
|
if [[ -z "$cmd" ]]; then
|
|
|
|
cmd=bash
|
|
|
|
fi
|
|
|
|
|
2015-04-21 02:03:01 +03:00
|
|
|
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
|
|
|
|
|
2015-05-20 02:17:16 +03:00
|
|
|
# To avoid AUFS permission issues, files must allow access by "other" (permissions rX required).
|
|
|
|
# Mirror permissions to "other" from the owning group (for which we assume it has at least rX permissions).
|
|
|
|
chmod -R o=g .
|
2015-04-21 02:03:01 +03:00
|
|
|
|
2015-08-12 11:56:37 +03:00
|
|
|
args="$args -e USER=vitess -v /dev/log:/dev/log"
|
2015-04-21 02:03:01 +03:00
|
|
|
args="$args -v $PWD:/tmp/src"
|
|
|
|
|
2015-08-12 11:56:37 +03:00
|
|
|
# Share maven dependency cache so they don't have to be redownloaded every time.
|
|
|
|
mkdir -p /tmp/mavencache
|
|
|
|
chmod 777 /tmp/mavencache
|
|
|
|
args="$args -v /tmp/mavencache:/home/vitess/.m2"
|
|
|
|
|
2015-04-21 02:03:01 +03:00
|
|
|
# Mount in host VTDATAROOT if one exists, since it might be a RAM disk or SSD.
|
|
|
|
if [[ -n "$VTDATAROOT" ]]; then
|
2015-04-21 03:11:45 +03:00
|
|
|
hostdir=`mktemp -d --tmpdir=$VTDATAROOT test-XXX`
|
2015-04-21 02:03:01 +03:00
|
|
|
testid=`basename $hostdir`
|
|
|
|
|
2015-04-21 03:11:45 +03:00
|
|
|
chmod 777 $hostdir
|
|
|
|
|
2015-04-21 02:03:01 +03:00
|
|
|
echo "Mounting host dir $hostdir as VTDATAROOT"
|
2015-04-21 03:11:45 +03:00
|
|
|
args="$args -v $hostdir:/vt/vtdataroot --name=$testid -h $testid"
|
|
|
|
else
|
2015-04-22 06:12:20 +03:00
|
|
|
testid=test-$$
|
|
|
|
args="$args --name=$testid -h $testid"
|
2015-04-21 02:03:01 +03:00
|
|
|
fi
|
|
|
|
|
|
|
|
# Run tests
|
|
|
|
echo "Running tests in vitess/bootstrap:$flavor image..."
|
2015-11-05 05:48:34 +03:00
|
|
|
bashcmd="mv php/vendor /vt/dist/php-vendor && rm -rf * && cp -R /tmp/src/* . && ln -sf /vt/dist/php-vendor php/vendor && rm -rf Godeps/_workspace/pkg && $cmd"
|
2015-04-22 06:12:20 +03:00
|
|
|
|
|
|
|
if tty -s; then
|
|
|
|
# interactive shell
|
|
|
|
docker run -ti $args vitess/bootstrap:$flavor bash -c "$bashcmd"
|
|
|
|
exitcode=$?
|
|
|
|
else
|
|
|
|
# non-interactive shell (kill child on signal)
|
2015-08-12 11:56:37 +03:00
|
|
|
trap 'docker kill $testid &>/dev/null' SIGTERM SIGINT
|
2015-04-22 06:12:20 +03:00
|
|
|
docker run $args vitess/bootstrap:$flavor bash -c "$bashcmd" &
|
|
|
|
wait $!
|
|
|
|
exitcode=$?
|
|
|
|
fi
|
2015-04-21 02:03:01 +03:00
|
|
|
|
|
|
|
# Clean up host dir mounted VTDATAROOT
|
|
|
|
if [[ -n "$hostdir" ]]; then
|
2015-04-23 01:06:07 +03:00
|
|
|
# Use Docker user to clean up first, to avoid permission errors.
|
2015-08-25 01:40:54 +03:00
|
|
|
docker run --name=rm_$testid -v $hostdir:/vt/vtdataroot vitess/bootstrap:$flavor bash -c 'rm -rf /vt/vtdataroot/*'
|
|
|
|
docker rm -f rm_$testid &>/dev/null
|
2015-04-21 02:03:01 +03:00
|
|
|
rm -rf $hostdir
|
|
|
|
fi
|
2015-04-22 06:12:20 +03:00
|
|
|
|
2015-08-12 11:56:37 +03:00
|
|
|
# Delete the container
|
|
|
|
docker rm -f $testid &>/dev/null
|
|
|
|
|
2015-04-22 06:12:20 +03:00
|
|
|
exit $exitcode
|