[ Automated git deployment ] - Thu 16 April 2020

For deploying content on this site, I've set up a git hook to generate the Pelican files. Here's the breakdown:

  1. Create a deployment directory on the production server, in my case its a directory called pelican/ containing content, theme, and configuration files.
  2. Add a bare repo to the server somewhere where you have SSH access. git init --bare. This directory only serves to maintain the git version control information.
  3. Add the post-receive hook (shown below) to the bare repo and make it +x.
  4. Add the remote repository to your local repo.
  5. Push to the server.

After pushing, the following script will get run on the server:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
#!/bin/bash
TARGET="/home/garg/pelican"
GIT_DIR="/home/garg/pelican.git"
BRANCH="master"


while read oldrev newrev ref
do
    if [ "$ref" = "refs/heads/$BRANCH" ];
    then
        echo "Ref $ref received. Deploying ${BRANCH} branch to production..."
        git --work-tree=$TARGET --git-dir=$GIT_DIR checkout -f $BRANCH
        $TARGET/gen.sh
    else
        echo "Only the ${BRANCH} branch may be deployed on this server."
    fi
done

And the gen.sh file (line 13) simply calls pelican to generate the flat files.

Now, I can convert my emacs .org files into .md, store locally, commit, and push to the server. This will make it a lot easier to share my notes and projects on here.

Over and out.