Commit 64fbd415 authored by Ernesto Rodriguez Ortiz's avatar Ernesto Rodriguez Ortiz
Browse files

Update this docker version to integrate fabric task

parent d116dd7e
# Ignore source directory
src
src/drupal
/nbproject
.idea
[submodule "drupy"]
path = drupy
url = git@gitlab.savoirfairelinux.com:erortiz/drupy.git
......@@ -4,23 +4,16 @@ FROM sflinux/baseimage
MAINTAINER Ernesto Rodriguez Ortiz <ernesto.rodriguezortiz@savoirfairelinuc.com>
# Create project root directory and copy the structure
RUN mkdir /var/www/src && mkdir /var/www/output && mkdir /var/www/src/drupal
COPY build /var/www/build
COPY deploy /var/www/deploy
COPY doc /var/www/doc
COPY test /var/www/test
COPY site-install /var/www/site-install
RUN mkdir /opt/sfl-boilerplate
COPY . /opt/sfl-boilerplate
# Setup ssh keys to clone git repo
RUN mv /var/www/deploy/id_rsa* /root/.ssh/
RUN mv /opt/sfl-boilerplate/deploy/id_rsa* /root/.ssh/
RUN cat /root/.ssh/id_rsa.pub >> /root/.ssh/authorized_keys
RUN chmod 600 /root/.ssh/id_rsa*
RUN exec ssh-agent /bin/bash && ssh-add /root/.ssh/id_rsa
RUN ssh-keyscan gitlab.savoirfairelinux.com >> /root/.ssh/known_hosts
#Copy vhost configuration and enable modules
RUN cp /var/www/deploy/vhost.conf /etc/apache2/sites-available/000-default.conf
RUN a2enmod rewrite vhost_alias
# Installer Drupal et ruler des tests
RUN cd /var/www/ && /bin/bash deploy/jenkins-post-build.sh -ia
RUN cp /opt/sfl-boilerplate/deploy/vhost.conf /etc/apache2/sites-available/000-default.conf
RUN a2enmod rewrite vhost_alias
\ No newline at end of file
# Installation
## Création d'une nouvelle instance
Le script site-install va créer un nouveau site dans le répertoire src/drupal.
<code>
./site-install
</code>
### Restore the latest database dump
<code>
cd src/drupal
zcat ../../build/sfl_boilerplate_dbdump_latest.sql.gz | mysql -u <user> -p <dbname>
</code>
## Mise à jour d'un site existant
<code>
cd src/drupal
drush make --no-core ../../build/sfl_boilerplate .
drush updatedb
</code>
Copy patches that can be applied in the site.
Patches that must be applied should be specified in the Makefile.
core = 7.x
projects[] = drupal
api = 2
; SFLinux installation profile
projects[sflinux][type] = profile
projects[sflinux][download][type] = git
projects[sflinux][download][url] = git@gitlab.savoirfairelinux.com:drupal/sflinux.git
projects[sflinux][download][branch] = 7.x
<?php
/**
* Drush aliases definition.
*/
$aliases['local'] = array(
'root' => '/var/www/src/drupal',
'uri' => 'http://localhost',
'path-aliases' => array(
'%files' => 'sites/default/files',
),
);
#!/bin/bash
# default-vars
#
# This file contains vars definitions that are used by site-install and jenkins-post-build.sh
#
################################
# Apache user #
################################
APACHE=www-data
################################
# Apache workspace #
################################
WORKSPACE=/var/www
################################
# Password for MySQL root user #
################################
MYSQL_PASS="mysqlrootpass"
################################
# Informations for MySQL user #
# & website database #
################################
DB_USER=drupal_user
DB_PASS=drupal_pass
DB_NAME=drupal_database
################################
# Drupal site name #
################################
SITE_NAME="Drupal app"
################################
# Drupal administrator account #
################################
SITE_ADMIN_NAME="admin"
SITE_ADMIN_PASS="admin"
################################
# Drupal site modes #
################################
MAINTENANCE_MODE=1
ONLINE_MODE=0
################################
# Drupal default environment #
################################
SITE_ENVIRONMENT=local
################################
# Drupal root directory #
################################
DRUPAL_ROOT=$WORKSPACE/src/drupal
################################
# Drupal customs modules #
# directory #
################################
CUSTOMDIR=$DRUPAL_ROOT/sites/all/modules/custom
################################
# Drush script location #
################################
DRUSH=`which drush`
################################
# Drush aliases location #
################################
DRUSH_ALIASES=$DRUPAL_ROOT/sites/all/drush
################################
# User that execute the script #
################################
ME=`whoami`
......@@ -16,3 +16,4 @@ $aliases['staging'] = array(
'%files' => 'sites/default/files',
),
);
-----BEGIN RSA PRIVATE KEY-----
MIIEpAIBAAKCAQEAv+GJkEcFdvgcXljWpuuFbkm15D1i50nB9eHP7OIZWf3jBs7a
W6dTUWn68kMVDUBEZeIUuaMXV5cc5Ng084tUzY3o7fqAAUJ8YfXcnLewfOMlMfel
LTOB/FCG6t/DfzN8ZD3ogfIVmh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bVz
gEIgPMpHm3TgWBOoyAGsm1xFAoGARNes2/tyT0FZWs1iAuucFPqEOC2Dgw75aMHU
0rfEXsoE2Cy7cWzKhGtLM6z6hDI9eU8qnijyPYdP8nnXEBIUQrC7nFUv52sxYKNG
T/8wwKwVN8RszVgtjbSOLKfc3Aa9QErv/aa7ypIJIj46IdQ087msMaBWuX6Bx/5u
+nWxt9UCgYB6mRoDBvcYPfFdguf/4hKB5S89SXjWD/ki1sQnjbhCExiW7N50VZRp
hox3kC3dexPM4nu3vwxdDOI123MPIUhr66CWpTxldsA1bXDqTLRtsYKOQwQTn+b8
9b3TLV7Vhzqq7I4hZ0lPcw+1neRj+AoPbWL2VNx/jCkLa8OoVDrSxQ==
-----END RSA PRIVATE KEY-----
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC/4YmQRwV2+BxeWNam64VuSbXkPWLnScH14c/s4hlZ/eMGztpbp1NRafryQxUNQERl4hS5oxdXlxzk2DTzi1TNjejt+oABQnxh9dyct7B84yUx96UtM4H8UIbq38N/M3xkPeiB8hWaG+OlWOhsZOps4fFQzneRth1K5M6qOGNdWZw+TKY05Rn16/6c4yQps6MjEGUvsQb1Z1C54y3iqDgGu8k78umtrytMlcftB5ggiTlUSWpzbCJq37Qdp8XY8+00VZkRnEYgzN+WGds5NxTWzel7mj8/HTJVwjo44BQVz1DWiAdllEBeqbdL2ZNHCMC1JPtxDBAVtrK1fyK+Bpqv root@xorez-workpc
#!/bin/bash
set -e
# Call default vars where are defined all global variables
source "deploy/default-vars"
# Get params from build
TAG=$1
# 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
EN_TESTS=0
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 :
-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
files -> logs/coder-*.xml
-d, --phpcpd
Copy paste detector of custom modules
Report type : PMD results
file -> logs/phpmd-drupal.xml
-m, --phpmd
Check Duplicate code of custom modules
Report type : Duplicate code results
file -> logs/phpcpd-drupal.xml
-t, --tests
Run Simple test
Report type : XML report Junits
files -> logs/tests/*.xml
-b, --behat
Run behat unitary tests
Report type : XML report Junits
files -> logs/behat/*.xml
-l, --legacy
Enable Legacy drupal Organisation Folders
Example :
./jenkins.sh -c -d -m -t -b
./jenkins.sh -cdmtb
./jenkins.sh --coder --phpcpd --phpmd --tests --behat
"
}
# 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 {
echo "site_install"
# start apache
service apache2 start
# start mysql server
/usr/bin/mysqld_safe & sleep 10s
# execute site-install
if ! $WORKSPACE/site-install
then
echo "Fail to site install"
exit 1
fi
# Setup signal handler so DB are always deleted
trap site_install_end 0
trap "exit 2" 1 2 3 13 15
cd $DRUPAL_ROOT
if ! drush status
then
echo "Failed to get status"
exit 1
fi
drush rf
}
# 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 {
echo "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
chown -R www-data:www-data $DRUPAL_ROOT/sites/default
# Directory for tests output
if [ ! -d "$WORKSPACE/output" ]; then
mkdir $WORKSPACE/output
fi
}
# Test to check drupal coding standards and other best practices
function run_coder {
echo "run_coder START"
if [ -d "$CUSTOMDIR" ]; then
mkdir -p ${WORKSPACE}/logs/coder
cd $DRUPAL_ROOT
drush dl coder --yes
drush en coder coder_review --yes
MODULES=$(ls -d $CUSTOMDIR)
#Run coder against our modules
for MOD in $MODULES; do
drush coder-review --checkstyle --major --severity --comment --druplart --security --sql --sniffer --style $MOD > ${WORKSPACE}/logs/coder/coder-$MOD.xml 2> /dev/null
done
else
echo "Nothing for coder in $CUSTOMDIR"
fi
}
# Test to check duplicate code, a copy/paste detector
function run_phpcpd {
echo "run_phpcpd START"
if [ -d "$CUSTOMDIR" ]; then
mkdir -p ${WORKSPACE}/logs/phpcpd
# Run Copy/Paste detector
phpcpd --log-pmd ${WORKSPACE}/logs/phpcpd/phpcpd-drupal.xml $CUSTOMDIR
else
echo "Nothing for phpcpd in $CUSTOMDIR"
fi
}
# Test to check php code and look for several potencial problems: bugs, unusedcode, etc.
function run_phpmd {
echo "run_phpmd START"
if [ -d "$CUSTOMDIR" ]; then
mkdir -p ${WORKSPACE}/logs/phpmd
# Run PHP MEss Detector on our custom modules
phpmd $CUSTOMDIR xml codesize,unusedcode,naming --reportfile ${WORKSPACE}/logs/phpmd/phpmd-drupal.xml 2> /dev/null
else
echo "Nothing for phpmd in $CUSTOMDIR"
fi
}
# Test of Drupal core
function run_tests {
echo "run_tests START"
# Create the directory to saves the results
mkdir -p ${WORKSPACE}/logs/tests
cd $DRUPAL_ROOT
drush en simpletest --yes
drush vset clean_url 0
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
#Behat tests
#Init for initialise the yml config of behat
cd ${WORKSPACE}/test/behat
./behat --ansi --format junit,pretty --out ${WORKSPACE}/logs/behat,
}
# Generate a report of the site using site_audit
function site_audit {
echo "site_audit"
cd $DRUPAL_ROOT
# Full report using site_audit drush module
drush aa --html --bootstrap --detail --skip=insights > $WORKSPACE/output/site_audit.html
}
# Export code and database. This is a test for Pantheon
function build_artefacts {
echo "build_artefacts"
# Change directory to the root drupal folder
cd $DRUPAL_ROOT
# Create an archive that excludes sites/default/files
drush archive-dump --tar-options="--exclude=.git" --destination=$WORKSPACE/build/sfl_boilerplate-archive.tar.gz --overwrite
# Create a compressed database backup
drush sql-dump | gzip -9 > $WORKSPACE/build/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_BUILD -eq 1 ]; then
build_artefacts
fi
if [ $EN_CODER -eq 1 ]; then
run_coder
fi
if [ $EN_PHPCPD -eq 1 ]; then
run_phpcpd
fi
if [ $EN_PHPMD -eq 1 ]; then
run_phpmd
fi
if [ $EN_TESTS -eq 1 ]; then
run_tests
fi
if [ $EN_BEHAT -eq 1 ]; then
run_behat
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
}
# 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
else
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
exit $E_OPTERR
fi
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 ;;
-p | --phpcpd ) EN_PHPCPD=1; shift ;;
-m | --phpmd ) EN_PHPMD=1; shift ;;
-t | --tests ) EN_TESTS=1; shift ;;
-b | --behat ) EN_BEHAT=1; shift ;;
-a | --audit ) EN_AUDIT=1; shift ;;
-l | --legacy ) drupal_legacy; shift ;;
-- ) shift; break ;;
* ) break ;;
esac
done
# 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
# Clear all cache
echo "Clearing cache on $DRUPAL_ENV environment ..."
cd $DRUPAL_ROOT && drush --yes @$DRUPAL_ENV cache-clear all
<VirtualHost *:80>
ServerName localhost
ServerAdmin webmaster@localhost
DocumentRoot /var/www/src/drupal
DocumentRoot /var/www/drupal
<Directory /var/www/src/drupal>
<Directory /var/www/drupal>
Options FollowSymLinks
AllowOverride All
Require all granted
......
Subproject commit b9104fd98edfe4e8a1ffad22603fa339ab4a3116
#!/bin/bash
# site-install
#
# Script d'installation complète d'un site
#
# Usage:
# Instantiating a new site: rm -rf src/drupal && ./site-install
# Updating an existing site: cd src/drupal && drush make ../build/sfl-boilerplate.make .
#
# set -x
# set -e
# call default vars
source "deploy/default-vars"
# set default environment if not passed as parameter
DRUPAL_ENV=$1
if [ -z "$1" ]; then
DRUPAL_ENV=$SITE_ENVIRONMENT
fi
# delete drupal root if it exist
if [ -d $DRUPAL_ROOT ]; then
rm -rf $DRUPAL_ROOT
fi
# start mysql and setup passwords and database
mysqladmin -u root password $MYSQL_PASS
mysql -uroot -p$MYSQL_PASS -e "CREATE DATABASE $DB_NAME; GRANT ALL PRIVILEGES ON $DB_NAME.* TO '$DB_USER'@'localhost' IDENTIFIED BY '$DB_PASS'; FLUSH PRIVILEGES;"
# Makefile
drush make --prepare-install --translations=fr $WORKSPACE/build/sfl-boilerplate.make $DRUPAL_ROOT -y || exit 1
# Site installation
chown -R $APACHE:$APACHE $DRUPAL_ROOT
cd $DRUPAL_ROOT
# Run drush as the web server user
sudo -u $APACHE drush si sflinux --locale="fr" --db-url=mysql://$DB_USER:$DB_PASS@localhost/$DB_NAME --site-name="SFL Boilerplate" --account-name=admin --account-pass=admin --clean-url=1 -y
# Copy drush aliases
mkdir $DRUSH_ALIASES
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
cp $WORKSPACE/deploy/env/settings.$DRUPAL_ENV.php $DRUPAL_ROOT/sites/default/settings.$DRUPAL_ENV.php
echo "
/**
* Call environment settings file.
*/
require_once 'settings."$DRUPAL_ENV".php';" >> $DRUPAL_ROOT/sites/default/settings.php