KamalOps
Reusable helpers and mix kamal.* Mix tasks for operating Kamal
deployments from Elixir projects.
Tasks
mix kamal.remote [--env NAME] [--app APP]mix kamal.migrate [--env NAME]mix kamal.seeds [--env NAME] [--app APP]mix kamal.secrets.check [--env NAME]mix kamal.db.psql [--env NAME] [--db-accessory NAME]mix kamal.db.query [--env NAME] [--db-accessory NAME] "SQL..."mix kamal.db.tunnel [--env NAME] [--db-accessory NAME] [--port 5432] [--ssh-opts \"...\"] [--role ROLE]mix kamal.db.url [--env NAME] [--db-accessory NAME] [--port 5432] [--print-url] [--with-password]
Conventions
-
Deploy config is read from
config/deploy.yml. -
With destinations (
--env NAME), deploy config is read fromconfig/deploy.ymlandconfig/deploy.NAME.ymland deep-merged (destination overrides base). -
Secrets follow Kamal destination semantics:
-
default:
.kamal/secrets -
named env:
.kamal/secrets.NAMEif present, otherwise.kamal/secrets-common
-
default:
Installer (Igniter)
If your project uses Igniter, you can run:
mix igniter.install kamal_ops
The installer:
-
ensures
/.kamal/secrets*are ignored in.gitignore(so secrets aren't accidentally committed) -
installs
kamal_opsas a dev-only, non-runtime dependency by default (only: :dev,runtime: false)
If you pass --init, it will:
-
check that the
kamalexecutable exists on your system (fails if missing) -
ask for (or use)
--host, then scaffold a minimalconfig/deploy.ymlthat should be close to a working setup
Example:
mix igniter.install kamal_ops --init --host 1.2.3.4
If the installer detects Postgres usage (heuristic: common deps like postgrex, ecto_sql, ash_postgres),
it will also scaffold a Postgres accessory and generate POSTGRES_PASSWORD and DATABASE_URL in .kamal/secrets.
You can force/disable this with --db / --no-db.
If you pass --example, it will also scaffold:
config/deploy.ymlandconfig/deploy.prod.yml(a minimal YAML structure to get to a working Kamal setup fast).kamal/secretsand.kamal/secrets-common(empty secret files; still ignored by git)
Minimal Kamal Setup (Single Server)
For a "hello world" Kamal setup, you usually only need:
- a server IP (or hostname)
-
SSH access (Kamal defaults to connecting as
rootif you omitssh.user)
The scaffolded config/deploy.yml uses Kamal's "local registry" (registry.server: localhost:5000)
so you can avoid setting up an external Docker registry account on day 1.
Installation
If available in Hex, the package can be installed
by adding kamal_ops to your list of dependencies in mix.exs:
def deps do
[
{:kamal_ops, "~> 0.1.0"}
]
endDocumentation can be generated with ExDoc and published on HexDocs. Once published, the docs can be found at https://hexdocs.pm/kamal_ops.