draft(post-receive): production script

script for git to automatically build and deploy the websites upon pushing an update to the main branch stored on the production server
steven 2021-09-15 15:49:55 -04:00
parent 8848cc7892
commit 0e2ed48634
1 changed files with 33 additions and 0 deletions

33
post-receive 100644
View File

@ -0,0 +1,33 @@
#!/bin/bash
# The production directory
TARGET="/var/www/friends.of.mineral.town"
# Local (to server) git repository
GIT_DIR="~/mineral.town.git"
# A temporary directory for deployment
TEMP="~/work"
# Name of production branch
BRANCH="main"
while read oldrev newrev ref
do
# only checking out the deployment branch
if [ "$ref" = "refs/heads/$BRANCH" ];
then
mkdir $TEMP
echo "Ref $ref received. Deploying ${BRANCH} branch to production..."
git --work-tree=$TEMP --git-dir=$GIT_DIR checkout -f $BRANCH
# build blog
cd $TEMP/blog
hugo -D
# Replace production directory with updated project files
cd ~
rm -rf $TARGET
mv $TEMP/ $TARGET/
else
echo "Ref $ref received. Doing nothing: only the ${BRANCH} branch may be deployed on this server."
fi
done