Skip to content

Instantly share code, notes, and snippets.

@acouch
Created October 13, 2016 13:58
Show Gist options
  • Save acouch/aed3ab34f074709f2f5671161bd04269 to your computer and use it in GitHub Desktop.
Save acouch/aed3ab34f074709f2f5671161bd04269 to your computer and use it in GitHub Desktop.
ahoyapi: v1
version: 0.0.0
commands:
setup:
usage: Setups sites settings
cmd: |
# Create an array with the arguments that were input.
ARGS=( {{args}} )
rm -f assets/sites/default/settings.docker.php
rm -f assets/sites/default/settings.local.php
ahoy cmd-proxy bash ./nucivic-ahoy/.scripts/drush.alias.sh
if [ ! -f assets/sites/default/settings.php ] && [ -f assets/sites/default/default.settings.php ]; then
cp assets/sites/default/default.settings.php assets/sites/default/settings.php
fi
if [ "$CI" = "true" ]; then
# Drush alias points to /var/www/docroot so we need this here.
sudo ln -sf /home/ubuntu/$CIRCLE_PROJECT_REPONAME/docroot /var/www/docroot
fi
if [ "$AHOY_CMD_PROXY" == "DOCKER" ]; then
cp assets/sites/default/settings.docker.demo.php assets/sites/default/settings.docker.php
ahoy docker up
elif [ "${#ARGS[@]}" -ne 0 ]; then
for i in "${ARGS[@]}"; do
case "$i" in
--db-user=*)
DB_USER="${i#*=}"
;;
--db-pass=*)
DB_PASS="${i#*=}"
;;
--db-host=*)
DB_HOST="${i#*=}"
;;
--db-port=*)
DB_PORT="${i#*=}"
;;
--db-name=*)
DB_NAME="${i#*=}"
;;
*)
echo "not recognized flag or param ${i#*=}"
exit 1
;;
esac
done
sed \
-e s/#DB_HOST/$DB_HOST/g \
-e s/#DB_USER/$DB_USER/g \
-e s/#DB_PASS/$DB_PASS/g \
-e s/#DB_PORT/$DB_PORT/g \
-e s/#DB_NAME/$DB_NAME/g \
assets/sites/default/settings.local.demo.php > assets/sites/default/settings.local.php
echo "A settings.local.php file was created at assets/sites/default/settings.local.php with your db credentials."
else
cp assets/sites/default/settings.local.demo.php assets/sites/default/settings.local.php
echo "A settings.local.php file was created at assets/sites/default/settings.local.php, but you need you add your own db credentials."
fi
reinstall:
usage: Reinstall the site from scratch (dkan + custom_config + environment).
cmd: |
ahoy dkan reinstall
ahoy drush -y en custom_config environment devinci
ahoy drush env-switch --force local
mysql-dump-sanitized:
usage: Creates a dump of a sanitized and pruned version of the site db
cmd: |
ahoy cmd-proxy exec mkdir -p backups
ahoy drush sql-dump > backups/unsanitized.sql
ahoy drush sql-cli < nucivic-ahoy/.mysqlscripts/sanitize.sql | grep -v concat > backups/truncate.sql
ahoy drush sql-cli < backups/truncate.sql
rm backups/truncate.sql
ahoy drush sql-dump > backups/sanitized.sql
ahoy drush -y sql-drop
ahoy drush sql-cli < backups/unsanitized.sql
mysql-prune:
usage: Prunes datasets and resources from site database
hide: true
cmd: |
ahoy drush php-script nucivic-ahoy/.scripts/prune-database.php
name:
usage: Utility function to determine the site name.
cmd: |
# TODO: use config/config.yml instead
if [ -s assets/drush/aliases.local.php ]; then
ahoy cmd-proxy php -f nucivic-ahoy/.scripts/site-name.php
else
echo "Site name not set. Type the alias followed by [ENTER]:"
read ALIAS
cat assets/drush/datastarter.aliases.drushrc.php | sed "s/data_starter/$ALIAS/g" > assets/drush/aliases.local.php
fi
hide: true
asset-download:
usage: Download database and files assets from S3 to local backups folder.
cmd: |
ahoy site asset-download-db
ahoy site asset-download-files
hide: true
asset-download-db:
usage: Download DB backup asset from S3 to local backups folder.
cmd: |
ahoy site asset-download-dbs sanitized
asset-download-db-unpruned:
usage: Download unpruned DB backup asset from S3 to local backups folder.
cmd: |
ahoy site asset-download-dbs unpruned
asset-download-dbs:
hide: true
usage: Download DB backup asset from S3 to local backups folder.
cmd: |
ahoy cmd-proxy exec mkdir -p backups
site=$(ahoy site name)
db={{args}}
asset=""
echo "ASSET NOT SETUP. SEE DOCUMENTATION FOR DETAILS"
exit(1)
LC_TIME=en_US.UTF-8 perl nucivic-ahoy/.scripts/s3curl.pl --id local $asset > backups/$db.sql.gz
echo ""
echo "Unpacking the $db database."
echo ""
ahoy cmd-proxy gunzip backups/$db.sql.gz -f
cp -f backups/$db.sql backups/last_install.sql
asset-download-files:
usage: Download files backup asset from S3 to local backups folder.
cmd: |
ahoy cmd-proxy exec mkdir -p backups
site=$(ahoy site name)
asset=""
echo "ASSET NOT SETUP. SEE DOCUMENTATION FOR DETAILS"
exit(1)
LC_TIME=en_US.UTF-8 perl nucivic-ahoy/.scripts/s3curl.pl --id local $asset > backups/$site.prod.files.tar.gz
echo ""
echo "Unpacking the files asset."
echo ""
tar xvzf backups/$site.prod.files.tar.gz
hide: true
asset-upload:
usage: Upload database and files assets to dedicated S3 bucket.
cmd: |
ahoy site asset-db-upload
ahoy site asset-files-upload
hide: true
s3-setup:
usage: Utility script for adding aws s3curl credentials.
cmd: bash nucivic-ahoy/.scripts/s3-setup.sh
hide: true
self-update:
usage: Utility function for self updating this repo.
cmd: |
ahoy dkan self-update
rm -fR nucivic-ahoy
git clone '[email protected]:nucivic/nucivic-ahoy' --depth=1
rm -rf nucivic-ahoy/.git
rm -rf nucivic-ahoy/.gitignore
hide: true
files-link:
usage: Links files.
cmd: ahoy cmd-proxy ln -s ../../../$(ahoy site name).prod.files/files docroot/sites/default/files
hide: true
files-fix-permissions:
usage: Fix the permissiosn for the files.
cmd: |
ahoy cmd-proxy bash ./nucivic-ahoy/.scripts/site.files-fix-permissions.sh
hide: true
test:
usage: Run the tests for site
cmd: |
# Store the arguments as a bash array.
ARGS=( "{{args}}" )
BEHAT_FOLDER=tests
ALT_CONFIG_FILE="behat.local.yml"
# Crazy bash to get rid of the carriage return. (docker issue)
BEHAT_ENV=$(echo $(ahoy cmd-proxy printenv HOSTNAME) | tr -d "\r" )
SKIP_COMPOSER_FLAG="--skip-composer"
if [[ ! "${ARGS[@]}" == *"$SKIP_COMPOSER_FLAG"* ]]; then
echo "Installing behat dependencies.."
ahoy cmd-proxy "cd $BEHAT_FOLDER && composer install --prefer-source --no-interaction"
else
echo "Skipping composer install.."
ARGS=( "${ARGS[@]/$SKIP_COMPOSER_FLAG}" )
fi
if [ -f "$BEHAT_FOLDER/$ALT_CONFIG_FILE" ]; then
echo "Using $BEHAT_FOLDER/$ALT_CONFIG_FILE .."
CONFIG=" -c $ALT_CONFIG_FILE"
elif [ "$BEHAT_ENV" == "cli" ]; then
echo "Using behat.docker.yml config .."
CONFIG=" -c behat.docker.yml"
elif [ "$CI" == "true" ]; then
echo "Using behat.circleci.yml config .."
CONFIG=" -c behat.circleci.yml"
else
echo "$BEHAT_ENV"
echo "Using behat.yml .."
fi
ahoy cmd-proxy "cd $BEHAT_FOLDER && bin/behat $CONFIG ${ARGS[@]}"
truncate-watchdog:
usage: Truncates the watchdog table.
hide: true
cmd: |
echo "truncate watchdog" | ahoy dkan sqlc;
fail-when-bad-disable:
usage: Kill the build if modules were incorrectly disabled.
hide: true
cmd: |
error=`echo "select message, variables from watchdog where type = 'custom_config_disable'" | ahoy dkan sqlc`
if [ "$error" ];
then
echo $error
exit 1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment