Commit 97e734e5 authored by Ernesto Rodriguez Ortiz's avatar Ernesto Rodriguez Ortiz
Browse files

docker: Using site-install in jenkins-post-build to install the site

Avoid the repetition of code and reutilise site-install script
parent 7a98b7a2
......@@ -6,13 +6,13 @@ set -e
# Get params from build
TAG=$1
# Change this if needed
MYSQL_PASS=`pwgen -c -n -1 12`
DB_USER=drupal
DB_PASS=`pwgen -c -n -1 12`
DB_NAME=drupaldb
#MYSQL_PASS=`pwgen -c -n -1 12`
#DB_USER=drupal
#DB_PASS=`pwgen -c -n -1 12`
#DB_NAME=drupaldb
WORKSPACE=/var/www/drupal
DRUPAL_ROOT="$WORKSPACE"/src
WORKSPACE=/var/www
DRUPAL_ROOT="$WORKSPACE"/src/drupal
CUSTOMDIR=$DRUPAL_ROOT/sites/all/modules/custom
# Do not edit after
......@@ -61,29 +61,13 @@ function display_usage {
"
}
function init_bd {
# Start mysql
/usr/bin/mysqld_safe & sleep 10s
# This is so the passwords show up in logs.
echo mysql root password: $MYSQL_PASS
echo user: $DB_USER password: $DB_PASS
echo $MYSQL_PASS > /mysql-root-pw.txt
echo $DB_PASS > /drupal-db-pw.txt
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;"
}
function drupal_install {
# We need to create an empty DB for drupal using our test user account
mysqladmin -f -u$DB_USER -p$DB_PASS drop $DB_NAME
mysqladmin -u$DB_USER -p$DB_PASS create $DB_NAME
cd $DRUPAL_ROOT
# Launch site installation. It will create database structure and edit settings.php
# Install site
if ! drush si --yes --locale="fr" --db-url="mysql://$DB_USER:$DB_PASS@localhost/${DB_NAME}" --site-name="SFL Boilerplate" sflinux --account-name=admin --account-pass=admin --clean-url=1
# start apache
service apache2 start
# start mysql server
/usr/bin/mysqld_safe & sleep 10s
# execute site-install
if ! $WORKSPACE/site-install prod
then
echo "Fail to site install"
exit 1
......@@ -92,12 +76,13 @@ function drupal_install {
# Setup signal handler so DB are always deleted
trap script_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
}
function script_end {
......@@ -107,8 +92,9 @@ function script_end {
function fix_permissions {
# Permissions
# chown jenkins:www-data $DRUPAL_ROOT/sites/default
#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
......@@ -179,6 +165,7 @@ function run_behat {
function site_audit {
cd $DRUPAL_ROOT
echo "site_audit"
# Full report using site_audit drush module
drush aa --html --bootstrap --detail --skip=insights > $WORKSPACE/output/site_audit.html
}
......@@ -247,16 +234,9 @@ while true; do
esac
done
if [ ! -f "$DRUPAL_ROOT"/sites/default/settings.php ]; then
init_bd
drupal_install
fix_permissions
fi
drupal_install
run_all_tests
# Uncomment if you dont want to exit for test the drupal installation manually
#supervisord -n
fix_permissions
# SUCCESS if we are here
#exit 0
......@@ -14,11 +14,12 @@
DRUSH=`which drush`
ME=`whoami`
APACHE=www-data
MYSQL_PASS=r00tp4ssw0rd
DB_USER=dev
DB_PASS=dev
DB_NAME=sfl_boilerplate
WORKSPACE=`pwd`
DRUPAL_ROOT=`pwd`/src/drupal
WORKSPACE=/var/www
DRUPAL_ROOT=$WORKSPACE/src/drupal
DRUSH_ALIASES=$DRUPAL_ROOT/sites/all/drush
# set default environment if not passed as parameter
......@@ -27,14 +28,20 @@ if [ -z "$1" ]; then
DRUPAL_ENV=local
fi
#if [ -d $DRUPAL_ROOT ]; then
# rm -rf $DRUPAL_ROOT
#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 build/sfl-boilerplate.make $DRUPAL_ROOT -y || exit 1
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
......@@ -54,6 +61,16 @@ echo "
require_once 'settings."$DRUPAL_ENV".php';" >> $DRUPAL_ROOT/sites/default/settings.php
echo "Copy environment settings file in "$DRUPAL_ROOT"/sites/default/ and call it in settings.php file"
# Hack for HTTP request failure
# It's OK, but Drupal consider an issue.. weird !!
# Had to escape the $, otherwise only "['drupal_http_request_fails'] = FALSE;" is printed
echo "
/**
* HTTP request status hotfix.
*/
\$conf['drupal_http_request_fails'] = FALSE;" >> $DRUPAL_ROOT/sites/default/settings.php
echo "HTTP request status hotfix"
# Secure settings.php file
chmod 644 $DRUPAL_ROOT/sites/default/settings.php
echo "Secure settings.php file"
......
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