Git Deploy Jekyl Website

19 May 2019

Let’s face it, if you’ve used Heroku, you love their easy deploy process - I know I do! But if you try to host a hobby project that requires access to the local filesystem, or in my case I want the site to be hosted on the naked domain without having to use DNSimple or another provider that has ALIAS records, then Heroku quickly becomes a problem.

So I’ve created this easy breazy process to git deploy your website

  1. On the server, create a new repository in /var/git/ as the “code vault”:

    git init --bare /var/git/chrisjones.git

  2. Create a new post-deploy hook file named post-update

    cd /var/git/chrisjones.git/hooks
    cp post-update.sample post-update

  3. Fill the file with this code for my Jekyll blog:

    echo "**** Pulling changes into Live [Production's post-update hook]"
    cd /srv/ || exit
    unset GIT_DIR
    git pull production master
    echo "bundle install"
    ~/.rbenv/shims/bundle install
    echo "Compiling assets..."
    JEKYLL_ENV=production ~/.rbenv/shims/bundle exec jekyll build
    exec git-update-server-info
  4. Now create the web directory

    mkdir /srv/

  5. Setup directory to receive code:

    git init
    git remote add production /var/git/chrisjones.git

  6. Now on the local development machine add the repository to your git config:

    git remote add production webserver:/var/git/chrisjones.git

  7. Now simply deploy!

    git push production master

Whenever you have an update, or I want to create a new post, I simply commit the code and deploy to production. Boom!

Tags: devops

Published on 19 May 2019 Find me on LinkedIn!