Using Middleman with Dokku

Warning - Old content ahead!

This page has been marked as a legacy post. This means it's quite old (from 2016) and probably out of date. Take it with a grain of salt!

I Recently started using Dokku for my websites, which has been great for using various versions of languages and frameworks and keeping different versions of dependencies separate.

I wanted to host my blog - which is a static site built with Middleman - on the same server and came accross this article which I feel is the perfect solution for most static sites, but I needed to add on to it for my own convenience with Middleman.

There's the option of using the middleman-deploy gem, but since there is a fair amount of issues with this gem I decided to try an alternate solution.

As with the previously linked article mentioned, I have made a separate nginx configuration slightly modified to work with Middleman's pretty URL option.

In my /etc/nginx/conf.d/static.conf file I have the following:

server {
  server_name ~^(?<domain>.+)$;
  root /home/static/sites/$domain;
  index index.html index.htm;
  location / {
    try_files $uri $uri/ =404;
    # this makesure pretty urls works with html files without the extension
    default_type "text/html";
    add_header X-Frame-Options SAMEORIGIN;
  }
  location ~ /\.git {
    deny all;
  }

  access_log /var/log/nginx/$domain-static-access.log;

  # error_log can't contain variables, so we'll have to share: http://serverfault.com/a/644898
  error_log /var/log/nginx/static-error.log;
}

I made sure my build directory is included in git and then pushed it to Github as a subtree.

git subtree push --prefix build origin production

In my static website directory on my server I clone the repository and switch to production.

git clone git@github.com:username/example.git
git checkout production

Below is an example of commands I can use to push changes up to production!

# Your usual git commit workflow
middleman build
git add .
git commit -m "your commit"
git push origin master
# Push update to the production build subtree
git subtree push --prefix build origin production
# SSH into your server, change into the repo directory and run git pull
echo "cd sites/example.com && git pull" | ssh static@example.com /bin/bash

After restarting nginx with sudo service nginx restart everything should work!

Spread the word

Share this article

Like this content?

Check out some of the apps that I've built!

Snipline

Command-line snippet manager for power users

View

Pinshard

Third party Pinboard.in app for iOS.

View

Rsyncinator

GUI for the rsync command

View

Comments