summaryrefslogtreecommitdiffstats
path: root/contrib/docker-test.sh
blob: 234ff9502cb42cfb5e773186d2fe8584ff4ffd0e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/bin/bash

MYSQL_CONTAINER=icingaweb2_director_mysql

echo "Starting MySQL container..."
docker run -d \
    -e MYSQL_ROOT_PASSWORD=onlyforadmin \
    -e MYSQL_DATABASE=icingaweb2 \
    -e MYSQL_USER=icingaweb2 \
    -e MYSQL_PASSWORD=rosebud \
    --name "$MYSQL_CONTAINER" \
    mariadb >/dev/null

echo "Running tests..."
docker run --rm -i \
    --link "$MYSQL_CONTAINER":mysql \
    -v `pwd`:/app \
    -e DIRECTOR_TESTDB_RES="Director MySQL TestDB" \
    -e DIRECTOR_TESTDB_HOST="mysql" \
    -e DIRECTOR_TESTDB_USER="icingaweb2" \
    -e DIRECTOR_TESTDB_PASSWORD="rosebud" \
    -e DIRECTOR_TESTDB="icingaweb2" \
    lazyfrosch/icingaweb2-test:5.6 \
    sh - \
<<EOF
    set -ex
    cd /app
    composer install
    {
        set +x
        count=0
        while ! nc -w 1 -z mysql 3306
        do
            echo "Waiting for MySQL to get ready..."
            sleep 2
            : \$((count++))
            if [ \$count -gt 10 ]; then
                echo "Waiting for MySQL timed out!"
                exit 2
            fi
        done
    }
    ret=0
    composer exec phpunit --verbose || ret=\$?
    #composer exec phpcs application/ library/ test/php/ *.php || ret=\$?
    exit \$ret
EOF

echo "Stopping MySQL container..."
docker kill "$MYSQL_CONTAINER"
docker rm "$MYSQL_CONTAINER"