From 5b4cfefeaddc3bc5f577ceab93077641f474269f Mon Sep 17 00:00:00 2001 From: Ivan Kurnosov Date: Sun, 22 Jun 2014 00:39:02 +1200 Subject: [PATCH] Cleaned up before_script.sh so that it was possible to reuse it for Vagrant --- after_script.sh => .ci/after_script.sh | 0 .ci/before_script.sh | 8 ++++ .ci/common_env.sh | 6 +++ .ci/phpunit-environment.conf | 13 +++++++ .ci/setup.sh | 35 +++++++++++++++++ .ci/start.sh | 10 +++++ .ci/travis_env.sh | 3 ++ .ci/vagrant_env.sh | 3 ++ .ci/vagrant_pre_setup.sh | 12 ++++++ .gitignore | 1 + .travis.yml | 2 +- Vagrantfile | 22 +++++++++++ before_script.sh | 53 -------------------------- 13 files changed, 114 insertions(+), 54 deletions(-) rename after_script.sh => .ci/after_script.sh (100%) create mode 100755 .ci/before_script.sh create mode 100644 .ci/common_env.sh create mode 100644 .ci/phpunit-environment.conf create mode 100644 .ci/setup.sh create mode 100644 .ci/start.sh create mode 100644 .ci/travis_env.sh create mode 100644 .ci/vagrant_env.sh create mode 100644 .ci/vagrant_pre_setup.sh create mode 100644 Vagrantfile delete mode 100755 before_script.sh diff --git a/after_script.sh b/.ci/after_script.sh similarity index 100% rename from after_script.sh rename to .ci/after_script.sh diff --git a/.ci/before_script.sh b/.ci/before_script.sh new file mode 100755 index 00000000..f08e962d --- /dev/null +++ b/.ci/before_script.sh @@ -0,0 +1,8 @@ +BEFORE_SCRIPT_DIR=$(dirname $0) + +source $BEFORE_SCRIPT_DIR/common_env.sh +source $BEFORE_SCRIPT_DIR/travis_env.sh + +source $BEFORE_SCRIPT_DIR/setup.sh + +source $BEFORE_SCRIPT_DIR/start.sh diff --git a/.ci/common_env.sh b/.ci/common_env.sh new file mode 100644 index 00000000..61acbed6 --- /dev/null +++ b/.ci/common_env.sh @@ -0,0 +1,6 @@ +#!/bin/bash + +SELENIUM_HUB_URL='http://127.0.0.1:4444' +SELENIUM_JAR=/usr/share/selenium/selenium-server-standalone.jar +SELENIUM_DOWNLOAD_URL=http://selenium-release.storage.googleapis.com/2.42/selenium-server-standalone-2.42.1.jar +PHP_VERSION=$(php -v) diff --git a/.ci/phpunit-environment.conf b/.ci/phpunit-environment.conf new file mode 100644 index 00000000..0b09e4d4 --- /dev/null +++ b/.ci/phpunit-environment.conf @@ -0,0 +1,13 @@ +[program:selenium] +command=xvfb-run java -Dwebdriver.firefox.bin=/usr/bin/firefox -jar /usr/share/selenium/selenium-server-standalone.jar +autostart=false ; selenium + +[program:python-webserver] +command=python -m SimpleHTTPServer 8080 +directory=. ; python-webserver +autostart=false ; python-webserver + +[program:php-webserver] +command=php -S localhost:8080 +directory=. ; php-webserver +autostart=false ; php-webserver diff --git a/.ci/setup.sh b/.ci/setup.sh new file mode 100644 index 00000000..60561a21 --- /dev/null +++ b/.ci/setup.sh @@ -0,0 +1,35 @@ +#!/bin/bash + +if [ ! -f "/usr/local/bin/composer" ]; then + echo "Installing Composer" + php -r "readfile('https://getcomposer.org/installer');" | sudo php -d apc.enable_cli=0 -- --install-dir=/usr/local/bin --filename=composer +else + echo "Updating Composer" + sudo /usr/local/bin/composer self-update +fi + +if [ ! -d vendor ] || [ ! -f vendor/autoload.php ]; then + echo "Installing dependencies" + composer install --dev +fi + +echo "Installing supervisord" +sudo apt-get install supervisor -y --no-install-recommends +sudo cp ./.ci/phpunit-environment.conf /etc/supervisor/conf.d/ +sudo sed -i "s/^directory=.*webserver$/directory=${ESCAPED_BUILD_DIR}\\/selenium-1-tests/" /etc/supervisor/conf.d/phpunit-environment.conf +sudo sed -i "s/^autostart=.*selenium$/autostart=true/" /etc/supervisor/conf.d/phpunit-environment.conf + +if $(echo "$PHP_VERSION" | grep --quiet 'PHP 5.4'); then + sudo sed -i "s/^autostart=.*php-webserver$/autostart=true/" /etc/supervisor/conf.d/phpunit-environment.conf +else + sudo sed -i "s/^autostart=.*python-webserver$/autostart=true/" /etc/supervisor/conf.d/phpunit-environment.conf +fi + +echo "Installing Firefox" +sudo apt-get install firefox -y --no-install-recommends + +if [ ! -f "$SELENIUM_JAR" ]; then + echo "Downloading Selenium" + sudo mkdir -p $(dirname "$SELENIUM_JAR") + sudo wget -nv -O "$SELENIUM_JAR" "$SELENIUM_DOWNLOAD_URL" +fi diff --git a/.ci/start.sh b/.ci/start.sh new file mode 100644 index 00000000..df1ce8e7 --- /dev/null +++ b/.ci/start.sh @@ -0,0 +1,10 @@ +#!/bin/bash + +sudo supervisorctl reload + +wget --retry-connrefused --tries=60 --waitretry=1 --output-file=/dev/null "$SELENIUM_HUB_URL/wd/hub/status" -O /dev/null +if [ ! $? -eq 0 ]; then + echo "Selenium Server not started" +else + echo "Finished setup" +fi diff --git a/.ci/travis_env.sh b/.ci/travis_env.sh new file mode 100644 index 00000000..9aaf5f75 --- /dev/null +++ b/.ci/travis_env.sh @@ -0,0 +1,3 @@ +#!/bin/bash + +ESCAPED_BUILD_DIR=$(echo "$TRAVIS_BUILD_DIR" | sed 's/\//\\\//g') diff --git a/.ci/vagrant_env.sh b/.ci/vagrant_env.sh new file mode 100644 index 00000000..04eba2ad --- /dev/null +++ b/.ci/vagrant_env.sh @@ -0,0 +1,3 @@ +#!/bin/bash + +ESCAPED_BUILD_DIR="\/vagrant" diff --git a/.ci/vagrant_pre_setup.sh b/.ci/vagrant_pre_setup.sh new file mode 100644 index 00000000..fab88890 --- /dev/null +++ b/.ci/vagrant_pre_setup.sh @@ -0,0 +1,12 @@ +#!/bin/sh + +sed -i "/mirror:\\/\\//d" /etc/apt/sources.list +sed -i "1ideb mirror://mirrors.ubuntu.com/mirrors.txt precise main restricted universe multiverse" /etc/apt/sources.list +sed -i "1ideb mirror://mirrors.ubuntu.com/mirrors.txt precise-updates main restricted universe multiverse" /etc/apt/sources.list +sed -i "1ideb mirror://mirrors.ubuntu.com/mirrors.txt precise-backports main restricted universe multiverse" /etc/apt/sources.list +sed -i "1ideb mirror://mirrors.ubuntu.com/mirrors.txt precise-security main restricted universe multiverse" /etc/apt/sources.list + +apt-get update + +# installing xvfb, java and php +apt-get install xvfb openjdk-7-jre-headless php5-cli php5-curl php5-xdebug -y --no-install-recommends diff --git a/.gitignore b/.gitignore index 038c896c..0095262b 100644 --- a/.gitignore +++ b/.gitignore @@ -14,3 +14,4 @@ firefox/ /.project /.buildpath /.settings +/.vagrant/ diff --git a/.travis.yml b/.travis.yml index fccb1b94..19828b9b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,5 +2,5 @@ language: php php: - 5.3 - 5.4 -before_script: ./before_script.sh +before_script: ./.ci/before_script.sh script: "vendor/bin/phpunit --verbose --debug Tests" diff --git a/Vagrantfile b/Vagrantfile new file mode 100644 index 00000000..28966115 --- /dev/null +++ b/Vagrantfile @@ -0,0 +1,22 @@ +VAGRANTFILE_API_VERSION = "2" + +$setupEnvironment = <<-SCRIPT + +cd /vagrant + +source ./.ci/vagrant_pre_setup.sh + +source ./.ci/common_env.sh +source ./.ci/vagrant_env.sh + +source ./.ci/setup.sh + +source ./.ci/start.sh + +SCRIPT + +Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| + config.vm.box = "hashicorp/precise32" + + config.vm.provision "shell", inline: $setupEnvironment +end diff --git a/before_script.sh b/before_script.sh deleted file mode 100755 index bbab9973..00000000 --- a/before_script.sh +++ /dev/null @@ -1,53 +0,0 @@ -serverUrl='http://127.0.0.1:4444' -serverFile=selenium-server-standalone.jar -serverFileDownloadUrl=http://selenium-release.storage.googleapis.com/2.42/selenium-server-standalone-2.42.1.jar -firefoxUrl=http://ftp.mozilla.org/pub/mozilla.org/firefox/releases/29.0/linux-x86_64/en-US/firefox-29.0.tar.bz2 -firefoxFile=firefox.tar.bz2 -fixturePort=8080 -phpVersion=`php -v` - - -if [ ! -f composer.phar ]; then - echo "Getting composer" - curl -O http://getcomposer.org/composer.phar -else - php composer.phar self-update -fi - -echo "Dependencies" -if [ ! -d vendor ] || [ ! -f vendor/autoload.php ]; then - php composer.phar install --dev -else - php composer.phar update --dev -fi - -cd selenium-1-tests -if $(echo "$phpVersion" | grep --quiet 'PHP 5.4'); then - echo "Starting PHP 5.4 web server" - php -S localhost:$fixturePort > /tmp/server.log 2>&1 & -else - echo "Starting Python web server" - python -m SimpleHTTPServer $fixturePort > /tmp/server.log 2>&1 & -fi -cd .. - -echo "Downloading Firefox" -if [ ! -f $firefoxFile ]; then - wget $firefoxUrl -O $firefoxFile - tar xvjf $firefoxFile -fi -killall firefox - -echo "Starting xvfb" -echo "Starting Selenium" -if [ ! -f $serverFile ]; then - wget ${serverFileDownloadUrl} -O $serverFile -fi -xvfb-run java -Dwebdriver.firefox.bin=firefox/firefox-bin -jar $serverFile > /tmp/selenium.log 2>&1 & - -wget --retry-connrefused --tries=60 --waitretry=1 --output-file=/dev/null $serverUrl/wd/hub/status -O /dev/null -if [ ! $? -eq 0 ]; then - echo "Selenium Server not started" -else - echo "Finished setup" -fi