|
| 1 | +#!/bin/sh |
| 2 | + |
| 3 | +# Exit on non defined variables and on non zero exit codes |
| 4 | +set -eu |
| 5 | + |
| 6 | +echo 'Building the container' |
| 7 | + |
| 8 | +docker build ./ -t alpine-apache-php-ci:latest |
| 9 | + |
| 10 | +NET="${DOCKER_NETWORK:-alpine-apache-php-autotest}" |
| 11 | + |
| 12 | +# use failure to switch on create |
| 13 | +docker network inspect ${NET} 1>/dev/null 2> /dev/null || docker network create ${NET} |
| 14 | + |
| 15 | +echo 'Preparing test folder' |
| 16 | + |
| 17 | +TMP_DIR="$(mktemp -d --suffix alpine-apache-php)" |
| 18 | + |
| 19 | +printf "<?php \n\ |
| 20 | + echo 'PHP: ' . PHP_MAJOR_VERSION . PHP_EOL;\n\ |
| 21 | + echo 'Admin: ' . \$_SERVER['SERVER_ADMIN'] . PHP_EOL;\n\ |
| 22 | + echo 'Host: ' . \$_SERVER['SERVER_NAME'] . PHP_EOL;\n\ |
| 23 | + echo 'Memory-limit: ' . ini_get('memory_limit') . PHP_EOL;\n\ |
| 24 | + echo 'Timezone: ' . ini_get('date.timezone') . PHP_EOL;\n\ |
| 25 | + " > "${TMP_DIR}/index.php" |
| 26 | + |
| 27 | +chmod 777 "${TMP_DIR}" |
| 28 | +chmod 666 "${TMP_DIR}/index.php" |
| 29 | + |
| 30 | +echo 'Running test containers' |
| 31 | + |
| 32 | +# stop if exists or silently exit |
| 33 | +docker stop alpine-apache-php-test 1>/dev/null 2> /dev/null || echo '' >/dev/null |
| 34 | + |
| 35 | +docker run --rm --detach \ |
| 36 | + --name alpine-apache-php-test \ |
| 37 | + --network ${NET} \ |
| 38 | + --volume ${TMP_DIR}:/htdocs \ |
| 39 | + --env HTTP_SERVER_NAME="www.example.xyz" \ |
| 40 | + --env HTTPS_SERVER_NAME="www.example.xyz" \ |
| 41 | + --env SERVER_ADMIN="admin@example.xyz" \ |
| 42 | + --env TZ="Europe/Paris" \ |
| 43 | + --env PHP_MEMORY_LIMIT="512M" \ |
| 44 | + alpine-apache-php-ci:latest 1>/dev/null |
| 45 | + |
| 46 | + |
| 47 | +# stop if exists or silently exit |
| 48 | +docker stop alpine-apache-php-test-normal 1>/dev/null 2> /dev/null || echo '' >/dev/null |
| 49 | + |
| 50 | +docker run --rm --detach \ |
| 51 | + --name alpine-apache-php-test-normal \ |
| 52 | + --network ${NET} \ |
| 53 | + --volume ${TMP_DIR}:/htdocs \ |
| 54 | + alpine-apache-php-ci:latest 1>/dev/null |
| 55 | + |
| 56 | +echo '' |
| 57 | +echo 'Running custom tests' |
| 58 | + |
| 59 | +docker run --rm --network ${NET} curlimages/curl:latest -s -k https://alpine-apache-php-test -H 'Host: www.example.xyz' |
| 60 | +docker run --rm --network ${NET} curlimages/curl:latest -s http://alpine-apache-php-test |
| 61 | +docker run --rm --network ${NET} curlimages/curl:latest -s -k https://alpine-apache-php-test |
| 62 | + |
| 63 | +echo '' |
| 64 | +echo 'Running normal tests' |
| 65 | + |
| 66 | +docker run --rm --network ${NET} curlimages/curl:latest -s -k https://alpine-apache-php-test-normal -H 'Host: www.example.xyz' |
| 67 | +docker run --rm --network ${NET} curlimages/curl:latest -s http://alpine-apache-php-test-normal |
| 68 | +docker run --rm --network ${NET} curlimages/curl:latest -s -k https://alpine-apache-php-test-normal |
| 69 | + |
| 70 | +echo '' |
| 71 | +echo 'Cleaning up' |
| 72 | +docker stop alpine-apache-php-test 1>/dev/null |
| 73 | +docker stop alpine-apache-php-test-normal 1>/dev/null |
| 74 | +docker network rm ${NET} 1>/dev/null |
| 75 | + |
| 76 | +rm "${TMP_DIR}/index.php" |
| 77 | +rmdir "${TMP_DIR}" |
0 commit comments