Skip to content

Instantly share code, notes, and snippets.

@Aleksandr-ru
Last active December 26, 2017 10:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Aleksandr-ru/53be84be619e08f63c488b1568a5553a to your computer and use it in GitHub Desktop.
Save Aleksandr-ru/53be84be619e08f63c488b1568a5553a to your computer and use it in GitHub Desktop.
Git bare repo post-receive hook for automatic deploy
#!/bin/sh
while read oldrev newrev refname
do
#echo post-receive: $oldrev $newrev $refname >> ~/post-receive.log
if [ "$oldrev" != "$newrev" ]; then
branch=$(git rev-parse --symbolic --abbrev-ref $refname)
if [ "master" == "$branch" ]; then
echo Deploying $branch branch to production
ssh -i ~/.ssh/gitbot.id_rsa gitbot@production-host.example.com "~/pull-repo-script.sh"
# don't forget to add id_rsa.pub to /home/gitbot/.ssh/authorized_keys at production-host.example.com
elif [ "develop" == "$branch" ]; then
echo Deploying $branch branch to webarm-dev
ssh -i ~/.ssh/gitbot.id_rsa gitbot@development-host.example.com "~/pull-repo-script.sh"
# don't forget to add id_rsa.pub to /home/gitbot/.ssh/authorized_keys at development-host.example.com
else
echo "Branch $branch is not deployable"
fi
fi;
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment