Notes to self

How to use a remote build server with Kamal

How and when to create an external build server for your Kamal deploys?

Remote build server

What’s a remote builder anyways? Kamal will build your Docker images locally by default (on your laptop or anywhere you run the kamal command), but you can choose to do the build on a different host by specifying the builder’s remote connection:

# config/deploy.yml
builder:
  arch: amd64
  cache:
    type: gha
  remote: ssh://root@164.92.229.121

Note that Kamal will continue to do local builds as long as the architecture of the local host matches your arch settings. To force a remote build set local to false:

# config/deploy.yml
builder:
  local: false
  remote: ssh://root@164.92.229.121

This way you’ll always build on the remote host when creating a new build:

$ kamal build create
$ kamal build push

Kamal expectations

Kamal doesn’t do anything else with the build server beyond submitting your build requests. This means you’ll need to install Docker at the very least:

# on the build server
curl -fsSL https://get.docker.com | sh
systemctl enable docker
systemctl start docker

Kamal will use the connection specified in builder’s remote settings and ignore any SSH user settings you might have. You need to set it up yourself if needed.

When to use remote server

Powerfull build servers can significantly improve the build times of your application. I would consider them if you or someone on your team cannot build the application in acceptable time and/or your current CI system is slow. Your CI system might also offer more powerful runners which would be an alternative to setting up your specialized build server.

Check out my book
Learn how to use Kamal to deploy your web applications with Kamal Handbook. Visualize Kamal's concepts, understand Kamal's configuration, and deploy practical life examples.
by Josef Strzibny
RSS