Skip to content

Instantly share code, notes, and snippets.

@paulsheldrake
Last active August 29, 2015 13:56
Show Gist options
  • Save paulsheldrake/8800962 to your computer and use it in GitHub Desktop.
Save paulsheldrake/8800962 to your computer and use it in GitHub Desktop.
sample create package of code
#!/bin/bash
# turn debugging on
set -x
source ./scripts/common.config.sh
# variables
BUILD_DIRECTORY=htdocs
COMPOSER_DIRECTORY=composer
DRUSH_DIRECTORY=drush
PACKAGE_FILENAME="package_${BRANCH_TAG}"
EXTRACTED_REPO_FOLDER=eurostar_repo
# make sure th github repo exists
if [ ! -d eurostar_builds ]; then
echo "Eurostar builds repo does not exist, creating..."
git clone git@github.com:Capgemini/eurostar_builds.git
fi
# get the branch/tag of the eurostar repo
# remove the old version and the extracted directory
rm -f eurostar.zip
rm -fr ${EXTRACTED_REPO_FOLDER}
curl -H "Authorization: token XXXXXXXXXXXXXXXXXXXXX" -L -o eurostar.zip \
https://api.github.com/repos/Capgemini/eurostar/zipball/${BRANCH_TAG}
# extract the zip
unzip eurostar.zip
# fix the name of the extracted directory
mv Capgemini-eurostar-* ${EXTRACTED_REPO_FOLDER}
# remove previous code
rm -rf ${BUILD_DIRECTORY}
rm -rf ${DRUSH_DIRECTORY}
rm -rf ${COMPOSER_DIRECTORY}
# Drush make
drush -y make --no-cache ${EXTRACTED_REPO_FOLDER}/eurostar.make ${BUILD_DIRECTORY}
if [ ! -d ${BUILD_DIRECTORY} ]; then
echo "Drupal make process failed..."
exit 1
else
echo "Drupal make process was successful"
fi
# run the js minify script. run closure over drupal core and all custom code
sh scripts/js-minify-v2.sh
# Drush
wget -O- http://ftp.drupal.org/files/projects/drush-7.x-5.9.tar.gz | tar zxv
# Composer
# download it if we don't have it already
if [ ! -e "${COMPOSER_VERSION}" ]; then
wget https://codeload.github.com/composer/composer/tar.gz/${COMPOSER_VERSION}
fi
mkdir -p ${COMPOSER_DIRECTORY}
tar -zxvf ${COMPOSER_VERSION}
mv ${COMPOSER_EXTRACTED_DIR} ${COMPOSER_DIRECTORY}
wget https://getcomposer.org/download/${COMPOSER_VERSION}/composer.phar
mv composer.phar ${COMPOSER_DIRECTORY}/${COMPOSER_EXTRACTED_DIR}/composer.phar
chmod 777 ${COMPOSER_DIRECTORY}/${COMPOSER_EXTRACTED_DIR}/composer.phar
# Write build.txt file
echo "${BRANCH_TAG}" > ${BUILD_DIRECTORY}/build.txt
# Remove spurious views module
rm -rf ${BUILD_DIRECTORY}/profiles/eurostar/modules/views
# Fix elfinder
rm -f ${BUILD_DIRECTORY}/profiles/eurostar/libraries/elfinder/elfinder.php.html
rm -f ${BUILD_DIRECTORY}/profiles/eurostar/libraries/elfinder/connectors/php/connector.php
rm -f ${BUILD_DIRECTORY}/profiles/eurostar/libraries/elfinder/elfinder.html
rm -f ${BUILD_DIRECTORY}/profiles/eurostar/libraries/elfinder/php/connector.php
rm -f ${BUILD_DIRECTORY}/profiles/eurostar/libraries/elfinder/php/connector.minimal.php
# Remove robots.txt to allow admin via robotstxt module
rm -f ${BUILD_DIRECTORY}/robots.txt
# SYMLINKING MODULES
#
# You can't symlink link in a way that works on another vm as part of the tar process. The symlink step needs
# to happen on the actual machine.
# We are just going to delete the "sites/all/modules" directory here because it will make the
# package smaller
rm -rf ${BUILD_DIRECTORY}/sites/all/modules
# Copy status.php for monitoring
cp -f ${EXTRACTED_REPO_FOLDER}/scripts/status.php ${BUILD_DIRECTORY}/status.php
# Copy js.php for minimal bootstrap
cp -f ${BUILD_DIRECTORY}/profiles/eurostar/modules/contrib/js/js.php ${BUILD_DIRECTORY}/js.php
# Make sure that layout file is in the files directory for css aggregation
mkdir -p ${BUILD_DIRECTORY}/sites/all/themes/eurostar/base/css/
cp -f ${BUILD_DIRECTORY}/profiles/eurostar/themes/eurostar/base/css/layout.css ${BUILD_DIRECTORY}/sites/all/themes/eurostar/base/css/layout.css
# Remove any old versions of packages with the same file name, I.E. packages made from branches
rm -f ${PACKAGE_FILENAME}
# copy the common settings
cp -vf ${EXTRACTED_REPO_FOLDER}/conf/drupal/common.settings.php ${BUILD_DIRECTORY}/sites/default/common.settings.php
# package the builds for each environment type
ENVIRONMENT_CONF=( dev test e2e ewt prod)
for ENV in "${ENVIRONMENT_CONF[@]}"
do :
ENVIRONMENT_PACKAGE_NAME="${PACKAGE_FILENAME}_${ENV}.tgz"
echo "Creating package: ${ENVIRONMENT_PACKAGE_NAME}"
# DRUPAL SETTINGS
# delete old version of settings file
rm -f ${BUILD_DIRECTORY}/sites/default/settings.php
# copy new environment specific version
cp -vf ${EXTRACTED_REPO_FOLDER}/conf/drupal/${ENV}.settings.php ${BUILD_DIRECTORY}/sites/default/settings.php
# LOG4PHP SETTINGS
# delete old version of log4php file
rm -f ${BUILD_DIRECTORY}/sites/default/log4php.xml
# copy new environment specific version
cp -vf ${EXTRACTED_REPO_FOLDER}/conf/drupal/${ENV}.log4php.xml ${BUILD_DIRECTORY}/sites/default/log4php.xml
# zip up that environment package
GZIP=-9 tar -czf ${ENVIRONMENT_PACKAGE_NAME} ${BUILD_DIRECTORY} ${DRUSH_DIRECTORY} ${COMPOSER_DIRECTORY}
# copy it so it can be added to github, put packages in to folders by environment
mkdir -p eurostar_builds/${ENV}
mv ${ENVIRONMENT_PACKAGE_NAME} eurostar_builds/${ENV}/${ENVIRONMENT_PACKAGE_NAME}
done
cd eurostar_builds
git pull
git add .
git commit -m "Adding ${PACKAGE_FILENAME} @ ${BUILD_ID}" .
git push origin master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment