From b27d86cd132b442c4562bd8d4ff0b37a03394df2 Mon Sep 17 00:00:00 2001 From: Zach Borboa Date: Sat, 13 Mar 2021 18:03:24 -0500 Subject: [PATCH] Add files to run php80 tests inside a docker container --- tests/PHPCurlClass/Helper.php | 2 +- tests/before_script.sh | 2 ++ tests/dockerfiles/php80/1_build.sh | 3 +++ tests/dockerfiles/php80/2_start.sh | 15 ++++++++++++++ tests/dockerfiles/php80/3_test.sh | 18 +++++++++++++++++ tests/dockerfiles/php80/4_stop.sh | 3 +++ tests/dockerfiles/php80/Dockerfile | 19 ++++++++++++++++++ tests/dockerfiles/php80/attach.sh | 3 +++ tests/dockerfiles/php80/run.sh | 23 ++++++++++++++++++++++ tests/dockerfiles/php80/run_interactive.sh | 14 +++++++++++++ 10 files changed, 101 insertions(+), 1 deletion(-) create mode 100755 tests/dockerfiles/php80/1_build.sh create mode 100755 tests/dockerfiles/php80/2_start.sh create mode 100755 tests/dockerfiles/php80/3_test.sh create mode 100755 tests/dockerfiles/php80/4_stop.sh create mode 100644 tests/dockerfiles/php80/Dockerfile create mode 100755 tests/dockerfiles/php80/attach.sh create mode 100755 tests/dockerfiles/php80/run.sh create mode 100755 tests/dockerfiles/php80/run_interactive.sh diff --git a/tests/PHPCurlClass/Helper.php b/tests/PHPCurlClass/Helper.php index d4ab84a..68ca777 100644 --- a/tests/PHPCurlClass/Helper.php +++ b/tests/PHPCurlClass/Helper.php @@ -54,7 +54,7 @@ class Test public static function getTestUrl($port) { if (getenv('PHP_CURL_CLASS_LOCAL_TEST') === 'yes' || - in_array(getenv('TRAVIS_PHP_VERSION'), array('7.0', '7.1', '7.2', '7.3', '7.4', 'nightly'))) { + in_array(getenv('TRAVIS_PHP_VERSION'), array('7.0', '7.1', '7.2', '7.3', '7.4', '8.0', 'nightly'))) { return 'http://127.0.0.1:' . $port . '/'; } else { return self::TEST_URL; diff --git a/tests/before_script.sh b/tests/before_script.sh index 726d24a..fd321d6 100755 --- a/tests/before_script.sh +++ b/tests/before_script.sh @@ -178,6 +178,8 @@ elif [[ "${TRAVIS_PHP_VERSION}" == "7.3" ]]; then start_php_servers elif [[ "${TRAVIS_PHP_VERSION}" == "7.4" ]]; then start_php_servers +elif [[ "${TRAVIS_PHP_VERSION}" == "8.0" ]]; then + start_php_servers elif [[ "${TRAVIS_PHP_VERSION}" == "hhvm" || "${TRAVIS_PHP_VERSION}" == "hhvm-nightly" ]]; then curl "https://nginx.org/keys/nginx_signing.key" | sudo apt-key add - echo "deb https://nginx.org/packages/mainline/ubuntu/ trusty nginx" | sudo tee -a /etc/apt/sources.list diff --git a/tests/dockerfiles/php80/1_build.sh b/tests/dockerfiles/php80/1_build.sh new file mode 100755 index 0000000..f7b9384 --- /dev/null +++ b/tests/dockerfiles/php80/1_build.sh @@ -0,0 +1,3 @@ +# Build an image. +set -x +docker build --tag="php-curl-class/php80" . diff --git a/tests/dockerfiles/php80/2_start.sh b/tests/dockerfiles/php80/2_start.sh new file mode 100755 index 0000000..699e8d9 --- /dev/null +++ b/tests/dockerfiles/php80/2_start.sh @@ -0,0 +1,15 @@ +# Run image to create container. + +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +set -x +cd "${SCRIPT_DIR}/../../.." +project_dir="${PWD}" + +docker start "php80" || + docker run \ + --detach \ + --interactive \ + --mount "type=bind,src=${project_dir},dst=/data,readonly=true" \ + --name="php80" \ + --tty \ + "php-curl-class/php80" diff --git a/tests/dockerfiles/php80/3_test.sh b/tests/dockerfiles/php80/3_test.sh new file mode 100755 index 0000000..b343eb5 --- /dev/null +++ b/tests/dockerfiles/php80/3_test.sh @@ -0,0 +1,18 @@ +# Run tests inside container. +command=$(cat <<-END +mkdir --parents "/tmp/php-curl-class" && +rsync --delete --exclude=".git" --exclude="vendor" --exclude="composer.lock" --links --recursive "/data/" "/tmp/php-curl-class/" && +cd "/tmp/php-curl-class" && +export TRAVIS_PHP_VERSION="8.0" && +( + [ ! -f "/tmp/.composer_updated" ] && + composer --no-interaction update && + touch "/tmp/.composer_updated" || + exit 0 +) && +bash "tests/before_script.sh" && +bash "tests/script.sh" +END +) +set -x +docker exec --tty "php80" sh -c "${command}" diff --git a/tests/dockerfiles/php80/4_stop.sh b/tests/dockerfiles/php80/4_stop.sh new file mode 100755 index 0000000..c3e6488 --- /dev/null +++ b/tests/dockerfiles/php80/4_stop.sh @@ -0,0 +1,3 @@ +# Stop container. +set -x +docker stop "php80" diff --git a/tests/dockerfiles/php80/Dockerfile b/tests/dockerfiles/php80/Dockerfile new file mode 100644 index 0000000..9d75040 --- /dev/null +++ b/tests/dockerfiles/php80/Dockerfile @@ -0,0 +1,19 @@ +FROM php:8.0-cli +ENV DEBIAN_FRONTEND noninteractive + +RUN apt-get --assume-yes --quiet update + +RUN apt-get --assume-yes --quiet install git && \ + apt-get --assume-yes --quiet install libpng-dev && \ + apt-get --assume-yes --quiet install rsync && \ + apt-get --assume-yes --quiet install zip + +RUN curl --silent --show-error "https://getcomposer.org/installer" | php && \ + mv "composer.phar" "/usr/local/bin/composer" && \ + composer global require --no-interaction "phpunit/phpunit" + +RUN docker-php-ext-configure gd && \ + docker-php-ext-install gd + +ENV PATH /root/.composer/vendor/bin:$PATH +CMD ["bash"] diff --git a/tests/dockerfiles/php80/attach.sh b/tests/dockerfiles/php80/attach.sh new file mode 100755 index 0000000..cfd1f0e --- /dev/null +++ b/tests/dockerfiles/php80/attach.sh @@ -0,0 +1,3 @@ +# Attach to running container. + +docker exec --interactive --tty "php80" bash -l diff --git a/tests/dockerfiles/php80/run.sh b/tests/dockerfiles/php80/run.sh new file mode 100755 index 0000000..ced63cf --- /dev/null +++ b/tests/dockerfiles/php80/run.sh @@ -0,0 +1,23 @@ +bash "1_build.sh" +if [[ $? -ne 0 ]]; then + echo "Error: Build failed" + exit 1 +fi + +bash "2_start.sh" +if [[ $? -ne 0 ]]; then + echo "Error: Start failed" + exit 1 +fi + +bash "3_test.sh" +if [[ $? -ne 0 ]]; then + echo "Error: Test failed" + exit 1 +fi + +bash "4_stop.sh" +if [[ $? -ne 0 ]]; then + echo "Error: Stop failed" + exit 1 +fi diff --git a/tests/dockerfiles/php80/run_interactive.sh b/tests/dockerfiles/php80/run_interactive.sh new file mode 100755 index 0000000..e79b8b4 --- /dev/null +++ b/tests/dockerfiles/php80/run_interactive.sh @@ -0,0 +1,14 @@ +# Run image to create container and attach to it. + +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +set -x +cd "${SCRIPT_DIR}/../../.." +project_dir="${PWD}" + +docker run \ + --interactive \ + --mount "type=bind,src=${project_dir},dst=/data,readonly=true" \ + --name="php80" \ + --rm \ + --tty \ + "php-curl-class/php80" /bin/bash