Commit 9010f434 authored by Ernesto Rodriguez Ortiz's avatar Ernesto Rodriguez Ortiz
Browse files

docker: Add the right drush aliases file, more options to jenkins script and...

docker: Add the right drush aliases file, more options to jenkins script and more needed variables to defaul-vars
parent 51149a98
<?php
/**
* Drush aliases definition.
*/
$aliases['local'] = array(
'root' => '/var/www/src/drupal',
'uri' => 'http://localhost',
'path-aliases' => array(
'%files' => 'sites/default/files',
),
);
......@@ -38,6 +38,12 @@ SITE_NAME="Drupal app"
SITE_ADMIN_NAME="admin"
SITE_ADMIN_PASS="admin"
################################
# Drupal site modes #
################################
MAINTENANCE_MODE=1
ONLINE_MODE=0
################################
# Drupal default environment #
################################
......@@ -69,6 +75,9 @@ DRUSH_ALIASES=$DRUPAL_ROOT/sites/all/drush
################################
ME=`whoami`
################################
# Echo script location #
################################
ECHO=/bin/echo
#!/bin/bash
set -e
# call default vars
# Call default vars where are defined all global variables
source "deploy/default-vars"
# Check this for long args example https://gist.github.com/cosimo/3760587
# Get params from build
TAG=$1
# Do not edit after
# Local variables used only in this script for the executions of differents task
EN_INSTALL=0
EN_DEPLOY=0
EN_BUILD=0
EN_SQLSYNC=0
EN_CODER=0
EN_PHPCPD=0
EN_PHPMD=0
......@@ -18,8 +20,29 @@ EN_BEHAT=0
EN_AUDIT=0
E_OPTERR=65
# Define DRUPAL_ENV using the value of the global variable SITE_ENVIRONMENT
DRUPAL_ENV=$SITE_ENVIRONMENT
# Display the usage of this script, diferentes options and examples
function display_usage {
echo "Usage :
echo "Usage :
-i, --install
Install drupal site using site-install script
-d, --deploy
Deploy files to an environment defined in defaul-vars file
-b, --build
Build and backup of files and database in /build
-s, --sqlsync
Sync database from live to staging
-a, --audit
Full report using site_audit drush module
Report type : HTML page
file -> output/site_audit.html
-c, --coder
Checkstyle of custom modules
Report type : Checkstyle results
......@@ -55,7 +78,20 @@ function display_usage {
"
}
function drupal_install {
# Put the site offline
function site_offline {
$ECHO "Setting $DRUPAL_ENV environment on maintenance mode ..."
drush --yes @$DRUPAL_ENV vset site_offline $MAINTENANCE_MODE
}
# Put the site online
function site_online {
$ECHO "Setting $DRUPAL_ENV environment off maintenance mode ..."
drush --yes @$DRUPAL_ENV vset site_offline $ONLINE_MODE
}
# Install the site using the site-install script to reuse code
function site_install {
# start apache
service apache2 start
# start mysql server
......@@ -68,7 +104,7 @@ function drupal_install {
fi
# Setup signal handler so DB are always deleted
trap script_end 0
trap site_install_end 0
trap "exit 2" 1 2 3 13 15
cd $DRUPAL_ROOT
if ! drush status
......@@ -79,11 +115,43 @@ function drupal_install {
drush rf
}
function script_end {
# End function of the script
function site_install_end {
# Drop this build database
echo "Nothing to do here."
}
# Deploy code on specified environment with rsync
# Param should be a drush valid alias for the current drupal installation
# cf aliases.drushrc.php
function site_deploy {
# Put site on maintenance mode
site_offline
# Copy env settings
$ECHO "Preparing environment-specific configuration ..."
sudo cp $WORKSPACE/deploy/env/settings.${DRUPAL_ENV}.php $DRUPAL_ROOT/sites/default/
$ECHO "Deploying code on $DRUPAL_ENV environment ..."
drush --yes rsync --exclude=sites/default/files --exclude=external --exclude=.htaccess --delete --verbose @self @$DRUPAL_ENV
if [ $DRUPAL_ENV != prod ]; then
if [ "${sqlreplace}" == true ]; then
$ECHO "Synchronising SQL database from self to $DRUPAL_ENV"
drush --yes sql-sync --create-db @self @$DRUPAL_ENV
fi
fi
# Run any available database update
$ECHO "Running available database update(s) on $DRUPAL_ENV environment ..."
drush --yes @$DRUPAL_ENV updatedb
# Put site online
site_online
}
# Set right permissions to drupal files after installation and tests
# Create the output directory for the tests results
function fix_permissions {
# Permissions
#chown -R jenkins:www-data $DRUPAL_ROOT/sites/default
......@@ -95,7 +163,7 @@ function fix_permissions {
fi
}
# Test to check drupal coding standards and other best practices
function run_coder {
echo "run_coder START"
......@@ -114,6 +182,7 @@ function run_coder {
fi
}
# Test to check duplicate code, a copy/paste detector
function run_phpcpd {
echo "run_phpcpd START"
......@@ -126,6 +195,7 @@ function run_phpcpd {
fi
}
# Test to check php code and look for several potencial problems: bugs, unusedcode, etc.
function run_phpmd {
echo "run_phpmd START"
......@@ -138,6 +208,7 @@ function run_phpmd {
fi
}
# Test of Drupal core
function run_tests {
echo "run_tests START"
......@@ -148,6 +219,7 @@ function run_tests {
php scripts/run-tests.sh --php /usr/bin/php --color --url http://localhost --verbose --xml ${WORKSPACE}/logs/tests System
}
# Test scenarios specific to Drupal sites using behat drupalextension
function run_behat {
echo "run_behat START"
mkdir -p ${WORKSPACE}/logs/behat
......@@ -157,6 +229,7 @@ function run_behat {
./behat --ansi --format junit,pretty --out ${WORKSPACE}/logs/behat,
}
# Generate a report of the site using site_audit
function site_audit {
cd $DRUPAL_ROOT
echo "site_audit"
......@@ -164,7 +237,32 @@ function site_audit {
drush aa --html --bootstrap --detail --skip=insights > $WORKSPACE/output/site_audit.html
}
function run_all_tests {
# Export code and database. This is a test for Pantheon
function build_artefacts {
# Specify the destination folder
TARGET=$WORKSPACE/build
# Specify the source folder
SOURCE=$WORKSPACE/src
# Change directory to the source folder
cd $SOURCE
# Create an archive that excludes sites/default/files
drush archive-dump --tar-options="--exclude=.git" --destination=$TARGET/sfl_boilerplate-archive.tar.gz --overwrite
# Create a compressed database backup
drush sql-dump | gzip -9 > $TARGET/db.sql.gz
}
# Main function that control the execution of the script
function run {
if [ $EN_INSTALL -eq 1 ]; then
site_install
fix_permissions
else
if ! drush @${DRUPAL_ENV} status; then
$ECHO "Failed to get ${DRUPAL_ENV} status" >&2
exit 1
fi
fi
if [ $EN_CODER -eq 1 ]; then
run_coder
fi
......@@ -182,30 +280,33 @@ function run_all_tests {
fi
if [ $EN_AUDIT -eq 1 ]; then
site_audit
# fix drupal permissions after site_audit because it create a ctools folder inside default/files but with the wrong rights
fix_permissions
fi
if [ $EN_DEPLOY -eq 1 ]; then
if [ $DRUPAL_ENV=prod && "${branch}" != 'prod' ]; then
$ECHO "Only \'prod\' branch is deployable in production" >&2
exit 1
fi
site_deploy
fi
if [ $EN_SQLSYNC -eq 1 ]; then
if [ $DRUPAL_ENV=staging ]; then
$ECHO "Sync \'staging\' environment" >&2
drush --yes sql-sync @self @test
else
$ECHO "Only \'staging\' environment can be sync" >&2
fi
fi
}
function build_artefacts {
# Export code and database. This is a test for Pantheon
# Creating a code archive
# Specify the destination folder
TARGET=$WORKSPACE/build
# Specify the source folder
SOURCE=$WORKSPACE/src
# Change directory to the source folder
cd $SOURCE
# Create an archive that excludes sites/default/files
drush archive-dump --tar-options="--exclude=.git" --destination=$TARGET/sfl_boilerplate-archive.tar.gz --overwrite
# Create a compressed database backup
drush sql-dump | gzip -9 > $TARGET/db.sql.gz
}
# Start point of execution
# Check the options passed to the script, print the usage if non options is passed
if [ -z "$*" ]; then
display_usage
# exit $E_OPTERR
exit $E_OPTERR
else
OPTS=`getopt -o cdmtbal --long coder,phpcpd,phpmd,tests,behat,audit,legacy -- "$@"`
OPTS=`getopt -o idbscpmtbal --long install,deploy,build,sqlsync,coder,phpcpd,phpmd,tests,behat,audit,legacy -- "$@"`
if [ $? != 0 ] ; then
echo "Failed parsing options."
display_usage
......@@ -214,10 +315,16 @@ else
eval set -- "$OPTS"
fi
# Set to TRUE the local variables if the right option was passed
# This local variables are used in the function run() to execute differents tasks
while true; do
case "$1" in
-i | --install ) EN_INSTALL=1; shift ;;
-d | --deploy ) EN_DEPLOY=1; shift ;;
-b | --build ) EN_BUILD=1; shift ;;
-s | --sqlsync ) EN_SQLSYNC=1; shift ;;
-c | --coder ) EN_CODER=1; shift ;;
-d | --phpcpd ) EN_PHPCPD=1; shift ;;
-p | --phpcpd ) EN_PHPCPD=1; shift ;;
-m | --phpmd ) EN_PHPMD=1; shift ;;
-t | --tests ) EN_TESTS=1; shift ;;
-b | --behat ) EN_BEHAT=1; shift ;;
......@@ -228,9 +335,16 @@ while true; do
esac
done
drupal_install
run_all_tests
fix_permissions
# Check that drush is installed
if ! type drush
then
$ECHO 'You must install drush to install and deploy' >&2
exit 1
fi
# Execute the tasks
run
# SUCCESS if we are here
#exit 0
# Clear all cache
$ECHO "Clearing cache on $DRUPAL_ENV environment ..."
cd $DRUPAL_ROOT && drush --yes @$DRUPAL_ENV cache-clear all
......@@ -40,8 +40,7 @@ sudo -u $APACHE drush si sflinux --locale="fr" --db-url=mysql://$DB_USER:$DB_PAS
# Copy drush aliases
mkdir $DRUSH_ALIASES
cd $DRUSH_ALIASES
ln -s $WORKSPACE/deploy/example.drushrc.aliases.php .
cp $WORKSPACE/deploy/aliases.drushrc.php $DRUSH_ALIASES/aliases.drushrc.php
echo "Copy drush aliases in "$DRUSH_ALIASES
# Copy environment settings and call it in settings.php
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment