Command reference

On this page

Every command that talks to a node takes --json, --key FILE or env:NAME, and exits with a code that says what happened. This page is built from the command-line usage and the task docs in the source.

The hotcode command

A stand-alone command for what does not need your project: sign, push, inspect and roll back. It ships in the CI image (Deploying from CI). build and deploy compile your code, so they stay Mix tasks.

  hotcode describe ENVELOPE|MANIFEST.json [--json]
  hotcode sign ENVELOPE --key FILE|env:NAME [--yes] [--json]
  hotcode push ENVELOPE TARGET [--key FILE|env:NAME] [--dry-run] [--local] [--wait-for-old-code 60s] [--cookie C|env:NAME] [--cacert PEM] [--json]
  hotcode push ENVELOPE --targets FILE|- | --target URL[,KEY=VALUE...] ... | --targets-cmd CMD --key FILE|env:NAME
    [--canary N] [--canary-match KEY=VALUE ...] [--soak 5m] [--max-parallel N] [--max-failures N] [--health-url URL] [--health-timeout 30s]
    [--group-by KEY] [--group-order V1,V2] [--rollback-file F | --no-rollback] [--wait-for-old-code 60s] [--dry-run] [--cacert PEM] [--json]
  hotcode rollback TARGET --key FILE|env:NAME [--local] [--cookie C|env:NAME] [--out F | --file F] [--json]
  hotcode status TARGET [--spread] [--key FILE|env:NAME] [--cookie C|env:NAME] [--cacert PEM] [--json]
  hotcode status --targets FILE|- | --target URL ... | --targets-cmd CMD --key FILE|env:NAME [--json]
  hotcode wait TARGET [--done | --halted] [--timeout 30m] [--interval 5s] [--key ...] [--cookie ...] [--json]
  hotcode promote TARGET --key FILE|env:NAME [--version V] [--out F | --file F] [--cookie ...] [--json]
  hotcode resume TARGET --key FILE|env:NAME [--version V] [--out F | --file F] [--cookie ...] [--json]
  hotcode gen-key NAME [--dir DIR]

TARGET is https://host:4747 or a node name (app@host). Building a patch runs in your
project: mix hotcode.build TARGET --out patch.hcp (or --manifest manifest.json, saved with
mix hotcode.manifest when the release was built). --targets pushes to a fleet of nodes that
are not an Erlang cluster, one by one: canary, soak, health checks, undo on failure.

--cacert PEM (or HOTCODE_CACERT) trusts a private CA for https; HOTCODE_COOKIE, HOTCODE_CLI_HOST
configure distribution.

exit codes: 0 ok, 2 usage, 3 node unreachable, 4 refused, 5 roll failed (wait: halted),
6 wait timed out with the spread still going, 1 other

Mix tasks

task what it does
mix hotcode.gen_key Generates an Ed25519 signing key for deploys
mix hotcode.build Builds an unsigned patch envelope against a live node or a saved manifest
mix hotcode.sign Adds your signature to a patch envelope
mix hotcode.push Uploads a signed patch envelope to a running node/cluster, or to a fleet
mix hotcode.deploy Build, sign and push in one step (single-signer setups)
mix hotcode.rollback Reverts the last hot deploy (needs the same signers as a deploy)
mix hotcode.status Shows the hot-deploy history of each node
mix hotcode.wait Waits for a release to finish spreading (or to halt)
mix hotcode.promote Signs the end of the canary phase (releases built with --require-promote)
mix hotcode.resume Signs the resume of a halted spread
mix hotcode.describe Prints what a patch envelope authorizes (or what a saved manifest describes)
mix hotcode.manifest Saves what a release will run, so patches can be built without reaching a node
mix hotcode.check Runs the Hotcode Credo rules on your code (hot-deploy mistakes)
mix hotcode.credo.install Adds the Hotcode rules to your .credo.exs
mix hotcode.install Installs Hotcode in your project (with Igniter)

mix hotcode.gen_key

mix hotcode.gen_key NAME [--dir DIR] [--force]

Writes DIR/NAME.key (private, mode 0600) and DIR/NAME.pub, and prints the public key to put in config :hotcode, trusted_keys:. It never overwrites NAME.key; it refuses to overwrite an existing NAME.pub (which may be the public half of a key someone else holds) unless --force is given.

The private key is what authorizes running code on your servers. Keep it off the servers; in CI keep it in the secret manager and read it with --key env:NAME; prefer a hardware token or an encrypted disk for people's keys, and use threshold: 2 so one stolen key is not enough.

mix hotcode.build

mix hotcode.build TARGET --out patch.hcp [--key FILE] [--force] [--ttl-minutes 15] [--requires VERSION] [--auto-rollback-after 120s [--auto-rollback-attempts N]] [--json] mix hotcode.build --manifest manifest.json --out patch.hcp [--audience NAME] [...]

Compiles, asks the node what it runs, and writes the smallest patch as an envelope bound to that node's audience, its current code (base) and a 15-minute validity window. It carries no signatures yet: pass it around with mix hotcode.sign until threshold people have signed, then mix hotcode.push.

--manifest FILE builds against a manifest saved when the release was built (mix hotcode.manifest) instead of asking a node, so the build needs no route to production. The audience comes from the manifest (--audience overrides it). The node still checks the patch against what it actually runs: if the manifest does not describe it (another release, a patch deployed since), the deploy is refused (:base_mismatch), nothing is loaded.

--restart-app my_app (repeatable) records that the signers accept restarting that application IN PLACE (never the node) so changes to its Application.start/2, @on_load or NIF modules can apply. The node's operator must also list it in config :hotcode, allow_app_restart:. Workers keep their state and open sockets.

--accept-major APP (repeatable) records that the signers accept a semver-major bump, a downgrade or a non-semver version of that application (usually a dependency). Without it the node refuses such a patch.

--requires VERSION (repeatable) makes the patch refuse to apply on a node, and a cluster roll refuse to start, unless that earlier release is live on EVERY node (a --local push or a direct deploy checks that one node only). Build the earlier release with --version NAME so the name is yours: the default version is a git short SHA, which two builds of one commit share. Use it for the release that starts writing a new message format: the one before it taught every node to read it.

--auto-rollback-after DURATION (120s, 5m; from 10 s to 24 h) puts a deadman policy inside the signed statement: on a cluster running convergence: [mode: :auto], if a reachable node has not caught up with this release that long after it was applied (and its pulls have failed), the release is undone on every node that has it. --auto-rollback-attempts N lets the undo start once the lagging nodes have made N failed catch-up attempts. Co-signers see it as an AUTO-ROLLBACK: line. Without the flag the statement has no such field and nothing is ever undone automatically. See "Deadman rollback" in the clusters guide.

--rollout-soak 60s (with --rollout-canary N, --rollout-canary-match KEY=VALUE (repeatable: the canaries are the nodes whose metadata matches), --rollout-success 0.99, --rollout-min-canaries N, --rollout-deadline 5m, --rollout-max-unavailable 10%, --rollout-fanout N, --rollout-group-by KEY (the cap is per group of nodes sharing that metadata value), --rollout-order group_by_group|any (needs --rollout-group-by), --rollout-halt-failures 3|5%, --require-promote) puts a rollout policy inside the signed statement: on a cluster running convergence: [mode: :spread], the release is deployed to the canaries only (mix hotcode.push --canary N) and the nodes spread it among themselves within these limits. Co-signers see it as ROLLOUT: lines. The envelope must outlive the canary phase: raise --ttl-minutes for a large cluster (see "Rolling out to a large cluster").

--json prints the result as one JSON line, the last line of stdout (human text goes to stderr; Mix itself may print ==> dep lines before the task runs). Exit codes: 0 ok (also when there is nothing to deploy), 2 usage, 3 node unreachable, 4 refused (a major bump, a module the node does not allow...). See the CI guide.

--force records, inside the signed statement, that the signers accept overriding analyzer blocks. A caller cannot add it later.

mix hotcode.sign

mix hotcode.sign patch.hcp --key alice.key [--yes] [--json]

Signs the envelope in place. Each person runs this with their own key; a node with threshold: 2 needs two different signers. --key takes a file, or env:NAME to read the key from an environment variable (a CI secret).

A signature says "run exactly this code on production", so the task prints what it authorizes (audience, version, expiry, force, applications that may restart, every module it replaces or removes) and asks before signing; --yes skips the question for automation. It refuses an envelope whose statement does not match the code inside it (exit 4).

mix hotcode.push

mix hotcode.push patch.hcp TARGET [--key FILE] [--dry-run] [--local] [--cookie C] [--json] [--wait-for-old-code 60s] mix hotcode.push patch.hcp --targets FILE|- | --target URL ... | --targets-cmd CMD --key FILE [--max-parallel N] [--canary N] [--soak 5m] [--max-failures N] [--canary-match KEY=VALUE ...] [--group-by KEY] [--group-order V1,V2] [--health-url URL] [--health-timeout 30s] [--rollback-file F | --no-rollback] [--wait-for-old-code 60s] [--dry-run] [--json]

TARGET is https://host:4747 (needs --key to sign the request) or a node name (app@10.0.0.5, cookie). Whatever the transport, the node decides by the signatures inside the envelope.

--canary N and/or --canary-match KEY=VALUE (repeatable; a key given twice matches either value) deploy only to the canaries of a release whose signed statement carries a rollout policy: the nodes whose metadata (config :hotcode, metadata:) matches, those with config :hotcode, canary: true first, then by name; N of them, or every matching node without --canary. The nodes then spread it themselves; follow it with hotcode status --spread or wait for it with hotcode wait. Without the flags the default comes from the policy's canary field only when one of them is given.

--wait-for-old-code 60s (1 s to 10 minutes): before refusing a deploy because a process still runs the old version of a module the patch replaces (:lingering_old_code), each node waits up to that long for it to end. See Hotcode.Drain.

A fleet that is not an Erlang cluster

