Deploy Jekyll with Mina

This blog is running on CentOS 7 server of DigitalOcean. The webserver is Nginx. The blog system I am using is Jekyll. To make the deployment smooth and fast I use Mina. The philosophy behind Mina is the same as Capistrano's, but with less features and configuration.

DigitalOcean has a good tutorial for setting up a CentOS server:

Nginx has an official repo for CentOS which you can use for sudo yum update:

Follow your preferred tool for Ruby version management and install ruby on the server.

Set up your jekyll blog on your local machine and make sure that it is ready for public. I use GitHub. You can use any git repository provider, but make sure that it will be available for pull from your CentOS machine. It can be even on your CentOS server!

Mina configuration

Initial Mina deploy file can be created with mina init command.

Here is my config/deploy.rb file.

# config/deploy.rb
require 'mina/bundler'
require 'mina/rails'
require 'mina/git'
require 'mina/rbenv'

set :domain,      ''
set :user,        'ali'
set :deploy_to,   '/home/ali/blog'
set :repository,  ''
set :branch,      'master'

task :environment do
  invoke :'rbenv:load'

desc "Deploys the current version to the server."
task :deploy => :environment do
  deploy do
    invoke :'git:clone'
    invoke :'bundle:install'
    queue "#{bundle_prefix} jekyll build"

Pretty straightforward. Declare ssh domain and user, deployment directory, repository to pull from (master branch). Prepare the rbenv environment (loads .ruby-version file) and actual deploy process.

Nginx configuration

First you'll need to create /etc/nginx/sites-available/ and /etc/nginx/sites-enabled/ folders. I like this approach because you can easily symlink/unlink website configurations. Add following line to /etc/nginx/nginx.conf:

# /etc/nginx/nginx.conf
# ...
include /etc/nginx/sites-enabled/*;
# ...

Once your blog is on the server you cane create your nginx website files.

# /etc/nginx/sites-available/
server {
  listen 80 default_server;
  root /home/ali/blog/current/_site;
  index index.html
  # how long should static files be cached for
  expires 1d;

Now symlink this file:

$ sudo ln -s /etc/nginx/sites-available/ /etc/nginx/sites-enabled/


These were the steps needed to take in order to set up Jekyll blog on CentOS. It can be easily deployed via git push and mina deploy commands.

I am great fan of GitHub, but GitHub Pages is way behind of the Jekyll release. I use Jekyll's tagging plugin, its SASS feature and I don't want limit myself on using any other feature of a great blogging system.

Here's the consoleshot of the deploy logs from local machine:

comments powered by Disqus