Skip to content

Instantly share code, notes, and snippets.

@flusher
Created May 25, 2016 13:31
Show Gist options
  • Save flusher/fedb3bcd201b946598bb310c82079781 to your computer and use it in GitHub Desktop.
Save flusher/fedb3bcd201b946598bb310c82079781 to your computer and use it in GitHub Desktop.
Deployment script for a given (git, versioned Drupal project) tag
#!/bin/bash
#########################
### Deployment script ###
#########################
APP_PATH="/var/www/myproject/www"
APP_URL="www.myproject.com"
APP_POST_DEPLOY_SCRIPT="$APP_PATH/scripts/myproject_update.sh"
#########################
command -v drush >/dev/null 2>&1 || { echo >&2 "Drush required."; exit 1; }
command -v git >/dev/null 2>&1 || { echo >&2 "Git required."; exit 1; }
if [ ! -d $APP_PATH ]; then
echo "Directory $APP_PATH does not exist."
exit 1
fi
cd $APP_PATH
# fetch new tags
git fetch --tags
# determine tag to deploy
if [ $# -eq 0 ]; then
last_tag=$(git describe)
echo "Tag not defined as argument. Please type the tag to deploy."
echo -n "> [${last_tag}]"
read use_tag
if [[ "$use_tag" == "" ]]; then
use_tag=$last_tag
fi
else
use_tag=$1
fi
# test tag existence
if ! git show-ref --tags --quiet --verify -- "refs/tags/$use_tag" ; then
echo "The tag \"$use_tag\" does not exist. Try again !"
exit 1
fi
if [ ! -f "$(pwd)/.deploy_noconfirm" ]; then
echo "/!\\ You are about to deploy tag \"$use_tag\". Type \"yes\" to confirm. /!\\"
echo 'Note : create an empty ".deploy_noconfirm" file in your homedir to bypass this confirmation.'
echo -n "> "
read answer
if [[ "$answer" != "yes" ]]; then
echo "Ok ok. Just leaving."
exit 1
fi
else
echo 'Warning : file .deploy_noconfirm present ! Type Ctrl+C to stop deployment.'
for i in $(seq $TIMER_DEPLOY | sort -r); do
echo "$i seconds to go..."
sleep 1
done
fi
git checkout $use_tag
# Stop deploy if git repo not sync'ed
if [[ "$?" != "0" ]]; then
echo "Git pull failed ! Deployment interrupted."
exit 1
fi
# Launch post deployment app-specific script
bash -x $APP_POST_DEPLOY_SCRIPT
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment