Add more integration tests

This commit is contained in:
cytopia
2018-03-03 22:02:24 +01:00
parent fcbc2e5f84
commit 1730094042
8 changed files with 382 additions and 5 deletions

View File

@@ -29,7 +29,7 @@ set_postfix() {
else
catch_all="$( env_get "${env_varname}" )"
if [ "${catch_all}" = "1" ]; then
log "info" "Enabling postfix catch-all" "${debug}"
log "info" "\$${env_varname} set to 1. Enabling postfix catch-all" "${debug}"
# Configure PHP
{
@@ -61,11 +61,10 @@ set_postfix() {
run "newaliases" "${debug}"
elif [ "${catch_all}" = "0" ]; then
log "info" "Disabling postfix catch-all" "${debug}"
log "info" "\$${env_varname} set to 0. Disabling postfix catch-all" "${debug}"
else
log "err" "Invalid value for \$${env_varname}" "${debug}"
log "err" "Only 1 (for on) or 0 (for off) are allowed" "${debug}"
log "err" "Invalid value for \$${env_varname}. Can only be 0 or 1. Prodived: ${catch_all}" "${debug}"
exit 1
fi
fi

View File

@@ -89,6 +89,76 @@ Have a look at the following table to see all supported environment variables fo
</tbody>
</table>
### Volumes
Have a look at the following table to see all offered volumes for each Docker image flavour.
<table>
<thead>
<tr>
<th>Image</th>
<th width="200">Volumes</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td rowspan="4"><strong>prod</strong><br/><br/><strong>work</strong></td>
<td><code>/etc/php-custom.d</code></td>
<td>Mount this directory into your host computer and add custom <code>\*.ini</code> files in order to alter php behaviour.</td>
</tr>
<tr>
<td><code>/etc/php-modules.d</code></td>
<td>Mount this directory into your host computer and add custo <code>\*.so</code> files in order to add your php modules.<br/><br/><strong>Note:</strong>Your should then also provide a custom <code>\*.ini</code> file in order to actually load your custom provided module.</td>
</tr>
<tr>
<td><code>/var/log/php</code></td>
<td>When setting environment variable <code>DOCKER_LOGS</code> to <code>0</code>, log files will be available under this directory.</td>
</tr>
<tr>
<td><code>/var/mail</code></td>
<td>Emails caught be the postfix catch-all (<code>ENABLE_MAIL=1</code>) will be available in this directory.</td>
</tr>
<tr>
<td colspan="3"></td>
</tr>
<tr>
<td rowspan="2"><strong>work</strong></td>
<td><code>/etc/bash-custom.d</code></td>
<td>Mount this directory into your host computer and add custom configuration files for <code>bash</code> and other tools.</td>
</tr>
<tr>
<td><code>/shared/backups</code></td>
<td>Mount this directory into your host computer to access MySQL backups created by <a href="https://mysqldump-secure.org" >mysqldump-secure</a>.</td>
</tr>
</tbody>
</table>
### Ports
Have a look at the following table to see all offered exposed ports for each Docker image flavour.
<table>
<thead>
<tr>
<th>Image</th>
<th width="200">Port</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td rowspan="1"><strong>base</strong><br/><strong>mods</strong><br/><strong>prod</strong><br/><strong>work</strong></td>
<td><code>9000</code></td>
<td>PHP-FPM listening port</td>
</tr>
</tbody>
</table>
<h2><img id="modules" width="20" src="https://github.com/devilbox/artwork/raw/master/submissions_logo/cytopia/01/png/logo_64_trans.png"> Modules</h2>
<table>

View File

@@ -150,6 +150,21 @@ function docker_exec() {
}
###
### Get docker name
###
function docker_name() {
local did="${1}"
local name=
name="$( docker ps | grep "${did}" | awk '{print $(NF)}' )"
if [ -z "${name}" ]; then
return 1
fi
echo "${name}"
}
###
### Stop container
###

View File

@@ -19,7 +19,6 @@ FLAVOUR="${3}"
# Tests
############################################################
###
### Docker logs
###

View File

@@ -0,0 +1,66 @@
#!/usr/bin/env bash
set -e
set -u
set -o pipefail
CWD="$(cd -P -- "$(dirname -- "$0")" && pwd -P)"
IMAGE="${1}"
VERSION="${2}"
FLAVOUR="${3}"
# shellcheck disable=SC1090
. "${CWD}/../.lib.sh"
############################################################
# Tests
############################################################
###
### Postfix
###
MOUNTPOINT="$( mktemp --directory )"
did="$( docker_run "${IMAGE}:${VERSION}-${FLAVOUR}" "-e DEBUG_ENTRYPOINT=2 -e NEW_UID=$(id -u) -e NEW_GID=$(id -g) -e ENABLE_MAIL=1 -v ${MOUNTPOINT}:/var/mail" )"
run "sleep 10"
if ! run "docker logs ${did} 2>&1 | grep -q 'ENABLE_MAIL'"; then
docker_logs "${did}" || true
docker_stop "${did}" || true
echo "Failed"
exit 1
fi
if [ ! -f "${MOUNTPOINT}/devilbox" ]; then
echo "Mail file does not exist: ${MOUNTPOINT}/devilbox"
ls -lap ${MOUNTPOINT}/
docker_logs "${did}" || true
docker_stop "${did}" || true
echo "Failed"
exit 1
fi
if [ ! -r "${MOUNTPOINT}/devilbox" ]; then
echo "Mail file is not readable"
ls -lap ${MOUNTPOINT}/
docker_logs "${did}" || true
docker_stop "${did}" || true
echo "Failed"
exit 1
fi
# Send test email
docker_exec "${did}" "php -r \"mail('mailtest@devilbox.org', 'the subject', 'the message');\""
run "sleep 5"
if ! run "grep 'the subject' ${MOUNTPOINT}/devilbox"; then
docker_logs "${did}" || true
docker_stop "${did}" || true
echo "Failed"
"run cat ${MOUNTPOINT}/devilbox"
exit 1
fi
docker_stop "${did}"
run "rm -rf ${MOUNTPOINT}" || true

View File

@@ -0,0 +1,50 @@
#!/usr/bin/env bash
set -e
set -u
set -o pipefail
CWD="$(cd -P -- "$(dirname -- "$0")" && pwd -P)"
IMAGE="${1}"
VERSION="${2}"
FLAVOUR="${3}"
# shellcheck disable=SC1090
. "${CWD}/../.lib.sh"
############################################################
# Tests
############################################################
###
### Socat forwarding
###
# Start mysql container
mdid="$( docker_run "mysql:5.6" "-e MYSQL_ALLOW_EMPTY_PASSWORD=yes" )"
mname="$( docker_name "${mdid}" )"
run "sleep 5"
did="$( docker_run "${IMAGE}:${VERSION}-${FLAVOUR}" "-e DEBUG_ENTRYPOINT=2 -e FORWARD_PORTS_TO_LOCALHOST=3306:${mname}:3306 --link ${mname}" )"
if ! run "docker logs ${did} 2>&1 | grep 'Forwarding ${mname}:3306'"; then
docker_logs "${did}" || true
docker_stop "${did}" || true
echo "Failed"
exit 1
fi
# Test connectivity
docker_exec "${did}" "ping -c 1 ${mname}"
docker_exec "${did}" "echo | nc -w 1 ${mname} 3306"
docker_exec "${did}" "echo | nc -w 1 127.0.0.1 3306"
# Only work container has mysql binary installed
if [ "${FLAVOUR}" = "work" ]; then
docker_exec "${did}" "mysql --user=root --password= --host=${mname} -e 'SHOW DATABASES;'"
docker_exec "${did}" "mysql --user=root --password= --host=127.0.0.1 -e 'SHOW DATABASES;'"
fi
docker_stop "${mdid}"
docker_stop "${did}"

View File

@@ -0,0 +1,124 @@
#!/usr/bin/env bash
set -e
set -u
set -o pipefail
CWD="$(cd -P -- "$(dirname -- "$0")" && pwd -P)"
IMAGE="${1}"
VERSION="${2}"
FLAVOUR="${3}"
# shellcheck disable=SC1090
. "${CWD}/../.lib.sh"
############################################################
# Tests
############################################################
###
### Test Nginx with PHP-FPM
###
WWW_PORT="12345"
DOC_ROOT_HOST="$( mktemp -d )"
DOC_ROOT_CONT="/var/www/default"
CONFIG_HOST="$( mktemp -d )"
CONFIG_CONT="/etc/nginx/conf.d"
PHP_INI_HOST="$( mktemp -d )"
PHP_INI_CONT="/etc/php-custom.d"
echo "post_max_size = 17M" > "${PHP_INI_HOST}/post.ini"
echo "<?php phpinfo();" > "${DOC_ROOT_HOST}/index.php"
# Start PHP-FPM
did="$( docker_run "${IMAGE}:${VERSION}-${FLAVOUR}" "-e DEBUG_ENTRYPOINT=2 -v ${DOC_ROOT_HOST}:${DOC_ROOT_CONT} -v ${PHP_INI_HOST}:${PHP_INI_CONT}" )"
name="$( docker_name "${did}" )"
# Nginx.conf
{
echo "server {"
echo " server_name _;"
echo " listen 80;"
echo " root ${DOC_ROOT_CONT};"
echo " index index.php;"
echo " location ~* \.php\$ {"
echo " fastcgi_index index.php;"
echo " fastcgi_pass ${name}:9000;"
echo " include fastcgi_params;"
echo " fastcgi_param SCRIPT_FILENAME \$document_root\$fastcgi_script_name;"
echo " fastcgi_param SCRIPT_NAME \$fastcgi_script_name;"
echo " }"
echo "}"
} > "${CONFIG_HOST}/php.conf"
# Start Nginx
ndid="$( docker_run "nginx:stable" "-v ${DOC_ROOT_HOST}:${DOC_ROOT_CONT} -v ${CONFIG_HOST}:${CONFIG_CONT} -p ${WWW_PORT}:80 --link ${name}" )"
# Check entrypoint
if ! run "docker logs ${did} | grep 'post.ini'"; then
run "rm -rf ${DOC_ROOT_HOST}"
run "rm -rf ${CONFIG_HOST}"
run "rm -rf ${PHP_INI_HOST}"
docker_logs "${ndid}" || true
docker_logs "${did}" || true
docker_stop "${ndid}" || true
docker_stop "${did}" || true
echo "Failed"
exit 1
fi
# Check PHP connectivity
if ! run "curl -q 127.0.0.1:${WWW_PORT}/index.php >/dev/null 2>&1"; then
run "rm -rf ${DOC_ROOT_HOST}"
run "rm -rf ${CONFIG_HOST}"
run "rm -rf ${PHP_INI_HOST}"
docker_logs "${ndid}" || true
docker_logs "${did}" || true
docker_stop "${ndid}" || true
docker_stop "${did}" || true
echo "Failed"
exit 1
fi
# Check modified php.ini
if ! docker_exec "${did}" "php -r \"echo ini_get('post_max_size');\" | grep '17M'"; then
docker_exec "${did}" "php -r \"echo ini_get('post_max_size');\""
run "rm -rf ${DOC_ROOT_HOST}"
run "rm -rf ${CONFIG_HOST}"
run "rm -rf ${PHP_INI_HOST}"
docker_logs "${ndid}" || true
docker_logs "${did}" || true
docker_stop "${ndid}" || true
docker_stop "${did}" || true
echo "Failed"
exit 1
fi
# Check modified php.ini
if ! run "curl -q 127.0.0.1:${WWW_PORT}/index.php 2>/dev/null | grep post_max_size | grep '17M'"; then
docker_exec "${did}" "php -r \"echo ini_get('post_max_size');\""
run "rm -rf ${DOC_ROOT_HOST}"
run "rm -rf ${CONFIG_HOST}"
run "rm -rf ${PHP_INI_HOST}"
docker_logs "${ndid}" || true
docker_logs "${did}" || true
docker_stop "${ndid}" || true
docker_stop "${did}" || true
echo "Failed"
exit 1
fi
# Cleanup
docker_stop "${did}"
docker_stop "${ndid}"
run "rm -rf ${DOC_ROOT_HOST}"
run "rm -rf ${CONFIG_HOST}"
run "rm -rf ${PHP_INI_HOST}"

View File

@@ -0,0 +1,54 @@
#!/usr/bin/env bash
set -e
set -u
set -o pipefail
CWD="$(cd -P -- "$(dirname -- "$0")" && pwd -P)"
IMAGE="${1}"
VERSION="${2}"
FLAVOUR="${3}"
# shellcheck disable=SC1090
. "${CWD}/../.lib.sh"
############################################################
# Tests
############################################################
###
### Mysqldump-secure
###
MYSQL_ROOT_PASSWORD="toor"
MOUNTPOINT="$( mktemp --directory )"
# Start mysql container
mdid="$( docker_run "mysql:5.6" "-e MYSQL_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD}" )"
mname="$( docker_name "${mdid}" )"
run "sleep 5"
# Start PHP-FPM container
did="$( docker_run "${IMAGE}:${VERSION}-${FLAVOUR}" "-e DEBUG_ENTRYPOINT=2 -e NEW_UID=$(id -u) -e NEW_GID=$(id -g) -e FORWARD_PORTS_TO_LOCALHOST=3306:${mname}:3306 -e MYSQL_BACKUP_USER=root -e MYSQL_BACKUP_PASS=${MYSQL_ROOT_PASSWORD} -e MYSQL_BACKUP_HOST=127.0.0.1 -v ${MOUNTPOINT}:/shared/backups --link ${mname}" )"
docker_exec "${did}" mysqldump-secure
if [ ! -d "${MOUNTPOINT}/mysql" ]; then
echo "MySQL backup dir does not exist: ${MOUNTPOINT}/mysql"
ls -lap ${MOUNTPOINT}/
docker_logs "${did}"
docker_logs "${mdid}"
docker_stop "${did}"
docker_stop "${mdid}"
run "rm -rf ${MOUNTPOINT}" || true
exit 1
fi
run "ls -lap ${MOUNTPOINT}/mysql/ | grep -E 'mysql\.sql\.gz'"
run "ls -lap ${MOUNTPOINT}/mysql/ | grep -E 'mysql\.sql\.gz\.info'"
docker_stop "${did}"
docker_stop "${mdid}"
run "rm -rf ${MOUNTPOINT}" || true