Last active
December 16, 2016 06:22
-
-
Save cowgill/8fdcda724f6939c31e0121c9db6b933b to your computer and use it in GitHub Desktop.
Git post-receive hook script used for automatic deployment from localhost to live server
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/sh | |
# | |
# Used for automatic deployment from localhost to live server | |
# Triggered when `git push live` is run locally (tutorial below must be followed first) | |
# | |
# Based off this Digital Ocean tutorial | |
# https://www.digitalocean.com/community/tutorials/how-to-set-up-automatic-deployment-with-git-with-a-vps | |
# | |
# Put this script in your local repo folder. Then set perms | |
# {YOUR_REPO}/.git/hooks/post-receive | |
# chmod +x post-receive | |
# Setup variables | |
# Todo: Make these dynamic | |
APP_NAME="vantage" | |
WEB_DIR="/var/www/vantagetheme.com/wp-content/themes/${APP_NAME}" | |
GIT_DIR="/var/repo/${APP_NAME}.git" | |
GIT_BRANCH="release-4.0" | |
while read oldrev newrev ref | |
do | |
echo "Deploying '${APP_NAME}' to '${WEB_DIR}'" | |
echo "Using repo '${GIT_DIR}'" | |
# Checkout branch we want | |
echo "Checking out branch '${GIT_BRANCH}'..." | |
git --work-tree=${WEB_DIR} --git-dir=${GIT_DIR} checkout -f ${GIT_BRANCH} || exit 1 | |
echo "Branch checked out" | |
# Change to working tree dir | |
echo "Changing into ${WEB_DIR} working tree dir..." | |
cd ${WEB_DIR} || exit 1 | |
echo "Done" | |
# Force submodule updates | |
echo "Updating submodules..." | |
git --work-tree=${WEB_DIR} --git-dir=${GIT_DIR} submodule update --init --recursive --force || exit 1 | |
echo "Submodules updated" | |
# Set the correct permissions | |
echo "Setting file perms..." | |
sudo chown -R www-data:www-data ${WEB_DIR} | |
# Remove dev files and dirs | |
echo "Deleting dev files and dirs..." | |
rm -rf tests grunt docs .* codeception.dist.yml apigen.neon bower.json composer.* phpcs.xml phpunit.xml Gruntfile.js package.json | |
echo "Done deploying. Success!" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment