Skip to content

Commit

Permalink
[TASK] Apply some runTests.sh cleanups
Browse files Browse the repository at this point in the history
 * Always clean-up containers when Control-C is pressed
 * Enforce removing networks even if some containers have not been
   fully stopped (does not work with older docker versions, therefore
   only enabled for podman)
 * Bail out if `waitFor` failed instead of resuming with subsequent
   commands
 * Avoid waiting unnecessarily for VNC-web port 7900 in headless mode
 * Do not derive `--pull=never` from the `$CI` environment variable, as
   `$CI` is set both in gitlab [1] and github [2] actions.
   runTests.sh might be used in github actions, therefore this flag is
   moved into our gitlab-ci specific configuration.
 * Fix typos

[1] https://docs.gitlab.com/ee/ci/variables/predefined_variables.html
[2] https://docs.github.com/en/actions/learn-github-actions/variables#default-environment-variables

Resolves: #103420
Releases: main, 12.4, 11.5
Change-Id: Ie8fcdc5ebc5ba651242bb54faffdfd8de0dc6026
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/83515
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Reviewed-by: Stefan Bürk <stefan@buerk.tech>
Reviewed-by: Benjamin Franzke <ben@bnf.dev>
Tested-by: core-ci <typo3@b13.com>
Tested-by: Stefan Bürk <stefan@buerk.tech>
Tested-by: Benjamin Franzke <ben@bnf.dev>
  • Loading branch information
bnf committed Mar 19, 2024
1 parent 3893153 commit 5ebc2e3
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 7 deletions.
28 changes: 21 additions & 7 deletions Build/Scripts/runTests.sh
Expand Up @@ -4,6 +4,8 @@
# TYPO3 core test runner based on docker or podman
#

trap 'cleanUp;exit 2' SIGINT

