How to setup Kamal?

less than 1 minute read

Note: This post has been updated on 7th Oct, 2024 to reflect the changes in Kamal 2.0.

Installation

gem install kamal

Initialization

kamal init

The above command will create 2 files

  1. .kamal/secrets
  2. config/deploy.yml

Configuration

.env

Add registry password to .env file. This can be a token from Docker Hub.

KAMAL_REGISTRY_PASSWORD=dckr_pat_*******************o

.kamal/secrets

Add the following secrets to .kamal/secrets file.

KAMAL_REGISTRY_PASSWORD=$KAMAL_REGISTRY_PASSWORD
RAILS_MASTER_KEY=$(cat config/master.key)

config/deploy.yml

<% require "dotenv"; Dotenv.load(".env") %>

service: kamal-demo
image: yourregistryusername/kamal-demo
servers:
  web:
    - 192.168.0.1

proxy:
  ssl: true
  host: example.com

registry:
  username: yourregistryusername
  password:
    - KAMAL_REGISTRY_PASSWORD

env:
  secret:
    - RAILS_MASTER_KEY
  clear:
    SOLID_QUEUE_IN_PUMA: true

volumes:
  - 'kamal_demo_storage:/rails/storage'

asset_path: /rails/public/assets

builder:
  arch: amd64

Deploy the application

kamal deploy

The above command will deploy the application to the server.