From 7babc0fc84e8cca70c8cf8d5349ce1dc6cba691e Mon Sep 17 00:00:00 2001 From: gggeek Date: Thu, 10 Dec 2020 17:28:24 +0000 Subject: [PATCH 1/1] WIP add a Docker-based test env --- .travis.yml | 9 +- tests/ci/Dockerfile | 29 +++++++ tests/ci/config/apache_vhost | 61 +++++++++++++ tests/ci/{travis => config}/privoxy | 0 tests/ci/docker/entrypoint.sh | 67 +++++++++++++++ tests/ci/setup/create_user.sh | 20 +++++ tests/ci/setup/get_composer.sh | 20 +++++ tests/ci/setup/install_packages.sh | 6 ++ tests/ci/setup/setup_apache.sh | 28 ++++++ tests/ci/setup/setup_php.sh | 108 +++++++++++++++++++++++ tests/ci/setup/setup_privoxy.sh | 12 +++ tests/ci/travis/apache_vhost | 84 ------------------ tests/ci/travis/setup_apache.sh | 15 ---- tests/ci/travis/setup_php_fpm.sh | 22 ----- tests/ci/travis/setup_privoxy.sh | 6 -- tests/ci/vm.sh | 128 ++++++++++++++++++++++++++++ 16 files changed, 484 insertions(+), 131 deletions(-) create mode 100644 tests/ci/Dockerfile create mode 100644 tests/ci/config/apache_vhost rename tests/ci/{travis => config}/privoxy (100%) create mode 100644 tests/ci/docker/entrypoint.sh create mode 100644 tests/ci/setup/create_user.sh create mode 100644 tests/ci/setup/get_composer.sh create mode 100644 tests/ci/setup/install_packages.sh create mode 100644 tests/ci/setup/setup_apache.sh create mode 100644 tests/ci/setup/setup_php.sh create mode 100644 tests/ci/setup/setup_privoxy.sh delete mode 100644 tests/ci/travis/apache_vhost delete mode 100755 tests/ci/travis/setup_apache.sh delete mode 100755 tests/ci/travis/setup_php_fpm.sh delete mode 100755 tests/ci/travis/setup_privoxy.sh create mode 100644 tests/ci/vm.sh diff --git a/.travis.yml b/.travis.yml index c2703572..bcb3af8e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -38,6 +38,7 @@ before_install: - sudo apt-get install -y privoxy # Disable xdebug for speed (executing composer), but allow us to re-enable it later + # @todo move to setup_php - export XDEBUG_INI=`php -i | grep xdebug.ini | grep home/travis | grep -v '=>' | head -1` - export XDEBUG_INI=${XDEBUG_INI/,/} - if [ "$XDEBUG_INI" != "" ]; then mv "$XDEBUG_INI" "$XDEBUG_INI.bak"; fi @@ -51,15 +52,15 @@ install: before_script: # Set up Apache and Privoxy instances inside the Travis VM and use them for testing against - - ./tests/ci/travis/setup_php_fpm.sh - - ./tests/ci/travis/setup_apache.sh - - ./tests/ci/travis/setup_privoxy.sh + - sudo ./tests/ci/setup/setup_apache.sh + - sudo ./tests/ci/setup/setup_php.sh + - sudo ./tests/ci/setup/setup_privoxy.sh # output what version of phpunit we got going - vendor/bin/phpunit --version script: - vendor/bin/phpunit $COVERAGE_OPTS tests + ./vendor/bin/phpunit $COVERAGE_OPTS tests after_failure: # Save as much info as we can to help developers diff --git a/tests/ci/Dockerfile b/tests/ci/Dockerfile new file mode 100644 index 00000000..a6040201 --- /dev/null +++ b/tests/ci/Dockerfile @@ -0,0 +1,29 @@ +ARG UBUNTU_VERSION=xenial + +FROM ubuntu:${UBUNTU_VERSION} + +ARG PHP_VERSION=default + +RUN mkdir -p /usr/share/man/man1 && \ + apt-get update + +COPY setup/*.sh /root/setup/ +COPY config/* /root/config/ + +RUN chmod 755 /root/setup/*.sh && \ + cd /root/setup && \ + ./install_packages.sh && \ + ./create_user.sh && \ + ./setup_apache.sh && \ + ./setup_privoxy.sh && \ + ./setup_php.sh "${PHP_VERSION}" && \ + apt-get remove -y composer || echo An error on the line above is ok; ./get_composer.sh && mv /usr/local/bin/composer.phar /usr/local/bin/composer && chmod 755 /usr/local/bin/composer + +COPY docker/entrypoint.sh /root/entrypoint.sh +RUN chmod 755 /root/entrypoint.sh + +EXPOSE 80 443 8080 + +WORKDIR /home/test + +ENTRYPOINT ["/root/entrypoint.sh"] diff --git a/tests/ci/config/apache_vhost b/tests/ci/config/apache_vhost new file mode 100644 index 00000000..0b821ce9 --- /dev/null +++ b/tests/ci/config/apache_vhost @@ -0,0 +1,61 @@ +# Uses env var: TESTS_ROOT_DIR + + + + DocumentRoot ${TESTS_ROOT_DIR} + + ErrorLog "${TESTS_ROOT_DIR}/apache_error.log" + CustomLog "${TESTS_ROOT_DIR}/apache_access.log" combined + + + Options FollowSymLinks MultiViews + AllowOverride All + + Require all granted + + # needed for basic auth (PHP_AUTH_USER and PHP_AUTH_PW) + RewriteEngine on + RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}] + RewriteRule .* - [E=REMOTE_USER:%{HTTP:Authorization}] + + + + + + + + + DocumentRoot ${TESTS_ROOT_DIR} + + ErrorLog "${TESTS_ROOT_DIR}/apache_error.log" + CustomLog "${TESTS_ROOT_DIR}/apache_access.log" combined + + + Options FollowSymLinks MultiViews + AllowOverride All + + Require all granted + + # needed for basic auth (PHP_AUTH_USER and PHP_AUTH_PW) + RewriteEngine on + RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}] + RewriteRule .* - [E=REMOTE_USER:%{HTTP:Authorization}] + + + SSLEngine on + # This cert is bundled by default in Ubuntu + SSLCertificateFile /etc/ssl/certs/ssl-cert-snakeoil.pem + SSLCertificateKeyFile /etc/ssl/private/ssl-cert-snakeoil.key + + + SSLOptions +StdEnvVars + + + BrowserMatch "MSIE [2-6]" \ + nokeepalive ssl-unclean-shutdown \ + downgrade-1.0 force-response-1.0 + BrowserMatch "MSIE [17-9]" ssl-unclean-shutdown + + + + diff --git a/tests/ci/travis/privoxy b/tests/ci/config/privoxy similarity index 100% rename from tests/ci/travis/privoxy rename to tests/ci/config/privoxy diff --git a/tests/ci/docker/entrypoint.sh b/tests/ci/docker/entrypoint.sh new file mode 100644 index 00000000..2642cc0a --- /dev/null +++ b/tests/ci/docker/entrypoint.sh @@ -0,0 +1,67 @@ +#!/bin/sh + +# @todo make username flexible + +USERNAME=test + +echo "[$(date)] Bootstrapping the Test container..." + +clean_up() { + # Perform program exit housekeeping + + echo "[$(date)] Stopping the Web server" + service apache2 stop + + echo "[$(date)] Stopping Privoxy" + service privoxy stop + + echo "[$(date)] Stopping FPM" + service php-fpm stop + + echo "[$(date)] Exiting" + exit +} + +# Fix UID & GID for user + +echo "[$(date)] Fixing filesystem permissions..." + +ORIGPASSWD=$(cat /etc/passwd | grep "^${USERNAME}:") +ORIG_UID=$(echo "$ORIGPASSWD" | cut -f3 -d:) +ORIG_GID=$(echo "$ORIGPASSWD" | cut -f4 -d:) +CONTAINER_USER_HOME=$(echo "$ORIGPASSWD" | cut -f6 -d:) +CONTAINER_USER_UID=${CONTAINER_USER_UID:=$ORIG_UID} +CONTAINER_USER_GID=${CONTAINER_USER_GID:=$ORIG_GID} + +if [ "$CONTAINER_USER_UID" != "$ORIG_UID" -o "$CONTAINER_USER_GID" != "$ORIG_GID" ]; then + groupmod -g "$CONTAINER_USER_GID" "${USERNAME}" + usermod -u "$CONTAINER_USER_UID" -g "$CONTAINER_USER_GID" "${USERNAME}" +fi +if [ $(stat -c '%u' "${CONTAINER_USER_HOME}") != "${CONTAINER_USER_UID}" -o $(stat -c '%g' "${CONTAINER_USER_HOME}") != "${CONTAINER_USER_GID}" ]; then + chown "${CONTAINER_USER_UID}":"${CONTAINER_USER_GID}" "${CONTAINER_USER_HOME}" + chown -R "${CONTAINER_USER_UID}":"${CONTAINER_USER_GID}" "${CONTAINER_USER_HOME}"/.* +fi + +echo "[$(date)] Fixing apache configuration..." + +# @todo set as well APACHE_RUN_USER and/or APACHE_RUN_GROUP ? +sed -e "s?^export TESTS_ROOT_DIR=.*?export TESTS_ROOT_DIR=${TESTS_ROOT_DIR}?g" --in-place /etc/apache2/envvars + +echo "[$(date)] Running Composer..." + +sudo test -c "cd /home/test && composer install" + +trap clean_up TERM + +echo "[$(date)] Starting FPM..." +service php-fpm start + +echo "[$(date)] Starting the Web server..." +service apache2 start + +echo "[$(date)] Starting Privoxy..." +service privoxy start + +tail -f /dev/null & +child=$! +wait "$child" diff --git a/tests/ci/setup/create_user.sh b/tests/ci/setup/create_user.sh new file mode 100644 index 00000000..b92951d2 --- /dev/null +++ b/tests/ci/setup/create_user.sh @@ -0,0 +1,20 @@ +#!/bin/sh + +# @todo set up the same user for running tests as on travis (ie. 'travis'), or maybe user 'user' ? +# @todo make the GID & UID of the user variable + +set -e + +USERNAME="${1:-test}" + +addgroup --gid 1013 ${USERNAME} +adduser --system --uid=1013 --gid=1013 --home /home/${USERNAME} --shell /bin/bash ${USERNAME} +adduser ${USERNAME} ${USERNAME} + +mkdir -p /home/${USERNAME}/.ssh +cp /etc/skel/.[!.]* /home/${USERNAME} + +adduser ${USERNAME} sudo +sed -i "\$ a ${USERNAME} ALL=\(ALL:ALL\) NOPASSWD: ALL" /etc/sudoers + +chown -R ${USERNAME}:${USERNAME} /home/${USERNAME} diff --git a/tests/ci/setup/get_composer.sh b/tests/ci/setup/get_composer.sh new file mode 100644 index 00000000..ba2d2a19 --- /dev/null +++ b/tests/ci/setup/get_composer.sh @@ -0,0 +1,20 @@ +#!/bin/sh + +# Installs Composer (latest version, to avoid relying on old ones bundled with the OS) +# @todo allow users to lock down to Composer v1 if needed + +EXPECTED_SIGNATURE="$(wget -q -O - https://composer.github.io/installer.sig)" +php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" +ACTUAL_SIGNATURE="$(php -r "echo hash_file('sha384', 'composer-setup.php');")" + +if [ "$EXPECTED_SIGNATURE" != "$ACTUAL_SIGNATURE" ] +then + >&2 echo 'ERROR: Invalid installer signature' + rm composer-setup.php + exit 1 +fi + +php composer-setup.php --install-dir=/usr/local/bin +RESULT=$? +rm composer-setup.php +exit $RESULT diff --git a/tests/ci/setup/install_packages.sh b/tests/ci/setup/install_packages.sh new file mode 100644 index 00000000..c760675e --- /dev/null +++ b/tests/ci/setup/install_packages.sh @@ -0,0 +1,6 @@ +#!/bin/sh + +set -e + +DEBIAN_FRONTEND=noninteractive apt-get install -y \ + lsb-release sudo unzip wget zip diff --git a/tests/ci/setup/setup_apache.sh b/tests/ci/setup/setup_apache.sh new file mode 100644 index 00000000..5faee24a --- /dev/null +++ b/tests/ci/setup/setup_apache.sh @@ -0,0 +1,28 @@ +#!/bin/sh + +set -e + +# @todo make this work across all apache versions (precise to focal) + +SCRIPT_DIR="$(dirname -- "$(readlink -f "$0")")" + +# install and configure apache2 + +DEBIAN_FRONTEND=noninteractive apt-get install -y apache2 + +# set up Apache for php-fpm +# @see https://github.com/travis-ci/travis-ci.github.com/blob/master/docs/user/languages/php.md#apache--php + +a2enmod rewrite proxy_fcgi setenvif ssl + +# configure apache virtual hosts + +cp -f "$SCRIPT_DIR/../config/apache_vhost" /etc/apache2/sites-available/000-default.conf + +if [ -n "${TRAVIS}" ]; then + echo "export TESTS_ROOT_DIR=$(pwd)" >> /etc/apache2/envvars +else + echo "export TESTS_ROOT_DIR=/var/www/html" >> /etc/apache2/envvars +fi + +service apache2 restart diff --git a/tests/ci/setup/setup_php.sh b/tests/ci/setup/setup_php.sh new file mode 100644 index 00000000..d9624de7 --- /dev/null +++ b/tests/ci/setup/setup_php.sh @@ -0,0 +1,108 @@ +#!/bin/sh + +set -e + +configure_php_ini() { + # @todo make this idempotent so that it can be run multiple times in a row + echo "cgi.fix_pathinfo = 1" >> "${1}" + echo "always_populate_raw_post_data = -1" >> "${1}" + + XDEBUG_INI=$(php -i | grep xdebug.ini | grep -v '=>' | head -1) + if [ "$XDEBUG_INI" != "" ]; then + #XDEBUG_INI=${XDEBUG_INI/,/} + mv "$XDEBUG_INI" "$XDEBUG_INI.bak"; + fi +} + +if ! which php >/dev/null; then + + # install php + PHP_VERSION=$1 + DEBIAN_VERSION=$(lsb_release -s -c) + + if [ "${PHP_VERSION}" = default ]; then + if [ "${DEBIAN_VERSION}" = jessie -o "${DEBIAN_VERSION}" = precise -o "${DEBIAN_VERSION}" = trusty ]; then + PHPSUFFIX=5 + else + PHPSUFFIX= + fi + # @todo check for mbstring presence in php5 (jessie) packages + DEBIAN_FRONTEND=noninteractive apt-get install -y \ + php${PHPSUFFIX} \ + php${PHPSUFFIX}-cli \ + php${PHPSUFFIX}-dom \ + php${PHPSUFFIX}-curl \ + php${PHPSUFFIX}-fpm \ + php${PHPSUFFIX}-mbstring \ + php${PHPSUFFIX}-xdebug + else + #DEBIAN_FRONTEND=noninteractive apt-get install -y \ + # gnupg2 ca-certificates lsb-release apt-transport-https + #wget https://packages.sury.org/php/apt.gpg + #apt-key add apt.gpg + #echo "deb https://packages.sury.org/php/ $(lsb_release -sc) main" > /etc/apt/sources.list.d/php.list + + DEBIAN_FRONTEND=noninteractive apt-get install -y language-pack-en-base software-properties-common + LC_ALL=en_US.UTF-8 add-apt-repository ppa:ondrej/php + apt-get update + + DEBIAN_FRONTEND=noninteractive apt-get install -y \ + php${PHP_VERSION} \ + php${PHP_VERSION}-cli \ + php${PHP_VERSION}-dom \ + php${PHP_VERSION}-curl \ + php${PHP_VERSION}-fpm \ + php${PHP_VERSION}-mbstring \ + php${PHP_VERSION}-xdebug + + update-alternatives --set php /usr/bin/php${PHP_VERSION} + fi + + PHPVER=$(php -r 'echo implode(".",array_slice(explode(".",PHP_VERSION),0,2));' 2>/dev/null) + + configure_php_ini /etc/php/${PHPVER}/fpm/php.ini + + # use a nice name for the php-fpm service, so that it does not depend on php version running + service "php${PHPVER}-fpm" stop + ln -s "/etc/init.d/php${PHPVER}-fpm" /etc/init.d/php-fpm + + # @todo shall we configure php-fpm? + + service php-fpm start + + # configure apache + a2enconf php${PHPVER}-fpm + service apache2 restart +fi + +if [ -n "$TRAVIS" ]; then + + # php is already installed, via phpenv + + PHPVER=$(phpenv version-name) + + configure_php_ini ~/.phpenv/versions/${PHPVER}/etc/php.ini + + # configure php-fpm + cp ~/.phpenv/versions/${PHPVER}/etc/php-fpm.conf.default ~/.phpenv/versions/${PHPVER}/etc/php-fpm.conf + + # work around travis issue #3385 + if [ -d ~/.phpenv/versions/${PHPVER}/etc/php-fpm.d ]; then + if [ "$TRAVIS_PHP_VERSION" = "7.0" -a -n "$(ls -A ~/.phpenv/versions/${PHPVER}/etc/php-fpm.d)" ]; then + cp ~/.phpenv/versions/${PHPVER}/etc/php-fpm.d/www.conf.default ~/.phpenv/versions/${PHPVER}/etc/php-fpm.d/www.conf + fi + if [ "$TRAVIS_PHP_VERSION" = "7.1" -a -n "$(ls -A ~/.phpenv/versions/${PHPVER}/etc/php-fpm.d)" ]; then + cp ~/.phpenv/versions/${PHPVER}/etc/php-fpm.d/www.conf.default ~/.phpenv/versions/${PHPVER}/etc/php-fpm.d/www.conf + fi + if [ "$TRAVIS_PHP_VERSION" = "7.2" -a -n "$(ls -A ~/.phpenv/versions/${PHPVER}/etc/php-fpm.d)" ]; then + cp ~/.phpenv/versions/${PHPVER}/etc/php-fpm.d/www.conf.default ~/.phpenv/versions/${PHPVER}/etc/php-fpm.d/www.conf + fi + if [ "$TRAVIS_PHP_VERSION" = "7.3" -a -n "$(ls -A ~/.phpenv/versions/${PHPVER}/etc/php-fpm.d)" ]; then + cp ~/.phpenv/versions/${PHPVER}/etc/php-fpm.d/www.conf.default ~/.phpenv/versions/${PHPVER}/etc/php-fpm.d/www.conf + fi + fi + + ~/.phpenv/versions/${PHPVER}/sbin/php-fpm + + # @todo configure apache for php-fpm via mod_proxy_fcgi +fi diff --git a/tests/ci/setup/setup_privoxy.sh b/tests/ci/setup/setup_privoxy.sh new file mode 100644 index 00000000..a0477ddf --- /dev/null +++ b/tests/ci/setup/setup_privoxy.sh @@ -0,0 +1,12 @@ +#!/bin/sh + +set -e + +# install and configure privoxy + +SCRIPT_DIR="$(dirname "$(readlink -f "$0")")" + +DEBIAN_FRONTEND=noninteractive apt-get install -y privoxy + +cp -f "$SCRIPT_DIR/../config/privoxy" /etc/privoxy/config +service privoxy restart diff --git a/tests/ci/travis/apache_vhost b/tests/ci/travis/apache_vhost deleted file mode 100644 index 11304793..00000000 --- a/tests/ci/travis/apache_vhost +++ /dev/null @@ -1,84 +0,0 @@ -# Configuration file for Apache running on Travis. -# PHP setup in FCGI mode - - - - DocumentRoot %TRAVIS_BUILD_DIR% - - ErrorLog "%TRAVIS_BUILD_DIR%/apache_error.log" - CustomLog "%TRAVIS_BUILD_DIR%/apache_access.log" combined - - - Options FollowSymLinks MultiViews ExecCGI - AllowOverride All - - Require all granted - - # needed for basic auth (PHP_AUTH_USER and PHP_AUTH_PW) - RewriteEngine on - RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}] - RewriteRule .* - [E=REMOTE_USER:%{HTTP:Authorization}] - - - # Wire up Apache to use Travis CI's php-fpm. - - AddHandler php5-fcgi .php - Action php5-fcgi /php5-fcgi - Alias /php5-fcgi /usr/lib/cgi-bin/php5-fcgi - FastCgiExternalServer /usr/lib/cgi-bin/php5-fcgi -host 127.0.0.1:9000 -pass-header Authorization - - Require all granted - - - - - - - - - - DocumentRoot %TRAVIS_BUILD_DIR% - - ErrorLog "%TRAVIS_BUILD_DIR%/apache_error.log" - CustomLog "%TRAVIS_BUILD_DIR%/apache_access.log" combined - - - Options FollowSymLinks MultiViews ExecCGI - AllowOverride All - - Require all granted - - # needed for basic auth (PHP_AUTH_USER and PHP_AUTH_PW) - RewriteEngine on - RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}] - RewriteRule .* - [E=REMOTE_USER:%{HTTP:Authorization}] - - - # Wire up Apache to use Travis CI's php-fpm. - - AddHandler php5-fcgi .php - Action php5-fcgi /php5-fcgi - Alias /php5-fcgi /usr/lib/cgi-bin/php5-fcgi - #FastCgiExternalServer /usr/lib/cgi-bin/php5-fcgi -host 127.0.0.1:9000 -pass-header Authorization - - Require all granted - - - - SSLEngine on - # This cert is bundled by default in Ubuntu - SSLCertificateFile /etc/ssl/certs/ssl-cert-snakeoil.pem - SSLCertificateKeyFile /etc/ssl/private/ssl-cert-snakeoil.key - - - SSLOptions +StdEnvVars - - - BrowserMatch "MSIE [2-6]" \ - nokeepalive ssl-unclean-shutdown \ - downgrade-1.0 force-response-1.0 - BrowserMatch "MSIE [17-9]" ssl-unclean-shutdown - - - - diff --git a/tests/ci/travis/setup_apache.sh b/tests/ci/travis/setup_apache.sh deleted file mode 100755 index 81aaf669..00000000 --- a/tests/ci/travis/setup_apache.sh +++ /dev/null @@ -1,15 +0,0 @@ -#!/bin/sh - -# make sure all files and folders are accessible by Apache -sudo find /home -type d -exec chmod 755 {} \; -sudo find . -type f -name "*.php" -exec chmod 644 {} \; - -# set up Apache for php-fpm -# @see https://github.com/travis-ci/travis-ci.github.com/blob/master/docs/user/languages/php.md#apache--php - -sudo a2enmod rewrite actions fastcgi alias ssl - -# configure apache virtual hosts -sudo cp -f tests/ci/travis/apache_vhost /etc/apache2/sites-available/000-default.conf -sudo sed -e "s?%TRAVIS_BUILD_DIR%?$(pwd)?g" --in-place /etc/apache2/sites-available/000-default.conf -sudo service apache2 restart diff --git a/tests/ci/travis/setup_php_fpm.sh b/tests/ci/travis/setup_php_fpm.sh deleted file mode 100755 index 05098eaa..00000000 --- a/tests/ci/travis/setup_php_fpm.sh +++ /dev/null @@ -1,22 +0,0 @@ -#!/bin/sh - -# enable php-fpm -sudo cp ~/.phpenv/versions/$(phpenv version-name)/etc/php-fpm.conf.default ~/.phpenv/versions/$(phpenv version-name)/etc/php-fpm.conf -# work around travis issue #3385 -if [ "-d ~/.phpenv/versions/$(phpenv version-name)/etc/php-fpm.d" ]; then - if [ "$TRAVIS_PHP_VERSION" = "7.0" -a -n "$(ls -A ~/.phpenv/versions/$(phpenv version-name)/etc/php-fpm.d)" ]; then - sudo cp ~/.phpenv/versions/$(phpenv version-name)/etc/php-fpm.d/www.conf.default ~/.phpenv/versions/$(phpenv version-name)/etc/php-fpm.d/www.conf - fi - if [ "$TRAVIS_PHP_VERSION" = "7.1" -a -n "$(ls -A ~/.phpenv/versions/$(phpenv version-name)/etc/php-fpm.d)" ]; then - sudo cp ~/.phpenv/versions/$(phpenv version-name)/etc/php-fpm.d/www.conf.default ~/.phpenv/versions/$(phpenv version-name)/etc/php-fpm.d/www.conf - fi - if [ "$TRAVIS_PHP_VERSION" = "7.2" -a -n "$(ls -A ~/.phpenv/versions/$(phpenv version-name)/etc/php-fpm.d)" ]; then - sudo cp ~/.phpenv/versions/$(phpenv version-name)/etc/php-fpm.d/www.conf.default ~/.phpenv/versions/$(phpenv version-name)/etc/php-fpm.d/www.conf - fi - if [ "$TRAVIS_PHP_VERSION" = "7.3" -a -n "$(ls -A ~/.phpenv/versions/$(phpenv version-name)/etc/php-fpm.d)" ]; then - sudo cp ~/.phpenv/versions/$(phpenv version-name)/etc/php-fpm.d/www.conf.default ~/.phpenv/versions/$(phpenv version-name)/etc/php-fpm.d/www.conf - fi -fi -echo "cgi.fix_pathinfo = 1" >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini -echo "always_populate_raw_post_data = -1" >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini -~/.phpenv/versions/$(phpenv version-name)/sbin/php-fpm diff --git a/tests/ci/travis/setup_privoxy.sh b/tests/ci/travis/setup_privoxy.sh deleted file mode 100755 index 12e0e614..00000000 --- a/tests/ci/travis/setup_privoxy.sh +++ /dev/null @@ -1,6 +0,0 @@ -#!/bin/sh - -# configure privoxy - -sudo cp -f tests/ci/travis/privoxy /etc/privoxy/config -sudo service privoxy restart diff --git a/tests/ci/vm.sh b/tests/ci/vm.sh new file mode 100644 index 00000000..8344ac80 --- /dev/null +++ b/tests/ci/vm.sh @@ -0,0 +1,128 @@ +#!/bin/sh + +# @todo support getting the 2 vars as cli args as well as via env vars? + +set -e + +ACTION="${1}" + +# Valid values: 'default', 5.6, 7.0 .. 7.4, 8.0 +export PHP_VERSION=${PHP_VERSION:-default} +# Valid values: precise (12), trusty (14), xenial (16), bionic (18), focal (20) +# We default to the same version we use on Travis +export UBUNTU_VERSION=${UBUNTU_VERSION:-xenial} + +IMAGE_NAME=phpxmlrpc:${UBUNTU_VERSION}-${PHP_VERSION} +CONTAINER_NAME=phpxmlrpc_${UBUNTU_VERSION}_${PHP_VERSION} +ROOT_DIR="$(dirname -- "$(dirname -- "$(dirname -- "$(readlink -f "$0")")")")" + +cd "$(dirname -- "$(readlink -f "$0")")" + +help() { +printf "Usage: vm.sh [OPTIONS] ACTION [OPTARGS] + +Manages the Test Environment Docker Stack + +Commands: + build build or rebuild the containers and set up the test env + enter enter the test container + #exec \$cmd execute a single shell command in the test container + #runtests [\$suite] execute the test suite using the test container (or a single test scenario eg. Tests/1ParsingBugsTest.php) + start start the containers + #status + stop stop containers + +Options: + -h print help +" +} + +build() { + stop + docker build --build-arg PHP_VERSION --build-arg UBUNTU_VERSION -t "${IMAGE_NAME}" . + if docker inspect "${CONTAINER_NAME}" >/dev/null 2>/dev/null; then + docker rm "${CONTAINER_NAME}" + fi + docker run -d \ + -p 80:80 -p 443:443 -p 8080:8080 \ + --name "${CONTAINER_NAME}" \ + --env CONTAINER_USER_UID=$(id -u) --env CONTAINER_USER_GID=$(id -g) --env TESTS_ROOT_DIR=/home/test \ + --env LOCALSERVER=localhost \ + --env URI=/demo/server/server.php \ + --env HTTPSSERVER=localhost \ + --env HTTPSURI=/demo/server/server.php \ + --env PROXYSERVER=localhost:8080 \ + --env HTTPSVERIFYHOST=0 \ + --env HTTPSIGNOREPEER=1 \ + --env SSLVERSION=0 \ + --env DEBUG=0 \ + -v "${ROOT_DIR}":/home/test "${IMAGE_NAME}" +} + +start() { + if docker inspect "${CONTAINER_NAME}" >/dev/null 2>/dev/null; then + docker start "${CONTAINER_NAME}" + else + build + fi +} + +stop() { + if docker inspect "${CONTAINER_NAME}" >/dev/null 2>/dev/null; then + docker stop "${CONTAINER_NAME}" + fi +} + +case "${ACTION}" in + + build) + build + stop + ;; + + cleanup) + docker rm "${CONTAINER_NAME}" + docker rmi "${IMAGE_NAME}" + ;; + + enter | shell | cli) + docker exec -it "${CONTAINER_NAME}" su test + ;; + + #exec) + # ;; + + restart) + stop + start + ;; + + #runtests) + # ;; + + start) + start + ;; + + #status) + # : + # ;; + + stop) + stop + ;; + + ps) + docker ps --filter "name=${CONTAINER_NAME}" + ;; + + diff | inspect | kill | logs | pause | port | stats | top | unpause) + docker container "${ACTION}" "${CONTAINER_NAME}" + ;; + + *) + printf "\n\e[31mERROR:\e[0m unknown action '${ACTION}'\n\n" >&2 + help + exit 1 + ;; +esac -- 2.45.2