js:void(0);

Setting Up Auto-deploy With Dokku

• dokku, and autodeploy

As a continuation to my previous post on setting up a VPS and moving away from a PaaS (like heroku), this small post goes into detail how you can get back one of the greatest features of the average PaaS: autodeploy!

This post will assume you have Dokku and letsencrypt installed already.

So, I was looking to move away from another PaaS that I was one (my last one!) from an old project. A huge pain point of using a private server is that Dokku doesn’t have any default auto-deploy support, meaning you have to pre-compile anything before you deploy. Well, every so often I look around and today I stumbled upon Wharf. What it is, is a simple way to manage Dokku apps on your server with a simplistic UI. It’s pretty ugly, but it does the basics of what you need - add/remove env variables, force a deploy, and look at deploy logs.

Lets look at how to set up Wharf. At the time of writing, it’s pretty simple:

Install some pre-requisite dokku plugins:

Set up the Wharf app:

Deploy Wharf to your server:

Once Wharf is deployed, you can go to http://my-server.tld (or whatever your server domain/ip is) to log into Wharf for the first time. I’ll be using http://my-server.tld as an example for the next section as well, so be sure to replace it with your server or ip!

Next, you can set the app to auto-deploy from github:

Now the app will auto deploy! If you don’t need to pre-compile your app, this will be sufficient for you. However, if you’re using typescript and don’t want the overhead of using ts-node in production, you have a little more work to do. So, just a few more steps to go for that:

First, create an app.json in the root of your repository. It should look something like this:

{
  "scripts": {
    "dokku": {
      "predeploy": "npm run build:server && npm run setup"
    }
  }
}

In my case, npm run build:server will call tsc and do some other things. npm run setup will seed the database and do whatever I need to do. The reason why this is done is so Wharf will compile and then send the updated server code to your Dokku app.

That should be all you need to do to get auto deploy to Dokku working! 🎉

comments powered by Disqus