Automatically deploying a Kamal application when you push to Github can be a simple 3 step process:
You are likely going to need a new personal access token for DockerHub and an SSH key for deployment.
In you Docker Hub, click your profile picture in the top right corner, and navigate to the Account Settings screen, then the Personal access tokens screen. Make a new token, giving it a name for this project with read and wrote access. Take note of this new token.
In your terminal run ssh-keygen -t ed25519 -C "PROJECT_NAME-deploy". You will want to avoid adding a passphrase to the key.
The public key can be added to the server by running ssh-copy-id -i FILENAME.pub root@IP_ADDRESS.
From your Github repository, navigate to the Settings > Secrets and variables > Actions screen.
In the Repository secrets section, add a New repository secret. Name one KAMAL_REGISTRY_PASSWORD and give it the value from Docker Hub, and create a second one with the value from the private SSH key you generated.
A basic workflow file is needed:
name: deploy.yml
on:
push:
branches:
- main
jobs:
deploy:
runs-on: ubuntu-latest
env:
KAMAL_REGISTRY_PASSWORD: ${{ secrets.KAMAL_REGISTRY_PASSWORD }}
steps:
- uses: actions/checkout@v2
- uses: ruby/setup-ruby@v1
with:
ruby-version: 3.4.7
bundler-cache: true
- uses: webfactory/ssh-agent@v0.7.0
with:
ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY }}
- run: |
bundle exec kamal deploy
Now when you push to the main branch, Github will automatically build and deploy your project.