Skip to content

Instantly share code, notes, and snippets.

@waynegraham
Last active August 29, 2015 13:57
Show Gist options
  • Save waynegraham/9468914 to your computer and use it in GitHub Desktop.
Save waynegraham/9468914 to your computer and use it in GitHub Desktop.
Deploy jekyll site with post-recieve hook

Make sure user's public key (id_rsa.pub) is in the ~/.ssh/authorized_keys.

laptop$ ssh deployer@example.com
server$ mkdir -p /usr/local/projects/[project_name]/shared/[project_name].git
server$ cd /usr/local/projects/[project_name]/shared/[project_name].git
server$ git --bare init
server$ touch hooks/post-receive
server$ mkdir -p /usr/local/projects/[project_name]/current

Add the post-receive hook.

Add the remote and push:

laptop$ git remote add deploy deployer@example.com:/usr/local/projects/[project_name]/shared/[project_name].git
laptop$ git push deploy master
#! /bin/sh
#
# Post receive hook script for the "post-receive" event.
#
# The "post-receive" script is run after receive-pack has accepted a pack
# and the repository has been updated. It is passed arguments in through
# stdin in the form
# <oldrev> <newrev> <refname>
# For example:
# aa453216d1b3e49e7f6f98441fa56946ddcd6a20 68f7abf4e6f922807889f52bc043ecd31b79f814 refs/heads/master
#
# see contrib/hooks/ for a sample, or uncomment the next line and
# rename the file to "post-receive".
PROJECT_BASE=/usr/local/projects/[project_name]
GIT_REPO=$PROJECT_BASE/shared/[project_name].git
TMP_GIT_CLONE=$PROJECT_BASE/shared/build
PUBLIC_WWW=$PROJECT_BASE/current
mkdir -p $TMP_GIT_CLONE
git clone $GIT_REPO $TMP_GIT_CLONE
jekyll build -s $TMP_GIT_CLONE -d $PUBLIC_WWW
rm -Rf $TMP_GIT_CLONE
exit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment