Skip to content

The cairn.toml reference ​

cairn.toml describes one app: where its image comes from, how big its machine is, what it publishes, what it mounts, and how it is checked and restarted. It sits in the project directory and cairn deploy reads it. Only two keys are required: app and either image or [build].

The parser is strict. An unknown key is an error that names the key and its line, and a key from another tool that cairn deliberately does not support is refused by name (see Refused keys).

A first manifest ​

toml
app = "hello"
image = "docker.io/library/nginx:1.27"

[[services]]
internal_port = 80
  [[services.ports]]
  port = 8080

cairn deploy --dry-run prints how cairn resolved a manifest, with every default filled in, without changing anything. Use it whenever you edit the file.

A fuller example using most of the file:

toml
version = 1
app = "notes"
image = "docker.io/library/postgres:17-alpine"
kill_signal = "SIGINT"
kill_timeout = "30s"
env_file = "db.env"                        # POSTGRES_PASSWORD=...

[vm]
cpus = 2
memory = "1gb"

[env]
PGDATA = "/var/lib/postgresql/data/pgdata"

[network]
allow = ["pypi.org", "*.pythonhosted.org"]

[[mounts]]
source = "pgdata"
destination = "/var/lib/postgresql/data"
initial_size = "2gib"

[[services]]
internal_port = 5432
  [[services.ports]]
  port = 5432

[checks.db]
tcp = 5432
on_failure = "restart"

[restart]
policy = "on-failure"
max_restarts = 5

[deploy]
restore_previous = "always"

Overview ​

Key or tablePurposeRequired
versionSchema versionno
appThe app's nameyes
image / [build]Where the image comes from; exactly oneyes
builderpodman or dockerno
[vm]CPUs, memory, disk, balloon, kernelno
[processes]The command to runno
[env] / env_fileThe workload's environmentno
[network]NAT or off, network name, DNS, egress allowlistno
[[services]]Ports the workload serves: reachable by peers, published on the hostno
[checks.<name>]Health checksno
[restart]Restart policyno
[[mounts]]Persistent volumesno
kill_signal, kill_timeoutHow the workload is asked to stopno
[deploy]What a failed deploy of an app with volumes doesno

There is no [kernel] table. The kernel is chosen with keys in [vm].

Sizes and durations follow the same grammar everywhere:

  • Sizes are a number and a unit: m/mb/mib (MiB), g/gb/gib (GiB), t/tb/tib (TiB), case-insensitive, all binary multiples, for example 512mb, 2gb, 1tib. A bare number is an error, as is zero.
  • Durations are digits and a unit: 500ms, 10s, 2m, 1h. A bare number is an error.

version ​

toml
version = 1

Integer, optional. The schema version this build reads, which is 1. Any other value is refused. Leave it out unless you want the file to say which schema it was written for.

app ​

toml
app = "shop"

String, required. 1 to 48 characters of a-z, 0-9 and hyphens, with no hyphen at either end. It names the app everywhere (cairn status shop) and, unless you set [network] name, the app's network.

image and build ​

Give exactly one of image or [build]. Giving both, or neither, is an error.

image ​

toml
image = "docker.io/library/nginx:1.27"

String. An OCI image reference. Cairn pulls it when it is not cached; cairn deploy --pull pulls it again.

builder ​

toml
builder = "podman"

String, optional: podman or docker. It chooses the tool used both to pull and to build. When absent, cairn tries podman, then docker.

build ​

Build the image from a Dockerfile in the project instead of pulling one.

toml
app = "api"

[build]
dockerfile = "Dockerfile"
context = "."
target = "runtime"
no_cache = false

[build.args]
VERSION = "${VERSION:-dev}"
KeyTypeDefaultMeaning
dockerfilestringnone (required)Path to the Dockerfile, relative to the project directory.
contextstring"."The build context, relative to the project directory.
targetstringnoneThe Dockerfile stage to build.
no_cacheboolfalseBuild without the cache.
argstable of stringsnoneBuild arguments (ARGs). Values are templates.

Both paths must be relative and stay inside the project: an absolute path, a .. that leaves the project, or a symlink that leads outside is refused. The args names must be POSIX names (letters, digits and _, not starting with a digit).

