Deploying my Website to GitHub Pages
Let’s look back at my website back in early 2012:
After finishing my M.Sc degree I decided to work in industry instead of pursuing a Ph.D. I continued to update the website with minor changes, but for the most part it stagnated over time.
I eventually wanted to revamp my website to be more relevant and decided going with a blog to document my technical endeavors and musings. I retired the old website and built up the new blog from scratch. I look through the Ruby Toolbox to see the alternatives to nanoc. Top pick seems to be Jekyll, which is likely contributed to its painless integration with GitHub Pages.
My two main concerns with Jekyll were:
The second contender is Middleman. Its offering was very similar to nanoc. I decided to give Middleman a spin as it was new and different from nanoc. For hosting I could figure it out later, although I was still leaning towards a manual usage of GitHub Pages as it was a free hosting solution.
With the initial work on the new blog being completed, it was time to handle the deployment of it. As previously mentioned I was still going to use GitHub pages due to its free offering. All the work can be seen in the kevinjalbert/kevinjalbert.github.io repository. A few things to note:
master
branch of the github repository.To accommodate this I decided to treat master
as the holding ground for the generated Middleman output. With respect to where to place the actual Middleman code, I placed everything in a new branch real-master
.
After a quick setup on GitHub, anything in the master
branch would be deployed to the public.
To reduce friction in deploying new changes, I created the following ruby deploy script.
require 'tmpdir'
`git checkout real-master`
current_sha = `git rev-parse --short HEAD`.strip
`rm -R -f ./bower_components`
`rm -R -f ./build`
`git add -f -A`
`git commit -m "Temp commit"`
`bundle install`
`bower install`
`bundle exec middleman build`
Dir.mktmpdir do |tmp_dir|
`mv ./build/* #{tmp_dir}/`
`git checkout master`
`cp CNAME #{tmp_dir}/`
`cp README.md #{tmp_dir}`
`rm -R -f *`
`cp -r #{tmp_dir}/* ./`
end
`git add -f -A`
`git commit -m "Update site @ #{Time.now} with #{current_sha}"`
`git push`
`git checkout real-master`
`git clean -df`
`git reset --soft HEAD~1`
`git reset`
`bower install`
Now, when everything is committed on real-master
and I’m ready to deploy I just run ruby deploy.rb
. The following is then carried out:
real-master
git branchmaster
real-master
again, clean everything, and reset that temporary commitThis results in a formatted commit log on master
that has snapshots of each deployment of the website.
This approach is working well for me at the current moment. I’ll probably keep using Middleman for the foreseeable future. I am sure I will go through another phase of redesigning this process, in which I will document yet again.