From 5133a738e1e0246b5c5291268726a2afb21935e2 Mon Sep 17 00:00:00 2001 From: Morris Jobke Date: Mon, 13 Apr 2015 16:08:50 +0200 Subject: autotest.sh with docker support for postgres * waits until the docker container is started * export USEDOCKER=1 to run the docker version of postgres --- autotest.sh | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) (limited to 'autotest.sh') diff --git a/autotest.sh b/autotest.sh index 46c55edef19..4fa51e2d071 100755 --- a/autotest.sh +++ b/autotest.sh @@ -145,7 +145,20 @@ function execute_tests { mysql -u "$DATABASEUSER" -powncloud -e "DROP DATABASE IF EXISTS $DATABASENAME" -h $DATABASEHOST || true fi if [ "$1" == "pgsql" ] ; then - dropdb -U "$DATABASEUSER" "$DATABASENAME" || true + if [ ! -z "$USEDOCKER" ] ; then + echo "Fire up the postgres docker" + DOCKER_CONTAINER_ID=$(docker run -e POSTGRES_USER="$DATABASEUSER" -e POSTGRES_PASSWORD=owncloud -d postgres) + DATABASEHOST=$(docker inspect "$DOCKER_CONTAINER_ID" | grep IPAddress | cut -d '"' -f 4) + + echo "Waiting for Postgres initialisation ..." + + # grep exits on the first match and then the script continues + docker logs -f "$DOCKER_CONTAINER_ID" 2>&1 | grep -q "database system is ready to accept connections" + + echo "Postgres is up." + else + dropdb -U "$DATABASEUSER" "$DATABASENAME" || true + fi fi if [ "$1" == "oci" ] ; then echo "Fire up the oracle docker" @@ -177,6 +190,12 @@ function execute_tests { "${PHPUNIT[@]}" --configuration phpunit-autotest.xml --log-junit "autotest-results-$1.xml" "$2" "$3" RESULT=$? fi + + if [ ! -z "$DOCKER_CONTAINER_ID" ] ; then + echo "Kill the docker $DOCKER_CONTAINER_ID" + docker rm -f $DOCKER_CONTAINER_ID + unset DOCKER_CONTAINER_ID + fi } # -- cgit v1.2.3