My blog is generated by Jekyll and hosted on a Digital Ocean VPS. This is how I set up Git to allow me to instantly deploy updates.
My setup has gone through a few iterations over the years, as I changed technologies and tried to make it easier. I used to host it on GitHub pages but then I wanted some customisability over the server settings. Up until a few weeks ago, I was using a Travis to recognise when I pushed to the Git repo, which would trigger a build to push to my server. The main issue I had with this was Travis would sometimes take 5 minutes to see a new push. I wanted something a little faster.
git remote add live user@host:/path
I have a Git “post-receive” hook set up to run when I push, which provides automatic compilation.
#!/bin/bash
GIT_REPO=/var/www/entofarmers.club/website/repo
TMP_GIT_CLONE=/var/www/entofarmers.club/website/tmp
PUBLIC_WWW=/var/www/entofarmers.club/website/live
git clone --recursive $GIT_REPO $TMP_GIT_CLONE
chdir $TMP_GIT_CLONE
~/gems/bin/bundle install
~/gems/bin/bundle exec jekyll build -s $TMP_GIT_CLONE -d $PUBLIC_WWW
rm -Rf $TMP_GIT_CLONE
exit
chmod +x hooks/post-receive
sudo apt-get install ruby ruby-dev make build-essential
nano ~/.bashrc
--> # Ruby exports
--> export GEM_HOME=$HOME/gems
--> export PATH=$HOME/gems/bin:$PATH
source ~/.bashrc
gem install jekyll bundler