With --targets FILE (one https://host:4747 [key=value ...] per line, the pairs being the node's metadata; - reads standard input), --target URL[,key=value,...] (repeatable) or --targets-cmd CMD (a shell command that prints the list, such as one that lists ECS tasks or Fly machines), the envelope goes to each node on its own (scope: local), see Hotcode.Fleet: every target is surveyed (status and dry run) first and the ones already on the release are skipped, then --canary N targets (default 1, here NOT the spread's canaries; with --canary-match KEY=VALUE the matching targets, all of them unless --canary is given) are deployed and checked, --soak passes, and the rest follow, --max-parallel at a time (default 1): with --group-by KEY group by group of the targets' metadata, in the order they first appear or --group-order V1,V2 first. Each target is checked after its deploy: its status must list the release, and --health-url (where {host} is the target's host; a health=URL field in the file overrides it) must answer 2xx within --health-timeout. More than --max-failures failed targets (default 0; a canary failure always) halts the push and rolls back the targets it changed with a rollback signed by the same --keys, or --rollback-file F (pre-signed: needed when one key is below the threshold; checked before anything is deployed: a rollback of this release's version and audience that outlives --soak), or nothing with --no-rollback. --dry-run surveys only. One --target value is one target (no whitespace, control characters or health=); --targets-cmd runs without the signing key and cookie variables in its environment.

The result (--json) lists every target with its status: deployed, skipped, planned, failed, unknown (the request timed out: may still finish, not rolled back), not_started, rolled_back, rollback_failed. Exit codes: 0 every target is on the release (or skipped); 3 or 4 nothing was changed anywhere (every failure unreachable, or refused); 5 a target failed after the push had changed something (read targets and needs_attention).

--key takes a file, or env:NAME to read the key from an environment variable. --json prints the result as one JSON line, the last line of stdout (human text goes to stderr). Exit codes: 0 ok, 2 usage, 3 node unreachable, 4 refused (nothing changed), 5 the roll failed. See the CI guide.

mix hotcode.deploy

mix hotcode.deploy TARGET --key alice.key [--key bob.key] [--dry-run] [--force] [--local] [--json]

Equivalent to hotcode.build, hotcode.sign with every --key given, and hotcode.push. If the node requires more signers than keys you hold here, use the three tasks separately and pass the file between people.

--requires, --auto-rollback-after, --auto-rollback-attempts, --ttl-minutes and the --rollout-* flags are as for mix hotcode.build; --canary N, --canary-match KEY=VALUE and --wait-for-old-code 60s as for mix hotcode.push.

--key takes a file or env:NAME; --json and the exit codes are as for mix hotcode.push. In CI see the CI guide.

Build with the SAME OTP and Elixir as the running release (normally MIX_ENV=prod).

mix hotcode.rollback

mix hotcode.rollback TARGET --key alice.key [--key bob.key] [--local] [--cookie C] [--json]

A rollback is a signed statement naming the version it undoes, with the same signature threshold, audience, expiry and replay rules as a deploy. One stolen key cannot undo a deploy that needed two people. For a two-person rule build the statement with --out FILE, pass the file around for hotcode.sign, and send it with --file FILE.

Exit codes: 0 ok, 2 usage, 3 node unreachable, 4 refused, 5 failed. See the CI guide.

mix hotcode.status

mix hotcode.status TARGET --key FILE [--cookie C] [--spread] [--json] mix hotcode.status --targets FILE|- | --target URL ... | --targets-cmd CMD --key FILE [--json]

--spread shows, instead of every node's history, the spread of a release as that one node sees the cluster (Hotcode.Spread.status/0, one call however large the cluster): its phase, the count of nodes per role (and per group, when the policy has group_by), the canaries' health, failures, whether it halted, and a rough time left.

With a target list (as for mix hotcode.push --targets, see Hotcode.Fleet), each node of a fleet that is not an Erlang cluster is asked on its own: one line per node with its version and history (targets in the JSON). Exit 3 when any of them could not be reached.

Exit codes: 0 ok, 2 usage, 3 node unreachable, 4 refused. See the CI guide.

mix hotcode.wait

mix hotcode.wait TARGET [--done | --halted] [--timeout 30m] [--interval 5s] [--key FILE] [--cookie C] [--cacert PEM] [--json]

Asks one node, every --interval (default 5 s, at least 1 s), how the spread of a release looks from there (Hotcode.Spread.status/0), until it is final or --timeout (default 30 m, at most 24 h) runs out. A CI job deploys to the canaries (mix hotcode.push --canary N) and then runs this, instead of driving every node itself.

--done (the default) waits for every reachable node to run the release:

  • 0: done (nodes that failed and rolled themselves back are listed in failed)
  • 5: the spread halted (too many failures, or a canary missed its deadline); the JSON detail says why, and whether the release was undone (undone)
  • 6: the time ran out and the spread is still going: nothing failed, nothing is final

--halted is for a watcher that reacts to a halt: 0 when the spread halts, 6 when the time runs out or the spread finished without halting (the JSON detail.phase says which).

2 usage, 3 the node cannot be reached (a node that stops answering after the first poll is asked again until the timeout). The last line of stdout is the JSON result with --json.

mix hotcode.promote

mix hotcode.promote TARGET --key alice.key [--key bob.key] [--version V] [--out FILE | --file FILE] [--cookie C] [--cacert PEM] [--json]

For a release built with --require-promote: its canaries pass their soak, then wait for this signed statement before they become spreaders. It names the release (--version, default the one the node is spreading, and the seq of its deploy statement), needs the same signature threshold as a deploy, and expires like one. The node verifies it, then forwards it to every canary it sees, and each of them verifies it again.

For a two-person rule build it with --out FILE, pass the file around for hotcode.sign, and send it with --file FILE.

Exit codes: 0 ok, 2 usage, 3 node unreachable, 4 refused. See the CI guide.

mix hotcode.resume

mix hotcode.resume TARGET --key alice.key [--key bob.key] [--version V] [--out FILE | --file FILE] [--cookie C] [--cacert PEM] [--json]

For a release whose spread HALTED (too many failed nodes, or a canary missed its deadline) and was not undone: a signed statement that lets it go on. It names the release (--version, default the one the node is spreading, and the seq of its deploy statement), needs the same signature threshold as a deploy, expires like one, and cannot be replayed (each node keeps the seq of the last resume it applied). The node verifies it and, under the roll lock on every reachable node, delivers it to all of them, each verifying it again. Failures said before it no longer count, and each failed node is retried once.

Refused (exit 4) once the release was undone (:undone), while an undo holds the lock ({:busy, :roll_lock}: run it again), when it is not halted, or for another release.

For a two-person rule build it with --out FILE, pass the file around for hotcode.sign, and send it with --file FILE.

Exit codes: 0 ok, 2 usage, 3 node unreachable, 4 refused. See the CI guide.

mix hotcode.describe

mix hotcode.describe patch.hcp [--json] mix hotcode.describe manifest.json [--json]

Audience, version, expiry, applications that may restart, every module it replaces or removes, the OTP and Elixir it was built with, and how many signatures it has. A CI job runs this before signing so the log records what the signature authorized.

Given a manifest (mix hotcode.manifest, or a node's /manifest saved as JSON), it prints where it comes from, the audience and allowed_prefixes, the OTP and Elixir versions, MIX_ENV, the release, and how many applications and modules it lists.

mix hotcode.manifest

mix hotcode.manifest --out manifest.json [--release _build/prod/rel/my_app] [--audience NAME] [--allowed-prefix MyApp ...] [--json]

Writes the manifest of a build: every module's MD5 and code digest and its application, the application versions, the OTP and Elixir versions, MIX_ENV, and the audience and allowed_prefixes the nodes run with. Run it where the release is built (the same step, the same image), keep the file next to the release, and later build patches against it with mix hotcode.build --manifest manifest.json, from a CI job that cannot reach production.

--release DIR reads an assembled release (mix release): DIR/lib/*/ebin and the consolidated protocols in DIR/releases/VSN/consolidated, exactly what the node will boot. Without it the task compiles the project and reads _build/MIX_ENV, which also contains dependencies a release leaves out (runtime: false); prefer --release.

audience and allowed_prefixes come from --audience and --allowed-prefix (repeatable), else from config :hotcode as Mix loads it (config/config.exs and the environment's file), else from config/runtime.exs if it can be read here. Without an audience the task stops (exit 2): a patch is bound to the audience it is built for.

The node does not trust the manifest: it checks the patch's base code, OTP release, audience, policy and signatures against what it runs. A stale manifest makes it refuse the patch; it cannot make it load anything else. hotcode describe manifest.json prints a summary.

Exit codes: 0 ok, 2 usage (a missing audience, an unreadable release). See the CI guide.

mix hotcode.check

mix hotcode.check [credo options] [paths]

Runs Credo with the Hotcode rules (Hotcode.Credo) and nothing else. Which files are read (files: %{included: ..., excluded: ...}) comes from the default configuration in your own .credo.exs; --strict, --format json, paths and every other Credo option pass through.

mix hotcode.check
mix hotcode.check --strict --format json lib/
mix hotcode.check --all           # your own configuration and checks too, plus Hotcode's

It needs no change to your configuration: the rules are added for this run, whatever your checks: section says. To have them in every mix credo run, install them once with mix hotcode.credo.install.

--all is this task's flag, not Credo's: it runs your whole configuration with the rules added (a checks: %{enabled: [...]} list in it replaces the plugin's, see the Credo rules guide).

The exit status is Credo's: 0 when nothing was found, 16 when a rule found something (so a CI step fails), other values as in mix credo --help; 2 when Credo is missing from your project: {:credo, "~> 1.7", only: [:dev, :test], runtime: false}.

mix hotcode.credo.install

mix hotcode.credo.install [--path .credo.exs]

Adds {Hotcode.Credo.Plugin, []} to the plugins of your Credo configuration, so every mix credo run includes the Hotcode rules:

  • no .credo.exs: one is written (Credo's defaults plus the plugin);
  • a .credo.exs with a plugins: [...] list: the plugin is added to it;
  • already installed: nothing changes;
  • any other shape: the file is left alone and the line to add is printed. It never rewrites a configuration it does not recognise.

Credo itself is a dependency of yours, not of Hotcode: {:credo, "~> 1.7", only: [:dev, :test], runtime: false}.

mix hotcode.install

Installs Hotcode in a project:

mix igniter.install hotcode

(or, when :hotcode is already a dependency, mix hotcode.install). It

  • adds config :hotcode to config/runtime.exs for :prod: the audience (--audience, default "prod"), allowed_prefixes (your application's module prefix, plus MyAppWeb for a Phoenix application and the first segment of every other top-level defmodule under lib/ that no other application owns, each named in a notice), store_dir (--store-dir, default /var/lib/<app>/hotcode) and threshold: 1;
  • adds Credo to your dev and test dependencies and the Hotcode rules to .credo.exs (--no-credo to skip), see mix hotcode.check;
  • on Elixir 1.17, adds jason (Hotcode reads JSON with it where JSON does not exist).

It does not invent a signing key: a node with no trusted_keys refuses every deploy. Generate one with mix hotcode.gen_key NAME and add its public half to trusted_keys.

Options

  • --audience NAME, the environment's name that every signed patch must carry
  • --threshold N, how many different signers a deploy needs (default 1: use 2 when it matters)
  • --store-dir PATH, where applied patches, the replay counter and the audit log live
  • --no-credo