Using Middleman with Dokku - Updated

Posted on Jan 31, 2018

Middleman Dokku Static websites

In a previous blog post I explained how to set up a Middleman blog alongside Dokku. Since then I’ve found a better approach which uses middleman-deploy.

Full credit to this Github thread which pointed me to the right path.

First add your new Dokku app on your server the same way you’d set up any Dokku app.

1
dokku apps:create example-url.com

In your local version add middleman deploy to your Gemfile

https://github.com/middleman-contrib/middleman-deploy

Use these settings in your confir.rb

1
2
3
4
5
activate :deploy do |deploy|
	deploy.deploy_method = :git
	deploy.remote = '[email protected]<serverip>:example-url.com'
	deploy.branch = 'master'
end

Note that in Middleman v3 you should use method and in v4 you should use deploy_method

Make sure to add Dokku as a remote git on your local Middleman project

1
git remote add dokku [email protected]<serverip>:example-url.com

In the source dir add these two files

Procfile

1
web: vendor/bin/heroku-php-nginx -C nginx.conf

composer.json

1
{}

Running build will then put both files in the build which is where Dokku will find them.

To deploy, simply commit to git and run

1
Bundle exec middleman deploy

That's all there is to it. Except perhaps one caveat!

1
Can't deploy! Please add a remote with the name '[email protected]<serverip>:example-url.com' to your repo

There are a couple of issues at play here, and it's to do with the middleman-deploy gem. Here's the quick fix:

You will need to modify the gem code, do this either by using a git clone, and setting the path: in your Gemfile to your local version. Or (and not recommended) use bundle show middleman-deploy to get the gem location on your computer.

In the file named lib/middleman-deploy/strategies/git/force_push.rb comment out these lines

1
2
3
unless remote =~/\.git$/
	url = `git config --get remote.#{url}.url`
end

If your using the name 'dokku' instead of the full remote url in the config.rb, change the remote from dokku to the full git remote address.

Alternatively to modifying the middleman-deploy code, you can name your dokku project ending with .git.

Like this article? Sign up to updates - no spam!