Last active
November 22, 2016 11:37
-
-
Save SqyD/4d020ca7978d443100a60a2776637265 to your computer and use it in GitHub Desktop.
Acquia Pipelines script to assemble from various git sources
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
version: 1.0.0 | |
events: | |
build: | |
steps: | |
- build: | |
type: script | |
script: | |
- bash -e scripts/pipelines_build.sh | |
ssh-keys: | |
id_rsa: | |
secure: [key] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
main: | |
git_repo: [email protected]:user/drupalcode.git | |
git_branch: master |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
site_a: | |
primary_domain: site-a.com | |
domains: 'www.site-a.com,site-a.com' | |
theme: theme_site_a | |
git_repo: [email protected]: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: [email protected]: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