A build argument is not a secret mechanism. A RUN that uses it is recorded in the image's history, and other local users can see it on the builder's command line while the build runs.

vm ​

The machine's size, balloon and kernel. Every key is optional.

toml
[vm]
cpus = 2
memory = "1gb"
rootfs_size = "4gb"
balloon = true
kernel = "6.1.155"
KeyTypeDefaultMeaning
cpusinteger1Virtual CPUs, 1 to 32.
memorysize512mbGuest RAM, at least 128mb. This is the ceiling the guest sees, not a reservation: the host allocates pages as the guest touches them.
rootfs_sizesize2gbRoot filesystem size, at least 64mb. It is a sparse file, so unused space costs nothing.
balloonbooltrueGive memory the guest frees back to the host (best effort; page cache and free blocks under 128 KiB stay). Set false for a workload that frees and reallocates large buffers.
kernelstring"6.1.155"The name of a kernel cairn knows. Only 6.1.155 exists today.
kernel_filestringnoneAn uncompressed x86_64 ELF vmlinux, relative to the project.
kernel_sha256stringnoneThe sha256 kernel_file must have: 64 lowercase hex digits. Only valid with kernel_file.
jailstring"require"Only "require" is accepted in a file.

Notes:

  • kernel and kernel_file are mutually exclusive. kernel_sha256 without kernel_file is an error.
  • kernel_file must stay inside the project, including through symlinks (use relative links; absolute symlinks are refused). The file need not exist for --dry-run. At deploy it is checked and imported into $CAIRN_HOME/kernels/custom/<sha256>. See kernels for what a custom kernel must contain.
  • cairn deploy --cpus, --memory, --rootfs-size and --kernel-file override the file. The kernel flag replaces all three kernel keys, so the file's kernel_sha256 is not applied to a file chosen on the command line.
  • A deploy of a changed memory, cpus or rootfs_size creates a new machine, as any deploy does.

processes ​

The command the workload runs, replacing the image's ENTRYPOINT and CMD.

toml
[processes]
app = ["postgres", "-c", "fsync=on"]

A table with exactly one entry. The key is only a label; the value is an array of strings, the program first. This build runs one process, so two entries are an error. Leave the table out to run the image's own ENTRYPOINT plus CMD.

The program is an absolute path or a bare name looked up on the image's PATH; a relative path with a slash (bin/app) is refused. There is no shell and no $ expansion: for variables or shell syntax run a shell yourself, ["/bin/sh", "-c", "exec app --password \"$DB_PASSWORD\""].

env ​

Environment variables for the workload.

toml
[env]
LOG_LEVEL = "info"
DATABASE_URL = "postgres://shop:${DB_PASSWORD}@db.internal:5432/shop"
API_TOKEN = "${API_TOKEN:?create one at https://example.test/tokens}"
REGION = "${REGION:-eu-west-1}"

A table of strings. Names must be POSIX names. Values are templates: ${NAME} is replaced from your shell or a variable file at deploy time. A value may not contain a NUL byte. HOSTNAME defaults to the app name when nothing sets it.

The workload's environment, lowest to highest priority, is: the image's own Env, each env_file in order, then [env].

env_file ​

toml
env_file = "secrets.env"
# or
env_file = ["base.env", "secrets.env"]

A path or an array of paths, relative to the project directory. Every NAME=value line in each file goes into the workload's environment. This is how to pass a credential without writing it in cairn.toml.

  • Each file must exist, be a regular file, stay inside the project, and be at most 1 MiB.
  • A path listed twice is an error.
  • References inside an env_file look in the same variables as ${} templates (see below), then the file's own earlier lines, then earlier env_files. An env_file never sees [env].
  • Names must be POSIX names. Lines that are not valid are refused with their line number.

Add .env and every file you name in env_file to .gitignore. Cairn does not look at git.

Variables and templates ​

cairn.toml is committed, so a credential must never be written in it. Name the value instead, as Docker Compose does. Templates are expanded in [env] values and [build] args values, and nowhere else.

Where a ${NAME} comes from ​

First match wins:

  1. The environment of the cairn deploy process.
  2. The variable files, a later file beating an earlier one. That is <project>/.env when it exists, or, when you pass --env-file PATH (repeatable, in order, each must exist), those files instead; .env is then not read.

