Skip to content

Commit

Permalink
Merge pull request ezsystems#20 from ezsystems/behat
Browse files Browse the repository at this point in the history
Add support for running Behat tests in containers
  • Loading branch information
vidarl committed Jan 9, 2015
2 parents 1874a77 + f589819 commit efd968f
Show file tree
Hide file tree
Showing 18 changed files with 720 additions and 16 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -16,4 +16,5 @@ dockerfiles/php-fpm/etcd_functions
dockerfiles/php-fpm/etcd_0.4.6_amd64.deb
dockerfiles/nginx/etcd_functions
dockerfiles/nginx/etcd_0.4.6_amd64.deb
dockerfiles/ezpublish/prepare/kickstart_template.ini

3 changes: 3 additions & 0 deletions dockerfiles/ezpublish/prepare/Dockerfile
Expand Up @@ -6,6 +6,9 @@ ADD run.sh /run.sh
ADD generate_kickstart_file.sh /generate_kickstart_file.sh
ADD install_packages.sh /install_packages.sh
ADD auth.json /auth.json
ADD setupwizard_ezstep_welcome.patch /setupwizard_ezstep_welcome.patch
ADD kickstart_template.ini /kickstart_template.ini

RUN chmod 755 /*.sh

CMD /run.sh
Expand Down
19 changes: 15 additions & 4 deletions dockerfiles/ezpublish/prepare/generate_kickstart_file.sh
@@ -1,14 +1,16 @@
#!/bin/bash

# Parameter $1 is value of EZ_KICKSTART_FROM_TEMPLATE ( could be empty )

if [ ! -f ezpublish_legacy/kickstart.ini-dist ]; then
echo "ERROR: Could not find ezpublish_legacy/kickstart.ini-dist, did you forget to place eZ Publish in vagrant/ezpublish folder?"
exit 1;
fi

if [ "aa$1" == "aa" ]; then
echo "Generating kickstart.ini"

echo "Generating kickstart.ini"

echo "[database_choice]
echo "[database_choice]
Continue=true
Type=mysqli
Expand All @@ -23,4 +25,13 @@ Socket=
[site_details]
Database=ezp
" > ezpublish_legacy/kickstart.ini
" > ezpublish_legacy/kickstart.ini
else
cp $1 ezpublish_legacy/kickstart.ini

sed -i "s@^Server=@Server=db@" ezpublish_legacy/kickstart.ini
sed -i "s@^Port=@Port=${DB_PORT_3306_TCP_PORT}@" ezpublish_legacy/kickstart.ini
sed -i "s@^Database=@Database=ezp@" ezpublish_legacy/kickstart.ini
sed -i "s@^User=@User=admin@" ezpublish_legacy/kickstart.ini
sed -i "s@^Password=@Password=${DB_ENV_MYSQL_PASS}@" ezpublish_legacy/kickstart.ini
fi
55 changes: 46 additions & 9 deletions dockerfiles/ezpublish/prepare/run.sh
Expand Up @@ -2,10 +2,14 @@

# Script accepts the following environment variable:
# - EZ_KICKSTART ( "true" or "false" )
# - EZ_KICKSTART_FROM_TEMPLATE ( template file )
# Note that the value of this setting passed on to this script is the filename outside the container. Inside the container, the actuall file will always be named /kickstart_template.ini
# Therefore, the value of this setting will be rewritten internally in the script
# - EZ_PACKAGEURL ( url, pointing to url where packages are located )
# - EZ_INSTALLTYPE ( "composer" )
# - EZ_COMPOSERVERSION ( What version of eZ Publish to install using composer )
# - EZ_COMPOSERREPOSITORYURL ( Url to composer repository which should be used )
# - EZ_PATCH_SW ( "true" or "false" ) : Whatever to patch setup wizard or not, so that the welcome page also can be kickstarted
#
# Parameters can also be given as options, in the same order:
# ./run.sh [ EZ_KICKSTART ] [ EZ_PACKAGEURL ] ....
Expand All @@ -18,17 +22,23 @@ function parseCommandlineOptions
EZ_KICKSTART=$1
fi
if [ "aa$2" != "aa" ]; then
EZ_PACKAGEURL=$2
export EZ_PACKAGEURL
EZ_KICKSTART_FROM_TEMPLATE=$2
fi
if [ "aa$3" != "aa" ]; then
EZ_INSTALLTYPE=$3
EZ_PACKAGEURL=$3
export EZ_PACKAGEURL
fi
if [ "aa$4" != "aa" ]; then
EZ_COMPOSERVERSION=$4
EZ_INSTALLTYPE=$4
fi
if [ "aa$5" != "aa" ]; then
EZ_COMPOSERREPOSITORYURL=$5
EZ_COMPOSERVERSION=$5
fi
if [ "aa$6" != "aa" ]; then
EZ_COMPOSERREPOSITORYURL=$6
fi
if [ "aa$7" != "aa" ]; then
EZ_PATCH_SW=$7
fi


Expand All @@ -48,6 +58,20 @@ function validateDocRootIsEmpty
fi
}


function patchSetupWizard
{
local pwd
pwd=`pwd`
echo patch setup wizard ? : $EZ_PATCH_SW
if [ "aa$EZ_PATCH_SW" == "aatrue" ]; then
cd /var/www
echo patching ....
patch -p0 < /setupwizard_ezstep_welcome.patch
cd - > /dev/null
fi
}

function installViaComposer
{
validateDocRootIsEmpty
Expand Down Expand Up @@ -79,6 +103,8 @@ function installViaComposer

mv ezp/* /var/www

patchSetupWizard

cd ..
rm -Rf $tmpDir

Expand All @@ -102,6 +128,8 @@ function installTarball

mv ezpublish5/* /var/www

patchSetupWizard

cd /var/www
# php ezpublish/console assets:install --relative --symlink web
# php ezpublish/console ezpublish:legacy:assets_install --relative --symlink web
Expand All @@ -110,6 +138,12 @@ function installTarball

function processCommandLineOptions
{
# Fix value of KICKSTART_FROM_TEMPLATE
if [ "aa$EZ_KICKSTART_FROM_TEMPLATE" != "aa" ]; then
EZ_KICKSTART_FROM_TEMPLATE="/kickstart_template.ini"
fi


if [ $EZ_INSTALLTYPE == "composer" ]; then
installViaComposer
fi
Expand Down Expand Up @@ -156,7 +190,7 @@ cd /var/www/

# Prepare for setup wizard if requested
if [ "$EZ_KICKSTART" = "true" ]; then
/generate_kickstart_file.sh
/generate_kickstart_file.sh $EZ_KICKSTART_FROM_TEMPLATE
fi

# Dowload packages if requested
Expand All @@ -173,9 +207,12 @@ sudo setfacl -dR -m u:$APACHE_RUN_USER:rwx -m u:`whoami`:rwx \


echo "Re-generate symlink assets in case rsync was used so asstets added during setup wizards are reachable"
# php ezpublish/console assetic:dump --env dev
php ezpublish/console assets:install --symlink --relative --env dev
php ezpublish/console ezpublish:legacy:assets_install --symlink --relative --env dev
if [ aa$EZ_ENVIRONMENT != "prod" ]; then
php ezpublish/console assetic:dump --env $EZ_ENVIRONMENT
fi

php ezpublish/console assets:install --symlink --relative --env $EZ_ENVIRONMENT
php ezpublish/console ezpublish:legacy:assets_install --symlink --relative --env $EZ_ENVIRONMENT


# Create ezp database if we intend to run setup wizard (need to be run last to make sure db is up)
Expand Down
14 changes: 14 additions & 0 deletions dockerfiles/ezpublish/prepare/setupwizard_ezstep_welcome.patch
@@ -0,0 +1,14 @@
--- ezpublish_legacy/kernel/setup/steps/ezstep_welcome.php.org 2014-09-05 11:06:31.718258749 +0000
+++ ezpublish_legacy/kernel/setup/steps/ezstep_welcome.php 2014-09-05 11:07:45.724225972 +0000
@@ -64,6 +64,11 @@
$this->PersistenceList['tests_run'] = $testsRun;
$this->PersistenceList['optional_tests_run'] = $testsRun;

+ if ( $this->hasKickstartData() )
+ {
+ return $this->kickstartContinueNextStep();
+ }
+
return false; // Always show welcome message
}

3 changes: 3 additions & 0 deletions dockerfiles/nginx/run.sh
Expand Up @@ -30,6 +30,9 @@ ln -s -f /etc/nginx/sites-available/ezpublish /etc/nginx/sites-enabled/ezpublish
sed -i "s@ fastcgi_pass unix:/var/run/php5-fpm.sock;@ # fastcgi_pass unix:/var/run/php5-fpm.sock;@" /etc/nginx/sites-available/ezpublish
sed -i "s@ #fastcgi_pass 127.0.0.1:9000;@ fastcgi_pass php_fpm:${PHP_FPM_PORT_9000_TCP_PORT};@" /etc/nginx/sites-available/ezpublish

# Setting environment for ezpublish ( dev/prod/behat etc )
sed -i "s@ #fastcgi_param ENVIRONMENT dev;@ fastcgi_param ENVIRONMENT ${EZ_ENVIRONMENT};@" /etc/nginx/sites-available/ezpublish

# Update port number and basedir in site-available/ezpublish
sed -i "s@%PORT%@${PORT}@" /etc/nginx/sites-available/ezpublish
sed -i "s@%BASEDIR%@${BASEDIR}@" /etc/nginx/sites-available/ezpublish
Expand Down
28 changes: 28 additions & 0 deletions dockerfiles/sahi/Dockerfile
@@ -0,0 +1,28 @@
FROM ezpublishdocker_sahibase

RUN apt-get install -y \
firefox


#wget -nv -O sahi_20130429.zip "http://downloads.sourceforge.net/project/sahi/sahi-v44/sahi_20130429.zip?r=http%3A%2F%2Fsourceforge.net%2Fprojects%2Fsahi%2Ffiles%2Fsahi-v44%2F&ts=1376728867&use_mirror=garr"
ADD sahi_20130429.zip /tmp/sahi.zip

# Travis tests uses this one : https://github.com/ezsystems/ezpublish-community/blob/master/bin/.travis/sahi/browser_types.xml-dist
# However, we'll use the default one for now....
#ADD browser_types.xml-dist /tmp/browser_types.xml-dist

RUN adduser sahi

RUN unzip /tmp/sahi.zip
RUN chmod +x /sahi/bin/sahi.sh /sahi/bin/dashboard.sh
RUN chown sahi:sahi -R /sahi
#RUN cp /tmp/browser_types.xml-dist /sahi/userdata/config/browser_types.xml

ADD run.sh /run.sh

ADD x_session.sh /x_session.sh

USER sahi
CMD ["/run.sh"]

EXPOSE 9999 5900
10 changes: 10 additions & 0 deletions dockerfiles/sahi/base/Dockerfile
@@ -0,0 +1,10 @@
FROM ezpublishdocker_ubuntu

RUN apt-get install -y \
xvfb \
xterm \
x11vnc \
default-jre \
mwm \
unzip

6 changes: 6 additions & 0 deletions dockerfiles/sahi/run.sh
@@ -0,0 +1,6 @@
#!/bin/bash

xvfb-run -n 99 -f /home/sahi/.Xauthority --server-args="-screen 0, 1024x768x24" /x_session.sh &
x11vnc -auth /home/sahi/.Xauthority -display :99 &

while [ 1 ]; do echo -n .; sleep 2; done
Binary file added dockerfiles/sahi/sahi_20130429.zip
Binary file not shown.
8 changes: 8 additions & 0 deletions dockerfiles/sahi/x_session.sh
@@ -0,0 +1,8 @@
#!/bin/bash


mwm &
cd /sahi/bin/; xterm -e /sahi/bin/sahi.sh &
cd /
xterm

10 changes: 8 additions & 2 deletions fig.sh
Expand Up @@ -23,6 +23,12 @@ if [ aa$FIX_EXECUTION_PATH == "aa" ]; then
fi
fi

# Copy kickstart template to build dir
if [ "aa$EZ_KICKSTART_FROM_TEMPLATE" != "aa" ]; then
cp files/$EZ_KICKSTART_FROM_TEMPLATE dockerfiles/ezpublish/prepare/kickstart_template.ini
else
echo "" > dockerfiles/ezpublish/prepare/kickstart_template.ini
fi

# Make a argumentlist where any "-d" is removed
for i in "$@"; do
Expand All @@ -49,8 +55,8 @@ fi
${FIX_EXECUTION_PATH}fig "$@"

echo "Waiting for prepare container to complete"
continue=1; while [ $continue -eq 1 ]; do docker ps -a|grep "ezpublishdocker_prepare:latest"|grep Exited > /dev/null; continue=$?; echo -n "."; sleep 3; done;
continue=1; while [ $continue -eq 1 ]; do docker ps -a|grep "${FIG_PROJECT_NAME}_prepare:latest"|grep Exited > /dev/null; continue=$?; echo -n "."; sleep 3; done;

echo "Last output from prepare container:"
echo "###################################"
docker logs -t ezpublishdocker_prepare_1|tail -n 15
docker logs -t ${FIG_PROJECT_NAME}_prepare_1|tail -n 15
21 changes: 21 additions & 0 deletions fig.yml
Expand Up @@ -44,10 +44,13 @@ prepare:
- ${EZ_TARBALL_FILENAME}:/tmp/ezpublish.tar.gz
environment:
- EZ_KICKSTART
- EZ_KICKSTART_FROM_TEMPLATE
- EZ_PACKAGEURL
- EZ_INSTALLTYPE
- EZ_COMPOSERVERSION
- EZ_COMPOSERREPOSITORYURL
- EZ_ENVIRONMENT
- EZ_PATCH_SW
phpfpm:
build: dockerfiles/php-fpm
links:
Expand All @@ -72,3 +75,21 @@ nginx:
- "8080:80"
environment:
- ETCD_ENABLED
- EZ_ENVIRONMENT
sahibase:
build: dockerfiles/sahi/base
sahi:
build: dockerfiles/sahi
links:
- nginx:web
ports:
- "9999:9999"
- "5900:5900"
behatphpcli:
build: dockerfiles/php-cli
links:
- db1:db
- nginx:web
- sahi:sahi
volumes_from:
- ezpublishvol
14 changes: 13 additions & 1 deletion files/fig.config-EXAMPLE
Expand Up @@ -30,6 +30,12 @@ MYSQL_PASS=youmaychangethis
# Generates kickstart.ini file with database settings if true
EZ_KICKSTART=true

# Name of template file to use for generating a kickstart file
# If value of setting is empty, a default kickstart file will be generated where db settings are stored ( given that EZ_KICKSTART=true )
# The template must contain "Server=", "Port=", "Database=", "User=" and "Password=" so that the values for these settings can be injected
# Template file should be located in the files/ directory
EZ_KICKSTART_FROM_TEMPLATE=

# Pre downloads packages from provided url if set for setup wizard speed up
# EZ_PACKAGEURL=http://packages.ez.no/ezpublish/5.4/5.4.0/
EZ_PACKAGEURL=
Expand Down Expand Up @@ -59,12 +65,18 @@ EZ_COMPOSERREPOSITORYURL=
# Path cannot escape the project root ( ie do not do "../ezpublish5-5.3.0-ee-ttl-full.tar.gz"
EZ_TARBALL_FILENAME=ezpublish5-5.3.0-ee-ttl-full.tar.gz

# Set the environment for ezpublish. Valid options are "prod", "dev", "behat"
EZ_ENVIRONMENT=prod

# Whatever to patch setup wizard so that the welcome page also can be kickstarted
EZ_PATCH_SW=false

#### FIG settings ####
# Path to location of fig. If fig is in your PATH, you may leave it empty
export FIX_EXECUTION_PATH=""


export ETCD_ENABLED START_ETCD ETCD_DISCOVERY ETCD_NAME
export MYSQL_PASS
export EZ_KICKSTART EZ_PACKAGEURL EZ_INSTALLTYPE EZ_COMPOSERVERSION EZ_COMPOSERREPOSITORYURL EZ_TARBALL_FILENAME
export EZ_KICKSTART EZ_KICKSTART_FROM_TEMPLATE EZ_PACKAGEURL EZ_INSTALLTYPE EZ_COMPOSERVERSION EZ_COMPOSERREPOSITORYURL EZ_TARBALL_FILENAME EZ_ENVIRONMENT EZ_PATCH_SW
export FIX_EXECUTION_PATH

0 comments on commit efd968f

Please sign in to comment.