Skip to content

Instantly share code, notes, and snippets.

@thomasweng15
Created May 3, 2018 21:20
Show Gist options
  • Save thomasweng15/6726f99cee79cf0adc037c6ba85c511d to your computer and use it in GitHub Desktop.
Save thomasweng15/6726f99cee79cf0adc037c6ba85c511d to your computer and use it in GitHub Desktop.
Git deploy post-receive hook
#!/bin/bash
TARGET="/home/thomas_weng11/deploy-robopubs"
GIT_DIR="/home/thomas_weng11/robopubs.git"
BRANCH="master"
while read oldrev newrev ref
do
# only checking out the branch to deploy
if [[ $ref = refs/heads/"$BRANCH" ]];
then
echo "Ref $ref received. Deploying ${BRANCH} branch to prod..."
git --work-tree="$TARGET" --git-dir="$GIT_DIR" checkout -f
source /home/thomas_weng11/deploy-robopubs/robopubsenv/bin/activate
pip install -r /home/thomas_weng11/deploy-robopubs/requirements.txt
deactivate
sudo systemctl reload-or-restart myproject.service
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