A variable file's own references look in the environment, then its earlier lines, then earlier files. Names in .env are read for ${...} only and never reach the workload; use env_file for that.

sh
export API_TOKEN=tok-123
cairn deploy --dry-run                          # templates, names and origins; never values
cairn deploy
cairn deploy --env-file ~/secrets/shop.prod.env # instead of .env

The template grammar ​

Compose's grammar: $NAME, ${NAME}, and the operators below, which may be nested.

FormMeaning
${NAME}The value; an error if unset.
${NAME:-default}The value, or default when unset or empty.
${NAME-default}The value, or default when unset.
${NAME:+word}word when set and non-empty, else empty.
${NAME+word}word when set, else empty.
${NAME:?message}The value; an error printing message when unset or empty.
${NAME?message}The value; an error printing message when unset.
$$A literal $.

Rules to know:

  • $$ in either TOML quoting. A TOML literal string ('...') does not turn interpolation off. In [env] and [build] args write $$ for a literal $. (In a .env file, single quotes are literal.)
  • A {} in a default works alone (${X:-{}}) but swallows the next } on its line, so ${A:-{}}${B} is refused. Put such a default in a variable, or write { }.
  • A ${ must be followed by a name; an unclosed ${ is an error.
  • Stricter than Compose. An unset variable with no default is an error, not a blank (write ${NAME:-} for an empty one). A reference is checked whatever is set, so a typo never depends on your environment. In a variable file, a malformed line, a bare NAME line (write NAME=${NAME} to pass one through), an octal escape, a NUL byte, non-UTF-8 text and a name that is not [A-Za-z_][A-Za-z0-9_]* are all refused with the line number.
  • Limits. 131072 bytes per variable (with its name and NUL), 1 MiB per variable file, templates nested at most 16 deep, and 1 MiB for the command and environment together.

What cairn prints ​

Plans, dry runs, JSON, warnings, errors and progress never contain a value that came from the environment, .env, --env-file or an env_file. --dry-run lists the variables a deploy reads and where each is set, never the value. This does not cover the image builder's output, the workload's console and logs, or a literal committed in cairn.toml. Review the dry run's variables row before deploying someone else's project.

Changing a value is a deploy ​

The resolved environment is stored in the machine's spec. A restart, cairn start and systemd never read your shell, .env or an env_file again. To rotate a secret, change it and cairn deploy.

network ​

toml
[network]
mode = "nat"
name = "backend"
dns = ["1.1.1.1", "9.9.9.9"]
allow = ["pypi.org", "*.pythonhosted.org", "140.82.112.0/20"]
KeyTypeDefaultMeaning
modestring"nat""nat" gives the machine a NAT-ed network; "off" gives it no network device at all.
namestringthe app's nameThe network to join. 1 to 32 lowercase letters, digits and inner hyphens, starting with a letter. Several apps can join one network; they reach each other as <app>.internal.
dns"host" or array"host""host" uses the host's resolvers; an array of 1 to 3 IPv4 resolver addresses uses those. Private and special-use addresses are refused.
allowarray of stringsnone (no filtering)The egress allowlist. With it, the machine reaches only what is listed.

Rules:

  • With mode = "off", name, dns and allow are errors (there is nothing to apply them to).
  • allow and an array dns cannot be combined: under an allowlist all DNS goes through the host's resolvers.
  • cairn deploy --network, --network-mode, --dns and --allow override the file.

Allow list entries ​

Each entry is one of:

  • A name, pypi.org: HTTPS (443) and HTTP (80) to that name.
  • A wildcard, *.pythonhosted.org: the same, for any name ending in the zone. It does not cover the bare pythonhosted.org; list that too.
  • An IPv4 address or range, 8.8.8.8 or 140.82.112.0/20: everything at those addresses, on every port.

At most 256 entries. A URL, a port (host:443) or an IPv6 address is refused, as are a duplicate entry and overlapping ranges. allow = [] allows nothing at all. An empty list is not the same as leaving allow out, which means no filtering. The limits and behaviour of the gate (what DNS types are answered, what a wildcard trusts) are in networking.

services ​

Declare the ports the workload serves, and publish them on the host.

toml
[[services]]
internal_port = 80          # the port the workload listens on
protocol = "tcp"            # "tcp" (default) or "udp"

  [[services.ports]]
  port = 8080               # the host port
  bind = "127.0.0.1"        # default
KeyTypeDefaultMeaning
internal_portintegerrequiredThe guest port, 1 to 65535.
protocolstring"tcp""tcp" or "udp".
portsarray of tablesnoneThe host ports to publish this service on.
ports.portintegerrequiredThe host port, 1 to 65535.
ports.bindstring"127.0.0.1"The host IPv4 address: 127.0.0.1, 0.0.0.0 (every address) or one of the host's unicast addresses.

Rules:

  • Each (protocol, internal_port) may appear once.
  • A host (protocol, port) can be published only once in the whole file, whatever the bind.
  • A service with no ports is reachable by peers only: other apps on the same network reach it as <app>.internal:<internal_port>, and the host does not. Every declared service is reachable by peers, whether or not it has ports. Every TCP service's internal_port is also what the readiness gate waits for: before a deploy accepts the new machine, each of those TCP ports must accept connections (UDP ports are not checked).
  • 127.0.0.1 is reachable only from the host. Use 0.0.0.0 or an address to expose the port to others. See networking.

checks ​

Health checks run inside the guest after boot and feed cairn status and cairn ps.

toml
[checks.web]
http = "/healthz"
port = 8080
status = [200, 204]
interval = "10s"
timeout = "2s"
grace = "30s"
failures = 3
on_failure = "report"

[checks.db]
tcp = 5432

[checks.job]
exec = ["sh", "-c", "test -f /tmp/ready"]

Each [checks.<name>] table has exactly one kind and optional tuning keys. The name is 32 or fewer of a-z, 0-9 and hyphens; there are at most 8 checks.

Kinds (give exactly one):

KeyTypeMeaning
httpstringAn HTTP GET of this path, which starts with /, printable ASCII, no spaces, at most 1024 bytes. Passes on any 2xx unless status says otherwise.
tcpintegerPasses when a TCP connection to this port succeeds (1 to 65535).
execarray of stringsRuns this command in the guest; passes on exit 0. At most 64 arguments and 4096 bytes. The environment variable CAIRN_CHECK_ADDR holds the address the http and tcp checks probe: the guest's own address, or 127.0.0.1 when the network is off. It replaces any value your workload's environment has under that name.

Tuning keys:

KeyApplies toTypeDefaultMeaning
porthttpintegerthe only TCP service's portPort to probe. Required when the app has no TCP service or several.
statushttparray of integersany 2xxAccepted status codes, 100 to 599, not empty.
intervalallduration10sTime between probes, 1s to 1h.
timeoutallduration2s (or the interval if shorter)Probe deadline: 100ms or more, and not longer than interval.
graceallduration30sFailures before the first pass are not counted while the workload is younger than this; the first pass ends the grace. 0s to 15m.
failuresallinteger3Consecutive failures before the check is unhealthy, 1 to 10.
on_failureallstring"report""report" only marks it unhealthy; "restart" also restarts the machine.

on_failure = "restart" needs failures of 2 or more and cannot be used with [restart] policy = "never". How checks interact with deploys and restarts is in lifecycle.

restart ​

toml
[restart]
policy = "on-failure"
max_restarts = 5
KeyTypeDefaultMeaning
policystring"on-failure""never", "on-failure" (restart after a non-zero exit or a signal, an out-of-memory kill included) or "always" (restart after a clean exit too).
max_restartsintegernone (no limit)Give up after this many consecutive restarts without a stable run, 1 to 10000.

A failure of the VMM itself is always recovered, whatever the policy. To stop restarting after the guest's own endings use policy = "never", not max_restarts = 0 (which is an error). Backoff and the details are in lifecycle.

mounts ​

Persistent volumes: ext4 disks that belong to the app and survive redeploys. The commands to list, extend, back up and repair them, and the full story of ownership and redeploys, are in volumes.

toml
[[mounts]]
source = "pgdata"
destination = "/var/lib/postgresql/data"
initial_size = "2gib"
KeyTypeDefaultMeaning
sourcestringrequiredThe volume's name: a lowercase letter, then up to 29 lowercase letters, digits or _.
destinationstringrequiredWhere the guest sees it: an absolute, normalised path.
initial_sizesize1gibThe size when the volume is first created, 64 MiB to 1 TiB. It does nothing to an existing volume; grow one with cairn volume extend.

Rules:

  • At most 4 mounts per app. Names are unique, and two destinations may not be the same or nested.
  • destination may not be /, end in /, contain //, . or .., be one of /etc, /bin, /sbin, /lib, /lib64 or /usr (a path beneath them is fine), or be inside /proc, /sys, /dev, /run or /tmp. At deploy time cairn also refuses a destination whose path passes through a symlink in the image.
  • An app with mounts cannot run with cairn deploy --jail off.
  • A mount hides what the image has at that path and is not seeded from it. A new volume's root has lost+found; databases that want an empty directory need a subdirectory.
  • An app with volumes deploys stop-first: the old machine stops before the new one starts, so the app does not answer in between.

stopping ​

kill_signal and kill_timeout are top-level keys: place them before the first table header.

toml
kill_signal = "SIGINT"
kill_timeout = "30s"
KeyTypeDefaultMeaning
kill_signalstring or integerthe image's StopSignal, else SIGTERMThe signal sent to the workload to stop it: a name with or without SIG, a number, or SIGRTMIN+n / SIGRTMAX-n.
kill_timeoutduration string10sHow long the workload has before it is killed with SIGKILL: 1s to 300s. A bare number is an error.

SIGKILL, SIGSTOP, SIGCHLD and the job-control signals (SIGCONT, SIGTSTP, SIGTTIN, SIGTTOU) are refused. So is an image whose own StopSignal is one of them; the deploy then asks you to set kill_signal. Real-time signals use Docker's numbering (SIGRTMIN is 34). cairn stop, deploy and the systemd unit wait longer when kill_timeout is longer. --dry-run shows which signal is used and who chose it.

deploy ​

toml
[deploy]
restore_previous = "always"
KeyTypeDefaultMeaning
restore_previousstring"before-start"What happens when a deploy of an app with volumes fails after the old machine stopped. "before-start" restores the previous release only when the new release never ran against the volumes; otherwise the app is held, and nothing boots it until you run cairn start <app> --release or deploy a fix. "always" restores the previous release every time.

Use "always" only if your data changes are always backward compatible. See volumes for how the decision is made.

Refused keys ​

Some keys are recognised and refused with a sentence, so you never get a silent ignore. They are mostly spellings from other tools, or features cairn does not have.

KeyWhat the error says
[restart] max_retriesIt is max_restarts.
[vmm]Moved: use [vm] jail.
[vm] providerThere are no provider profiles; Firecracker is the only VMM.
[vm] networkMoved: use [network] name.
[vm] debug_shellNot implemented.
[vm] jail = "off"Not allowed in a file. Only cairn deploy --jail off can turn the jail off, so a project's file cannot remove the VMM's filesystem boundary.
[build] builderMoved: use the top-level builder, which applies to pulling too.
[[services.ports]] handlersNot implemented; ports are published as raw TCP or UDP.
[[mounts]] processesA Fly.io per-group key; this build runs one process.
[deploy] strategy, max_unavailable, release_command, release_command_timeout, release_command_vm, wait_timeoutFly.io keys; cairn chooses how to deploy itself. The one [deploy] key is restore_previous. Set the readiness deadline with cairn deploy --wait-timeout.
version other than 1Not supported by this build.

Any other unknown key is reported as an unknown field with the list of keys the table accepts. Checks have their own refusal: an unknown key in [checks.<name>] names the key and, for a spelling other tools use (such as path, command or start_period), points to cairn's key.

How it works ​

  • One parse, then a plan. Cairn reads the whole file once into a typed structure and reports the first error with its line. The command-line flags are then applied on top, key by key, to make the plan that --dry-run prints.
  • Nothing is printed from the environment. Values from your shell and variable files are used but never quoted by cairn. A value written in cairn.toml itself is quoted in errors, with credential-shaped text masked on a best-effort basis.
  • Paths are confined. [build] paths, kernel_file, env_file and .env may only lead to files inside the project. Cairn checks early, and opens the files in a way that a path swapped for a symlink afterwards cannot escape the project.