Skip to content

Instantly share code, notes, and snippets.

@kevinchampion
Created March 5, 2014 17:26
Show Gist options
  • Save kevinchampion/9371951 to your computer and use it in GitHub Desktop.
Save kevinchampion/9371951 to your computer and use it in GitHub Desktop.
Builds repo project provision
1. Provision new vhost
2. Add CNAME record in rackspace
3. Create database and grant new mysql user full rights to it
## Steps for initial setup of buildsrepos
1. Create headless repo in correct directory
2. Create builds repo in correct directory
3. Copy .gitignore, commit, checkout new branch
4. Add remote to headless and push changes
5. Initialize repo in vhost (fix permissions to be able to)
6. Add remote to headless and pull builds branch
7. Run the first full build (includes ongoing build steps minus site specific at the end)
8. Copy default.settings.php into sites/default/
9. Run first site install
10. Run first ongoing build to ensure all pieces are working
// On just initialized repo, sets ref to new branch name so first commit will happen there.
*** git symbolic-ref HEAD refs/heads/7.x-1.x
###############################################################################
(as jenkins)
#!/bin/bash
CLIENT="sevone"
SITE="sevone_primary"
BUILDFILE="build-sevone.make"
PROFILE="sevone"
SCRIPTSDIR="var/www/vhosts/scripts"
BUILDSDIR="var/www/builds"
BUILDSREPOSDIR="var/www/buildsrepos"
VHOSTSDIR="var/www/vhosts"
VHOST="dev.sevone.ixm.ca"
INSTALL="no"
# Handle input errors to catch mistakes before they cause problems.
# Make sure buildsrepo doesn't already exist
if [ ! -d "/${BUILDSREPOSDIR}/${CLIENT}/${SITE}" ]; then
# Buildsrepo directory already exists indicating that this site has already been setup. Get out of here so that it's not overwritten accidentally.
echo "This site already exists at /${BUILDSREPOSDIR}/${CLIENT}/${SITE}. Manually remove this site or choose a different site name to proceed."
exit 1
fi
# Make sure build doesn't already exist.
if [ ! -d "/${BUILDSDIR}/${CLIENT}/${SITE}" ]; then
# Builds directory already exists indicating that this site has already been setup. Get out of here so that it's not overwritten accidentally.
echo "This site already exists at /${BUILDSDIR}/${CLIENT}/${SITE}. Manually remove this site or choose a different site name to proceed."
exit 1
fi
# Setup directory structure and create headless repo.
# Create the client directory if it doesn't exist yet.
if [ ! -d "/${BUILDSREPOSDIR}/${CLIENT}" ]; then
# Control will enter here if $DIRECTORY doesn't exist.
echo "Client directory doesn't exist yet, creating it now..."
mkdir /${BUILDSREPOSDIR}/${CLIENT}
fi
# Create the site directory if it doesn't exist yet.
if [ ! -d "/${BUILDSREPOSDIR}/${CLIENT}/${SITE}" ]; then
# Control will enter here if $DIRECTORY doesn't exist.
echo "Site directory doesn't exist yet, creating it now..."
mkdir /${BUILDSREPOSDIR}/${CLIENT}/${SITE}
fi
cd /${BUILDSREPOSDIR}/${CLIENT}/${SITE}
git init --bare
# Setup directory structure and create build repo for the builds destination.
# Create the client directory if it doesn't exist yet.
if [ ! -d "/${BUILDSDIR}/${CLIENT}" ]; then
# Control will enter here if $DIRECTORY doesn't exist.
echo "Client directory doesn't exist yet, creating it now..."
mkdir /${BUILDSDIR}/${CLIENT}
fi
# Create the site directory if it doesn't exist yet.
if [ ! -d "/${BUILDSDIR}/${CLIENT}/${SITE}" ]; then
# Control will enter here if $DIRECTORY doesn't exist.
echo "Site directory doesn't exist yet, creating it now..."
mkdir /${BUILDSDIR}/${CLIENT}/${SITE}
fi
cd /${BUILDSDIR}/${CLIENT}/${SITE}
git init
cp /${BUILDSDIR}/.gitignore .
git add .
git commit -m "Initial commit, add .gitignore."
git checkout -b 7.x-1.x-builds
git branch -D master
git remote add origin /${BUILDSREPOSDIR}/${CLIENT}/${SITE}/
git push origin 7.x-1.x-builds
# Set appropriate ownership and permissions for vhost and setup site repo.
sudo chmod g+w /${VHOSTSDIR}/${VHOST}
sudo chown jenkins /${VHOSTSDIR}/${VHOST}/public
sudo chmod g+w /${VHOSTSDIR}/${VHOST}/public
cd /${VHOSTSDIR}/${VHOST}/public
git init
git remote add origin /${BUILDSREPOSDIR}/${CLIENT}/${SITE}/
git pull origin 7.x-1.x-builds
# Trigger first build with first site install.
# Generate Jenkins task to manage builds.
#!/bin/bash
CLIENT="sevone"
SITE="sevone_primary"
BUILDFILE="build-sevone.make"
PROFILE="sevone"
SCRIPTSDIR="var/www/vhosts/scripts"
BUILDSDIR="var/www/builds"
VHOSTSDIR="var/www/vhosts"
VHOST="dev.sevone.ixm.ca"
INSTALL="no"
cd /${BUILDSDIR}/${CLIENT}/
sh /${SCRIPTSDIR}/dl_private_github_file.sh imagex 6c9753dcc3589cc72a18b145642f700e1529b6ed ${PROFILE} ${BUILDFILE} 7.x-dev ./
sudo rm -fR ${SITE}
drush make ${BUILDFILE} ${SITE} --no-gitinfofile --no-cache -y
# Check if built site directory exists.
if [ ! -d "/${BUILDSDIR}/${CLIENT}/${SITE}" ]; then
# If directory doesn't exist then the build failed and we need to get out of here.
echo "Site directory doesn't exist, which likely means the build failed, check for errors."
exit 1
fi
echo "Build succeeded, proceed..."
cd /${BUILDSDIR}/${CLIENT}/${SITE}
# This may not be necessary
sudo chown -R jenkins ./*
sudo chgrp -R www-data ./*
sudo chmod -R 0775 sites/default/files
TAG=`date +%Y-%m-%dT%H%M`
sh /${SCRIPTSDIR}/jenkins-tag-build.sh ${CLIENT} ${SITE} ${TAG}
cd /${VHOSTSDIR}/${VHOST}/public/
git fetch origin tag ${TAG}
git reset --hard ${TAG}
git show ${TAG}
if [ ${INSTALL} = "yes" ]; then
cp /var/www/builds/default.settings.php sites/default/default.settings.php
drush site-install sevone --account-name=admin --account-pass=thehourofthebewilderbeast --site-name="SevOne Dev" --db-url=mysql://devsevone:itsnotsoimpossible@localhost/dev_sevone -y
drush cache-clear drush
drush features-revert-all -y
drush cache-clear all
else
drush updatedb -y
drush cache-clear drush
drush features-revert-all -y
drush cache-clear all
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment