The dokku-push action requires an SSH key with push access to the Dokku instance. Here's how to do that.
Replace APPNAME
with the name of the app (e.g. this is a good idea to use the same name used on Dokku's).
We want each repo to have its own SSH key, so it's easier to rotate/invalidate them if required, without affecting all the repos. Let's generate a new key on your computer (see GitHub help):
mkdir -p ~/.ssh/github-actions/
ssh-keygen -t rsa -b 4096 -N "" -C "dokku-deploy@APPNAME" -f ~/.ssh/github-actions/dokku-deploy_APPNAME
We usually create a secure note in our shared 1Password vault, and attach both keys (private + public) as well as any additional details required.
This will allow this SSH key to be used to deploy to Dokku. If you're already an admin user on Dokku and can connect to SSH, you can directly add the new key like this (see Dokku help):
cat ~/.ssh/github-actions/dokku-deploy_APPNAME.pub | ssh [email protected] -p 22 sudo dokku ssh-keys:add dokku-deploy_APPNAME
Finally, we provide the GitHub Action with the private SSH key, via GitHub Secrets (see GitHub help).
Copy the contents of the private key to your clipboard:
pbcopy < ~/.ssh/github-actions/dokku-deploy_APPNAME
Then head over to https://github.com/{user}/{repo}/settings/secrets/, and add a new secret named SSH_KEY
, with the contents of the private key which should be in your clipboard.
Now you're done. Set up the GitHub Action (see https://github.com/marketplace/actions/push-to-dokku), using the SSH key from GH Secrets. Customize the parameters in green:
name: 'Deploy to Dokku'
on:
push:
+ branches: [ develop ]
env:
+ DOKKU_REPO: 'ssh://[email protected]:22/appname'
+ DOKKU_DEPLOY_BRANCH: 'develop'
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Cancel Previous Runs
uses: styfle/[email protected]
with:
access_token: ${{ github.token }}
- name: Cloning repo
uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Push to dokku
uses: obrassard/[email protected]
with:
ssh_key: ${{ secrets.SSH_KEY }}
dokku_repo: ${{ env.DOKKU_REPO }}
deploy_branch: ${{ env.DOKKU_DEPLOY_BRANCH }}