waitFor() {
local HOST=${1}
local PORT=${2}
Expand All @@ -19,14 +21,21 @@ waitFor() {
done;
"
${CONTAINER_BIN} run ${CONTAINER_COMMON_PARAMS} --name wait-for-${SUFFIX} ${XDEBUG_MODE} -e XDEBUG_CONFIG="${XDEBUG_CONFIG}" ${IMAGE_ALPINE} /bin/sh -c "${TESTCOMMAND}"
if [[ $? -gt 0 ]]; then
kill -SIGINT -$$
fi
}

cleanUp() {
ATTACHED_CONTAINERS=$(${CONTAINER_BIN} ps --filter network=${NETWORK} --format='{{.Names}}')
for ATTACHED_CONTAINER in ${ATTACHED_CONTAINERS}; do
${CONTAINER_BIN} kill ${ATTACHED_CONTAINER} >/dev/null
done
${CONTAINER_BIN} network rm ${NETWORK} >/dev/null
if [ ${CONTAINER_BIN} = "docker" ]; then
${CONTAINER_BIN} network rm ${NETWORK} >/dev/null
else
${CONTAINER_BIN} network rm -f ${NETWORK} >/dev/null
fi
}

handleDbmsOptions() {
Expand Down Expand Up @@ -399,7 +408,7 @@ HOST_PID=$(id -g)
USERSET=""
SUFFIX=$(echo $RANDOM)
NETWORK="typo3-core-${SUFFIX}"
CI_PARAMS=""
CI_PARAMS="${CI_PARAMS:-}"
CONTAINER_HOST="host.docker.internal"

# Option parsing updates above default vars
Expand Down Expand Up @@ -495,7 +504,6 @@ handleDbmsOptions
if [ "${CI}" == "true" ]; then
PHPSTAN_CONFIG_FILE="phpstan.ci.neon"
CONTAINER_INTERACTIVE=""
CI_PARAMS="--pull=never"
fi

# determine default container binary to use: 1. podman 2. docker
Expand Down Expand Up @@ -593,7 +601,9 @@ case ${TEST_SUITE} in
${CONTAINER_BIN} run --rm ${CI_PARAMS} -d --name ac-web-${SUFFIX} --network ${NETWORK} --network-alias web -v ${CORE_ROOT}:${CORE_ROOT} ${APACHE_OPTIONS} ${IMAGE_APACHE} >/dev/null
fi
waitFor chrome 4444
waitFor chrome 7900
if [ "${ACCEPTANCE_HEADLESS}" -eq 0 ]; then
waitFor chrome 7900
fi
waitFor web 80
if [ "${ACCEPTANCE_HEADLESS}" -eq 0 ] && type "xdg-open" >/dev/null; then
xdg-open http://localhost:7900/?autoconnect=1 >/dev/null
Expand Down Expand Up @@ -688,7 +698,9 @@ case ${TEST_SUITE} in
${CONTAINER_BIN} run --rm ${CI_PARAMS} -d --name ac-web-${SUFFIX} --network ${NETWORK} --network-alias web -v ${CORE_ROOT}:${CORE_ROOT} ${APACHE_OPTIONS} ${IMAGE_APACHE} >/dev/null
fi
waitFor chrome 4444
waitFor chrome 7900
if [ "${ACCEPTANCE_HEADLESS}" -eq 0 ]; then
waitFor chrome 7900
fi
waitFor web 80
if [ "${ACCEPTANCE_HEADLESS}" -eq 0 ] && type "xdg-open" >/dev/null; then
xdg-open http://localhost:7900/?autoconnect=1 >/dev/null
Expand All @@ -708,7 +720,7 @@ case ${TEST_SUITE} in
rm -rf "${CORE_ROOT}/typo3temp/var/tests/acceptance" "${CORE_ROOT}/typo3temp/var/tests/AcceptanceReports"
mkdir -p "${CORE_ROOT}/typo3temp/var/tests/acceptance"
APACHE_OPTIONS="-e APACHE_RUN_USER=#${HOST_UID} -e APACHE_RUN_SERVERNAME=web -e APACHE_RUN_GROUP=#${HOST_PID} -e APACHE_RUN_DOCROOT=${CORE_ROOT}/typo3temp/var/tests/acceptance -e PHPFPM_HOST=phpfpm -e PHPFPM_PORT=9000"
${CONTAINER_BIN} run --rm ${CI_PARAMS} -d ${SELENIUM_GRID} --name ac-istall-chrome-${SUFFIX} --network ${NETWORK} --network-alias chrome --tmpfs /dev/shm:rw,nosuid,nodev,noexec ${IMAGE_SELENIUM} >/dev/null
${CONTAINER_BIN} run --rm ${CI_PARAMS} -d ${SELENIUM_GRID} --name ac-install-chrome-${SUFFIX} --network ${NETWORK} --network-alias chrome --tmpfs /dev/shm:rw,nosuid,nodev,noexec ${IMAGE_SELENIUM} >/dev/null
if [ ${CONTAINER_BIN} = "docker" ]; then
${CONTAINER_BIN} run --rm -d --name ac-install-phpfpm-${SUFFIX} --network ${NETWORK} --network-alias phpfpm --add-host "${CONTAINER_HOST}:host-gateway" ${USERSET} -e PHPFPM_USER=${HOST_UID} -e PHPFPM_GROUP=${HOST_PID} -v ${CORE_ROOT}:${CORE_ROOT} ${IMAGE_PHP} php-fpm ${PHP_FPM_OPTIONS} >/dev/null
${CONTAINER_BIN} run --rm -d --name ac-install-web-${SUFFIX} --network ${NETWORK} --network-alias web --add-host "${CONTAINER_HOST}:host-gateway" -v ${CORE_ROOT}:${CORE_ROOT} ${APACHE_OPTIONS} ${IMAGE_APACHE} >/dev/null
Expand All @@ -717,7 +729,9 @@ case ${TEST_SUITE} in
${CONTAINER_BIN} run --rm ${CI_PARAMS} -d --name ac-install-web-${SUFFIX} --network ${NETWORK} --network-alias web -v ${CORE_ROOT}:${CORE_ROOT} ${APACHE_OPTIONS} ${IMAGE_APACHE} >/dev/null
fi
waitFor chrome 4444
waitFor chrome 7900
if [ "${ACCEPTANCE_HEADLESS}" -eq 0 ]; then
waitFor chrome 7900
fi
waitFor web 80
if [ "${ACCEPTANCE_HEADLESS}" -eq 0 ] && type "xdg-open" >/dev/null; then
xdg-open http://localhost:7900/?autoconnect=1 >/dev/null
Expand Down
4 changes: 4 additions & 0 deletions Build/gitlab-ci.yml
Expand Up @@ -10,6 +10,10 @@ variables:
# and fails with package conflicts. Having a full clone by setting depth 0
# prevents this, so we don't need to fiddle with COMPOSER_ROOT_VERSION env var.
GIT_DEPTH: 0
# The `--pull=never` flag must not be removed.
# All images used by CI-jobs have to be preloaded on the TYPO3 testing
# infrastructure to avoid exceeding rate limits for docker.io or ghcr.io.
CI_PARAMS: "--pull=never"

cache:
# Default caching of .cache directory if a job does not override it.
Expand Down

0 comments on commit 5ebc2e3

Please sign in to comment.