Deploy to Dokku using GitHub Actions

Ido Berkovich
2 min readOct 27, 2019

--

Photo by VanveenJF on Unsplash

Posted also in my personal blog.

Dokku is great. GitHub actions are great. Therefore, it only makes sense to combine these two amazing products to work together!

Deploying an app to Dokku as a part of your pipeline was never easier! Let’s see how we can have our apps deployed automatically to Dokku on certain events, in a few simple steps.

Note: At the time of writing, GitHub actions is still in beta. If you want to use it, you will need to sign up for the beta.

First step — add a workflow

Create a .github/workflow directory inside your project root and create a deploy.yml file in it. If you are new to GitHub actions, you may use the following example which deploys every time there’s a push to the master branch:

You should change dokku-host and app-name inputs to match your own Dokku app’s settings.
Do NOT change ssh-private-key to contain your private key! More on that in the next section.

There are two extra inputs that are optional:

  • dokku-user in case your dokku configuration expect a user which is different than “dokku” for git deployments
  • remote-branch in case your dokku configuration deploys from branches different than “master”

Finally, commit the file but don’t push yet!

Second step — add a private key

Your ssh private key should always remain in secret and never tracked in your git repository. In order to add the private key safely, you should add it as a secret.

Open your repository on GitHub, and navigate to Settings > Secrets:

Adding the ssh private key as a secret

Click on “Add a new secret”, name it SSH_PRIVATE_KEY and paste the contents of your private key in the value section.

If you’re not sure how to recognize your private key, it can be usually found in ~/.ssh/id_rsa file, and its content should be similar to:

-----BEGIN OPENSSH PRIVATE KEY-----
.
.
.
-----END OPENSSH PRIVATE KEY-----

Step 3 — Push the changes

Push the changes you’ve made in Step 1 to your GitHub repository and watch the deployment made automatically!

Successful deployment to Dokku using GitHub actions

That’s it!

Did you find a mistake? Please write me.
Was this post helpful? If it does, please 👏🏼
Are you using my dokku-deploy-action? Please give it a ⭐️: https://github.com/marketplace/actions/dokku-deploy-action

--

--