From d37a1fcb86f234154a540108e2958927ced15c94 Mon Sep 17 00:00:00 2001 From: cytopia Date: Mon, 28 Mar 2022 02:14:43 +0200 Subject: [PATCH] Ensure to test against timezone setting --- Dockerfiles/Dockerfile.alpine | 3 +- tests/00-test-html.sh | 70 +++++++++++++++++++++++++++ tests/00.sh | 64 ------------------------- tests/01-test-php.sh | 85 +++++++++++++++++++++++++++++++++ tests/{01.sh => 02-timezone.sh} | 41 +++++++++------- tests/start-ci.sh | 4 +- 6 files changed, 184 insertions(+), 83 deletions(-) create mode 100755 tests/00-test-html.sh delete mode 100755 tests/00.sh create mode 100755 tests/01-test-php.sh rename tests/{01.sh => 02-timezone.sh} (60%) diff --git a/Dockerfiles/Dockerfile.alpine b/Dockerfiles/Dockerfile.alpine index 1abc2cc..c22445b 100644 --- a/Dockerfiles/Dockerfile.alpine +++ b/Dockerfiles/Dockerfile.alpine @@ -25,7 +25,8 @@ ENV RUN_DEPS \ openssl \ py3-yaml \ shadow \ - supervisor + supervisor \ + tzdata ### diff --git a/tests/00-test-html.sh b/tests/00-test-html.sh new file mode 100755 index 0000000..116353f --- /dev/null +++ b/tests/00-test-html.sh @@ -0,0 +1,70 @@ +#!/usr/bin/env bash + +set -e +set -u +set -o pipefail + +CWD="$(cd -P -- "$(dirname -- "$0")" && pwd -P)" + +IMAGE="${1}" +#NAME="${2}" +#VERSION="${3}" +TAG="${4}" +ARCH="${5}" + + +HOST_PORT="8093" + +### +### Load Library +### +# shellcheck disable=SC1091 +. "${CWD}/.lib.sh" + + + +### +### Preparation +### +RAND_DIR="$( mktemp -d )" +RAND_NAME="$( get_random_name )" +run "echo \"hello world via html\" > ${RAND_DIR}/index.html" + + +### +### Startup container +### +run "docker run --rm --platform ${ARCH} \ + -v ${RAND_DIR}:/var/www/default/htdocs \ + -p 127.0.0.1:${HOST_PORT}:80 \ + -e DEBUG_ENTRYPOINT=2 \ + -e DEBUG_RUNTIME=1 \ + -e NEW_UID=$( id -u ) \ + -e NEW_GID=$( id -g ) \ + --name ${RAND_NAME} ${IMAGE}:${TAG} &" + + +### +### Tests +### +WAIT=120 +INDEX=0 +printf "Testing connectivity" +while ! curl -sS "http://localhost:${HOST_PORT}" 2>/dev/null | grep 'hello world via html'; do + printf "." + if [ "${INDEX}" = "${WAIT}" ]; then + printf "\\n" + run "docker logs ${RAND_NAME}" || true + run "docker stop ${RAND_NAME}" || true + echo "Error" + exit 1 + fi + INDEX=$(( INDEX + 1 )) + sleep 1 +done +printf "\\n[OK] Test success\\n" + +### +### Cleanup +### +run "docker stop ${RAND_NAME}" diff --git a/tests/00.sh b/tests/00.sh deleted file mode 100755 index 8b16b08..0000000 --- a/tests/00.sh +++ /dev/null @@ -1,64 +0,0 @@ -#!/usr/bin/env bash - -set -e -set -u -set -o pipefail - -CWD="$(cd -P -- "$(dirname -- "$0")" && pwd -P)" - -IMAGE="${1}" -#NAME="${2}" -#VERSION="${3}" -TAG="${4}" -ARCH="${5}" - - -### -### Load Library -### -# shellcheck disable=SC1091 -. "${CWD}/.lib.sh" - - - -### -### Preparation -### -RAND_DIR="$( mktemp -d )" -RAND_NAME="$( get_random_name )" -run "echo \"hello world\" > ${RAND_DIR}/index.html" - - -### -### Startup container -### -run "docker run -d --rm --platform ${ARCH} \ - -v ${RAND_DIR}:/var/www/default/htdocs \ - -p 127.0.0.1:80:80 \ - -e DEBUG_ENTRYPOINT=2 \ - -e DEBUG_RUNTIME=1 \ - -e NEW_UID=$( id -u ) \ - -e NEW_GID=$( id -g ) \ - --name ${RAND_NAME} ${IMAGE}:${TAG}" - - -### -### Tests -### -run "sleep 20" # Startup-time is longer on cross-platform -run "docker ps" -run "docker logs ${RAND_NAME}" -if ! run "curl -sS localhost/index.html"; then - run "docker stop ${RAND_NAME}" - exit 1 -fi -if ! run "curl -sS localhost/index.html | grep 'hello world'"; then - run "docker stop ${RAND_NAME}" - exit 1 -fi - - -### -### Cleanup -### -run "docker stop ${RAND_NAME}" diff --git a/tests/01-test-php.sh b/tests/01-test-php.sh new file mode 100755 index 0000000..3a34141 --- /dev/null +++ b/tests/01-test-php.sh @@ -0,0 +1,85 @@ +#!/usr/bin/env bash + +set -e +set -u +set -o pipefail + +CWD="$(cd -P -- "$(dirname -- "$0")" && pwd -P)" + +IMAGE="${1}" +#NAME="${2}" +#VERSION="${3}" +TAG="${4}" +ARCH="${5}" + + +HOST_PORT="8093" + +### +### Load Library +### +# shellcheck disable=SC1091 +. "${CWD}/.lib.sh" + + + +### +### Preparation +### +RAND_DIR="$( mktemp -d )" +RAND_NAME1="$( get_random_name )" +RAND_NAME2="$( get_random_name )" +run "chmod 0755 ${RAND_DIR}" +run "echo \" ${RAND_DIR}/index.php" + + +### +### Startup container +### +run "docker run -d --rm --platform ${ARCH} \ + -v ${RAND_DIR}:/var/www/default/htdocs \ + --name ${RAND_NAME1} \ + devilbox/php-fpm-8.1" + +run "docker run --rm --platform ${ARCH} \ + -v ${RAND_DIR}:/var/www/default/htdocs \ + -p 127.0.0.1:${HOST_PORT}:80 \ + -e DEBUG_ENTRYPOINT=2 \ + -e DEBUG_RUNTIME=1 \ + -e NEW_UID=$( id -u ) \ + -e NEW_GID=$( id -g ) \ + -e PHP_FPM_ENABLE=1 \ + -e PHP_FPM_SERVER_ADDR=${RAND_NAME1} \ + -e PHP_FPM_SERVER_PORT=9000 \ + --link ${RAND_NAME1} \ + --name ${RAND_NAME2} \ + ${IMAGE}:${TAG} &" + + +### +### Tests +### +WAIT=120 +INDEX=0 +printf "Testing connectivity" +while ! curl -sS "http://localhost:${HOST_PORT}" 2>/dev/null | grep 'hello world php'; do + printf "." + if [ "${INDEX}" = "${WAIT}" ]; then + printf "\\n" + run "docker logs ${RAND_NAME1}" || true + run "docker logs ${RAND_NAME2}" || true + run "docker stop ${RAND_NAME1}" || true + run "docker stop ${RAND_NAME2}" || true + echo "Error" + exit 1 + fi + INDEX=$(( INDEX + 1 )) + sleep 1 +done +printf "\\n[OK] Test success\\n" + +### +### Cleanup +### +run "docker stop ${RAND_NAME1}" +run "docker stop ${RAND_NAME2}" diff --git a/tests/01.sh b/tests/02-timezone.sh similarity index 60% rename from tests/01.sh rename to tests/02-timezone.sh index 3d9e3e5..6dbc280 100755 --- a/tests/01.sh +++ b/tests/02-timezone.sh @@ -13,6 +13,8 @@ TAG="${4}" ARCH="${5}" +HOST_PORT="8093" + ### ### Load Library ### @@ -38,37 +40,42 @@ run "docker run -d --rm --platform ${ARCH} \ -v ${RAND_DIR}:/var/www/default/htdocs \ --name ${RAND_NAME1} devilbox/php-fpm-8.1" -run "docker run -d --rm --platform ${ARCH} \ +run "docker run --rm --platform ${ARCH} \ -v ${RAND_DIR}:/var/www/default/htdocs \ - -p 127.0.0.1:80:80 \ + -p 127.0.0.1:${HOST_PORT}:80 \ -e DEBUG_ENTRYPOINT=2 \ -e DEBUG_RUNTIME=1 \ + -e TIMEZONE=Europe/Berlin \ -e NEW_UID=$( id -u ) \ -e NEW_GID=$( id -g ) \ -e PHP_FPM_ENABLE=1 \ -e PHP_FPM_SERVER_ADDR=${RAND_NAME1} \ -e PHP_FPM_SERVER_PORT=9000 \ --link ${RAND_NAME1} \ - --name ${RAND_NAME2} ${IMAGE}:${TAG}" + --name ${RAND_NAME2} ${IMAGE}:${TAG} &" ### ### Tests ### -run "sleep 20" # Startup-time is longer on cross-platform -run "docker ps" -run "docker logs ${RAND_NAME1}" -run "docker logs ${RAND_NAME2}" -if ! run "curl localhost"; then - run "docker stop ${RAND_NAME1}" - run "docker stop ${RAND_NAME2}" - exit 1 -fi -if ! run "curl localhost | grep 'hello world php'"; then - run "docker stop ${RAND_NAME1}" - run "docker stop ${RAND_NAME2}" - exit 1 -fi +WAIT=120 +INDEX=0 +printf "Testing connectivity" +while ! curl -sS "http://localhost:${HOST_PORT}" 2>/dev/null | grep 'hello world php'; do + printf "." + if [ "${INDEX}" = "${WAIT}" ]; then + printf "\\n" + run "docker logs ${RAND_NAME1}" || true + run "docker logs ${RAND_NAME2}" || true + run "docker stop ${RAND_NAME1}" || true + run "docker stop ${RAND_NAME2}" || true + echo "Error" + exit 1 + fi + INDEX=$(( INDEX + 1 )) + sleep 1 +done +printf "\\n[OK] Test success\\n" ### ### Cleanup diff --git a/tests/start-ci.sh b/tests/start-ci.sh index 1777030..bdd8a48 100755 --- a/tests/start-ci.sh +++ b/tests/start-ci.sh @@ -43,6 +43,8 @@ else echo "################################################################################" echo "# [${CWD}/${i}] ${IMAGE}:${TAG} ${NAME}-${VERSION} (${ARCH})" echo "################################################################################" - sh -c "${i} ${IMAGE} ${NAME} ${VERSION} ${TAG} ${ARCH}" + if ! sh -c "${i} ${IMAGE} ${NAME} ${VERSION} ${TAG} ${ARCH}"; then + exit 1 + fi done fi