Skip to content

Instantly share code, notes, and snippets.

@SqyD
Last active Nov 22, 2016
Embed
What would you like to do?
Acquia Pipelines script to assemble from various git sources
version: 1.0.0
events:
build:
steps:
- build:
type: script
script:
- bash -e scripts/pipelines_build.sh
ssh-keys:
id_rsa:
secure: [key]
main:
git_repo: git@bitbucket.org:user/drupalcode.git
git_branch: master
#!/bin/bash
# Custom script to assemble a multisite codebase from a main repository and a
# collection of theme respositories.
# Make sure we don't confuse people trying to run this locally
if [[ -z "$PIPELINE_ENV" ]]; then
echo "This script should be run from within the pipelines environment" 1>&2
exit 1
fi
# Configuration
MAIN_CFG=scripts/main.yml
# Source site files
SITES_CFG=scripts/sites.yml
# Generic yaml parser for bash
# Source: https://gist.github.com/pkuczynski/8665367
parse_yaml() {
local prefix=$2
local s='[[:space:]]*' w='[a-zA-Z0-9_]*' fs=$(echo @|tr @ '\034')
sed -ne "s|^\($s\)\($w\)$s:$s\"\(.*\)\"$s\$|\1$fs\2$fs\3|p" \
-e "s|^\($s\)\($w\)$s:$s\(.*\)$s\$|\1$fs\2$fs\3|p" $1 |
awk -F$fs '{
indent = length($1)/7;
vname[indent] = $2;
for (i in vname) {if (i > indent) {delete vname[i]}}
if (length($3) > 0) {
vn=""; for (i=0; i<indent; i++) {vn=(vn)(vname[i])("_")}
printf("%s%s%s=\"%s\"\n", "'$prefix'",vn, $2, $3);
}
}'
}
# Parse main configuration yml files.
eval $(parse_yaml $MAIN_CFG )
echo "Cloning main repository"
git clone --branch $main_git_branch --single-branch $main_git_repo main
echo "Copying what we need to the newly build docroot"
mkdir docroot
rsync -av main/docroot . --exclude sites/sites.php --exclude sites/g
rm -Rf main
echo "copying sites"
cp -Rv sites/* docroot/sites
# Parse sites configuration yml files.
eval $(parse_yaml $SITES_CFG "site_" )
# Gather an array of all site ids.
readarray -t SITES <<< "$(cat $SITES_CFG | grep ^[a-z] | cut -d ':' -f 1)"
SITE_COUNT=${#SITES[@]}
# counter
i=1
echo "Adding themes for $SITE_COUNT sites."
# Loop through each site
for SITE in "${SITES[@]}"
do
# Parse the site configuration
echo "Preparing for site $SITE. $i out of $SITE_COUNT"
eval THIS_THEME=\$site_${SITE}_theme
eval THIS_GIT_REPO=\$site_${SITE}_git_repo
eval THIS_GIT_BRANCH=\$site_${SITE}_git_branch
# Clone the theme repo
echo "Fetching theme repository for $THIS_THEME"
git clone --branch $THIS_GIT_BRANCH --single-branch $THIS_GIT_REPO $THIS_THEME
mkdir -p docroot/sites/$SITE/themes/$THIS_THEME
cp -Rv $THIS_THEME/* docroot/sites/$SITE/themes/$THIS_THEME
rm -Rf $THIS_THEME
((i++))
done
site_a:
primary_domain: site-a.com
domains: 'www.site-a.com,site-a.com'
theme: theme_site_a
git_repo: git@bitbucket.org:user/theme_site_a
git_branch: master
agency: agency_a
site_b:
primary_domain: site-b.com
domains: 'www.site-b.com,site-b.com'
theme: theme_site_b
git_repo: git@bitbucket.org:user/theme_site_b
git_branch: master
agency: agency_b
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment