My very first tech blog on my own personal site! We’ll see what comes of this. I have a bit of a problem on focusing on things and sticking to it, but I’m going to do my best to keep a semi-sort-of-regular-kind-of-occasional routine of tech blogs going.
It wasn’t so long ago that I started using Capistrano for deployments and that it was a gift directly from the spaghetti monster himself. Now after using Heroku for a year or so, I am even more spoiled. Spoiled by git deployments. Commit and push and then deployment is done. Like magic. A few weeks ago I decided to make this site for my work and to start doing some occasional tech blogging. I went through a few different possibilities for what to use but decided on Jekyll. A lot of people use Jekyll and deploy to Github pages on their Github account. I already had an idle Linode sitting around and I wanted to use that. So I came to a decision: use Jekyll and a automated git deployment workflow on my own server. That lead me to Jekyll and Gitolite. Jekyll is essentially a parser or a static site generator – not really a blog engine. It parses through files and generates all the flat html files needed for a site. So instead of managing a database and everything, you can just write your blog posts in markdown. It’s a really brilliant set up and is easy as hell. Since it is all flat files, it is also really convenient to keep your blog on Github so that it is always backed up.
Using Gitolite and Jekyll you can be auto-deploying within minutes.
- Create a user named ‘git’ and login with this user
- Copy your ssh pubkey from the workstation you wish to deploy from and put it in the home directory for the git user. Rename the key to your_name.pub. (Of course using your name… not “your_name”)
- Run these commands
That will complete the install. If you have problems with it though, there is a more extensive installation guide to solve problems.
You do not install repositories directly on the server. You clone the gitolite-admin repository on the workstation that you will deploy from in order to administer the gitolite installation. You can manage users, groups and repository access from this repository.
After you have cloned the admin respository, edit gitolite-admin/conf/gitolite.conf to add in your new repository and user permissions.
In this example, blog is the name of the repository you want to create and username is the name you put on the public key you uploaded. So if you uploaded a key named addam.pub you will need to put addam here.
Add the new files to the git repository (git add .) and commit. Push it back to the remote repository (the server you are deploying to) with git push origin master.
Managing a Jekyll-Bootstrap Blog
I really liked how Jekyll-Bootstrap has a lot of things good to go instead of me building it all by myself so I decided to go with Jekyll-Bootstrap. After you clone Jekyll-Bootstrap and modify a few config files, you will have a no-database Jekyll blog running straight-away.
In this example: my-server is the hostname of the server you set up Gitolite on and blog is whatever you named your repository in the Gitolite config file.
You can modify files and test them in real time by running jekyll –server inside the blog directory. This will run a WEBrick instance so that you’ll be able to access your blog from http://localhost:4000. You can leave this running while you edit your files and it will regenerate the files as you edit them.
I personally use Nginx to host my Jekyll site on my server but you can use any web server. Just point it to the directory you want it to be served from and then you can create an auto-update script that will run upon each push. So when you push your new blog that you have tested locally to your server, the post-receive hook will fire and update your blog. Completely automated deployment courtesy of Git, Gitolite and Jekyll.
On the your deployment server navigate to /home/git/repositories/blog.git/hooks and edit the post-receive file. Paste this inside the file:
Ensure that you set PUBLIC_WWW to wherever you have your web server pointing
After you save this file, commit a small change to test it. Upon pushing, the server should fire the post-receive hook and regenerate your site. This is an example of what a successful push should look like:
And there you go. git auto-deloy awesomeness. In order to create a blog post you just do:
and then edit the file in markdown or html. Jekyll is a create platform for creating a static website. Execute the command rake -T to see all the possible rake tasks.
The benefit of using Jekyll-Bootstrap is having a lot of things baked in and ready to go like themes. This simple setup is much easier than me setting up and maintaining a wordpress blog and database, and it enables you to create a basic, simple and clean static website and/or blog.
Looking forward to doing more blog posts using this system.
Still getting the hang of technical writing/blogging. So bear with me as I learn the ropes! Hope this post helped you set up an easy Jekyll deployment system.