Skip to content

Instantly share code, notes, and snippets.

@joeydi
Created September 24, 2019 15:44
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 joeydi/fc6a68452b31a03d273ddbebde1a0b99 to your computer and use it in GitHub Desktop.
Save joeydi/fc6a68452b31a03d273ddbebde1a0b99 to your computer and use it in GitHub Desktop.
Craft CMS post-receive hook
#!/bin/bash
WORK_TREE="/var/www/example"
GIT_DIR="/var/repo/example.git"
BRANCH="master"
while read oldrev newrev ref
do
# only checking out the master (or whatever branch you would like to deploy)
if [ "$ref" = "refs/heads/$BRANCH" ];
then
echo "Ref $ref received. Deploying ${BRANCH} branch to production..."
git --work-tree=$WORK_TREE --git-dir=$GIT_DIR checkout -f $BRANCH
cd $WORK_TREE
chown -R www-data:www-data $WORK_TREE
chmod -R 744 $WORK_TREE
composer install
else
echo "Ref $ref received. Doing nothing: only the ${BRANCH} branch may be deployed on this server."
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment