Deploying from CI
On this page
- The image
- The key lives in the secret manager
- Reaching the node
- Tailscale
- Building without reaching the node
- Several environments, several images
- Exit codes and
--json - A large cluster: deploy to the canaries, then wait
- A fleet that is not an Erlang cluster
- Fly.io machines
- ECS tasks
- Boxes behind SSH
- GitHub Actions
- One signer: build, sign, push in one job
- Two signers: CI builds, a person approves
- Argo
- What is tested, and what is not
A hot deploy is three steps, and only the first needs your code:
| step | command | needs |
|---|---|---|
| build a patch against what the node runs | mix hotcode.build TARGET --out patch.hcp |
your project, its deps, the same OTP and Elixir as production, and a route to the node (it asks the node what it runs, with a request signed by a trusted key), or a manifest saved when the release was built (Building without reaching the node) |
| sign it | hotcode sign patch.hcp --key env:HOTCODE_KEY --yes |
the patch and a private key |
| push it | hotcode push patch.hcp TARGET --key env:HOTCODE_KEY |
the signed patch and a route to the node |
hotcode is a stand-alone command: it runs without your project, so a job that only signs and
pushes does not compile anything. mix hotcode.deploy does all three in one go, in your
project, for single-signer setups.
The image
docker build -f docker/Dockerfile --build-arg ELIXIR=1.20 --build-arg OTP=29 -t hotcode-ci .
or, from the registry, one tag per OTP and Elixir pair (a release tag also gets a versioned one):
ghcr.io/<owner>/hotcode-ci:otp29-elixir1.20
ghcr.io/<owner>/hotcode-ci:0.1.0-otp29-elixir1.20
Pick the pair your release runs. A patch is compiled by the build's OTP and Elixir and
loaded by the node's. The patch records both (hotcode describe prints them); the node refuses
a patch built on another OTP release (:otp_mismatch, a block) and warns about another Elixir
(:elixir_mismatch), so a mismatch is caught, but only at deploy time, which is why the image
is built per pair. It has Elixir, Hex, Rebar and git, and hotcode on the PATH; it runs as a
non-root user (uid 10001), and its entrypoint is hotcode:
docker run --rm -v "$PWD:/work" hotcode-ci describe /work/patch.hcp
To compile your project, copy the command into your own builder image, which already has your toolchain and caches:
FROM hexpm/elixir:1.20.5-erlang-29.0-debian-bookworm-slim AS builder
COPY --from=ghcr.io/<owner>/hotcode-ci:otp29-elixir1.20 /usr/local/bin/hotcode /usr/local/bin/hotcode
or use the image as a GitHub Actions job container, where it must run as root (the runner mounts
the workspace as its own user, and sets another HOME):
container:
image: ghcr.io/<owner>/hotcode-ci:otp29-elixir1.20
options: --user root
steps:
- run: mix local.hex --force && mix local.rebar --force
The mix hotcode.* tasks come from the :hotcode dependency of your project; the image adds
the command that needs no project.
The key lives in the secret manager
mix hotcode.gen_key ci # once, on a trusted machine; prints the public key
Put the public key in the nodes' trusted_keys, and the private key file's contents in
your CI's secret store (GitHub environment secret, Argo/Kubernetes Secret, Vault). Hand it to
the job as an environment variable and name it with env::
hotcode sign patch.hcp --key env:HOTCODE_KEY --yes
The key never touches the disk, and a malformed value is reported without echoing it. --key
accepts a file or env:NAME everywhere: sign, push, status, rollback,
mix hotcode.build, mix hotcode.deploy. Do not write --key "$HOTCODE_KEY": that is the key
where a file name belongs (it is refused, and not repeated).
What a CI key means. A signature authorizes running code on production, so whoever can run your pipeline holds that power. Ways to keep it bounded:
- Protected environment. Store the secret only in the environment that deploys (a GitHub
environment with required reviewers and branch rules) and give every job that uses it that
environment:, so a pull request or another workflow cannot reach it. A repository secret is readable by every workflow. - Keep the key out of steps that run other people's code.
mix deps.getand compilation run code from your dependencies, in the same job: give the key only to the step that signs or deploys, never to the step that fetches and compiles (the examples below do). - Pin the image. The image runs in the jobs that hold the key. Use a version tag (or its
digest,
@sha256:...) rather than the floatingotpNN-elixirNNtag, and publish it only from tags (.github/workflows/image.ymldoes). threshold: 2with a human as the second signer. CI builds and signs; a person signs second. A stolen CI key alone cannot deploy. It does not make a compromised build harmless: the second signer is approving whatdescribeshows (module names, versions, the patch's sha256), not reading beams. To check the build, rebuild the patch independently and compare itspatch sha256with what CI built. This is the setup the example in Two signers uses.
Reaching the node
- HTTP(S),
https://host:4747. Recommended. Each request is signed with the private key, one port, nothing else to open. The node serves plain HTTP only on loopback (it refuses anything else unlessinsecure_http: true, which you should not set): off the machine it ishttpswith a certificate. A private CA is trusted with--cacert ca.pem(orHOTCODE_CACERT=ca.pem); verification is never switched off. Put the endpoint behind Tailscale or a VPN rather than on the public internet: it only accepts signed requests, but there is no reason to expose it. - Erlang distribution,
app@host. Needs the cluster cookie in the job (a second secret that grants far more than a deploy), epmd on 4369 and the distribution port reachable both ways. Pass the cookie as--cookie env:NAME(orHOTCODE_COOKIE) so it stays out of process listings and echoed commands. The command starts epmd if it is missing and names itself with the address the operating system routes to the target (on a tailnet, the tailnet address); setHOTCODE_CLI_HOSTwhen that is not an address the node can reach (a NAT, a name). Prefer HTTP from CI.
Tailscale
- uses: tailscale/github-action@v4
with:
oauth-client-id: ${{ secrets.TS_OAUTH_CLIENT_ID }}
oauth-secret: ${{ secrets.TS_OAUTH_SECRET }}
tags: tag:ci
then https://app-1.your-tailnet.ts.net:4747 (or its 100.x address) is the target. Give
tag:ci an ACL that reaches the deploy port and nothing else. (Tailscale encrypts the path, but
the node still serves https: the loopback-only rule for plain HTTP does not know about your
tailnet.)
Building without reaching the node
A job that builds patches often has no route to production, and should not need one. Save the manifest where the release is built, then build against the file:
# in the release build (the same step, the same image, the same MIX_ENV)
MIX_ENV=prod mix release
MIX_ENV=prod mix hotcode.manifest --release _build/prod/rel/my_app --out manifest.json
# keep manifest.json with the release (an artifact, the image, the bucket of the release)
# later, in the job that builds a patch: no route to any node
MIX_ENV=prod mix hotcode.build --manifest manifest.json --out patch.hcp --json
hotcode describe manifest.json # what it describes: audience, OTP/Elixir, release, counts
The manifest lists every module the release contains with its MD5 and code digest and its
application, the application versions, the OTP and Elixir versions, MIX_ENV, the release
name and version, and the audience and allowed_prefixes (from --audience and
--allowed-prefix, else from config :hotcode, else from config/runtime.exs when it can be
read on the build machine; without an audience the task exits 2). --release DIR reads the
assembled release, the exact code the node boots; without it the task reads _build/MIX_ENV,
which also has the dependencies a release leaves out.
Trust. The manifest is a convenience for the build, never an input the node believes. The
patch carries base, the MD5 of every module it replaces, copied from the manifest; the node
compares it with the code it runs, and checks its own OTP release, its audience, its
allowed_prefixes and the signatures, exactly as for a patch built against the live node. A
stale manifest (a hot patch deployed since, a node on another release) or a wrong one makes the
node refuse the patch (:base_mismatch, :otp_mismatch, :wrong_audience, exit 4), nothing
loaded; it cannot make the node load something else. After a hot deploy, the release's manifest
no longer describes the nodes: build the next patch against a node, or bake the patch into the
next release and save its manifest.
Several environments, several images
Teams often build staging and production separately: MIX_ENV=staging and MIX_ENV=prod, or
the same MIX_ENV with different config/*.exs overlays. The beams then differ: everything read
at compile time (Application.compile_env, @attr Application.get_env(...), Mix.env()) is
compiled in. A patch is therefore per environment:
- build one patch per environment, each against that environment's manifest (or a node of it),
with that environment's
MIX_ENVand config; never reuse the staging patch for production; - bind each to its own
audience(from that environment's manifest, or--audienceat build time): a node refuses an envelope for another audience (:wrong_audience), so a staging patch cannot land on production by mistake, and the staging keys can differ; - the manifest records
MIX_ENV, the release and theaudience;hotcode describe manifest.jsonshows them, and a patch built in anotherMIX_ENVthanprodis reported by the node as:build_env(a warning: a staging node built withMIX_ENV=stagingsees it on every patch, which is expected there).
for env in staging prod; do
MIX_ENV=$env mix hotcode.build --manifest manifests/$env.json --out patch-$env.hcp --json
done
hotcode sign patch-prod.hcp --key env:HOTCODE_KEY_PROD --yes # each with its own keys
What staging proves is the source change and its state migration, not the production beams: keep compile-time differences between environments small, and run the dry run against a production node before pushing.
Exit codes and --json
Every command, mix hotcode.* or hotcode, exits with a code that says what happened
(mix hotcode.check is Credo's: 0, or 16 when a rule found something):
| code | meaning | what changed on the nodes |
|---|---|---|
0 |
success, including "nothing to deploy" (check status in the JSON) |
as reported |
1 |
unexpected error (including a plain HTTP 500) | unknown: read the log |
2 |
usage: a bad flag, a missing or unreadable key or file | nothing |
3 |
the node cannot be reached: network, TLS, cookie, epmd, a gateway (502/503/504) | nothing |
4 |
refused: signatures, audience, expiry, replay, base, requires, a major bump, the preflight (including a node that did not answer it) |
nothing, no node ran the new code |
5 |
a roll started and failed: health check, a load error, a node timeout; or the request to a running roll timed out (outcome unknown: check status). For hotcode wait: the spread of the release halted |
rolled back where possible; the report lists rolled_back and needs_attention. After a halt: undone if the release carries auto_rollback (detail.undone) |
6 |
hotcode wait only: the time ran out and the spread is still going (nothing failed, nothing is final); with --halted, also a spread that finished without halting |
as reported in detail |
--json prints the result as one JSON line, the last line of stdout; human text goes to
stderr. The hotcode command prints nothing else; under mix, Mix itself may print ==> dep
lines when it recompiles a dependency before the task runs, so read the last line (tail -n 1):
{"ok": true, "status": "deployed", "plan": {"processes": 12, "findings": []}, "result": {...}}
{"ok": true, "status": "no_changes"}
{"ok": true, "status": "built", "out": "patch.hcp", "patch": {"version": "...", "changed": ["MyApp.Worker"], "new": [], "removed": [], "bytes": 4210}}
{"ok": true, "status": "planned", "plan": {...}}
{"ok": false, "error": {"kind": "refused", "exit_code": 4, "message": "plan refused: ...", "detail": ...}}
result and detail are what the node answered: over HTTP an object ({"ok": true, "nodes": {...}}
for a roll; for a failure [status, body]), over distribution the roll's own terms as JSON
lists. kind is one of usage, unreachable, refused, failed, error. A step that
branches on it:
set +e
hotcode push patch.hcp "$TARGET" --key env:HOTCODE_KEY --json > result.json
code=$?
set -e
case $code in
0) jq -r .status result.json ;;
4) echo "refused, nothing changed:"; jq -r .error.message result.json; exit 1 ;;
5) echo "ROLL FAILED or outcome unknown, check status:"; jq .error.detail result.json; exit 1 ;;
*) exit "$code" ;;
esac
A retry is only safe after 3: nothing happened, and an envelope applied once cannot be applied
again (replay protection), so a retry after a deploy returns 4. After 5 look at
hotcode status first.
--auto-rollback-after 120s (on mix hotcode.build or mix hotcode.deploy) adds a deadman
policy to the signed statement, so the person approving it sees AUTO-ROLLBACK: next to
everything else. It changes nothing about the exit code: 0 still means the roll finished and
every health check passed, at that moment. If the cluster later fails to follow the release
(a node that cannot take it, in convergence: [mode: :auto]), it is undone after the deadline,
long after the pipeline has exited; watch the audit event :cluster_auto_rollback or telemetry
[:hotcode, :cluster, :auto_rollback], not the job. A bad value (0s, 2h, 120 without a
unit, below 10 s or above 24 h) exits 2 before anything is built or sent.
A rollback answers once per node: if any node refused it (a stranger's key, an expired
statement), rollback exits 4 and detail has the per-node results.
A large cluster: deploy to the canaries, then wait
With a rollout policy in the release (see Rolling out to a large cluster), the job deploys to the canaries only and then waits for the nodes to spread it. It asks one node, every few seconds, how the whole cluster looks from there; it drives nothing.
mix hotcode.build "$TARGET" --out r.hcp --version "$GITHUB_SHA" --ttl-minutes 240 \
--rollout-canary 2 --rollout-soak 10m --rollout-success 0.99 \
--rollout-max-unavailable 10% --rollout-halt-failures 3 --auto-rollback-after 15m --json
hotcode sign r.hcp --key env:HOTCODE_KEY --yes --json
hotcode push r.hcp "$TARGET" --canary 2 --json # 0: the canaries run it
set +e
hotcode wait "$TARGET" --timeout 180m --interval 15s --json > spread.json
code=$?
set -e
case $code in
0) jq -r '.spread.counts' spread.json ;; # every reachable node has it
5) echo "HALTED:"; jq '.error.detail | {halted, failed, undone}' spread.json; exit 1 ;;
6) echo "still going; check later: hotcode status $TARGET --spread"; exit 1 ;;
*) exit "$code" ;;
esac
hotcode status TARGET --spread --json prints the same view once: phase (canary,
spreading, done, halted, idle), the count of nodes per role (and per group, with group_by), the
canaries' health, the failed nodes, and eta_ms, a rough time left at the rate so far. A
release built with --require-promote waits after its canaries passed until someone runs
hotcode promote TARGET --key ... (or, for two signers, --out, hotcode sign, --file).
After exit 5 without an undo (detail.undone false), a person who has fixed the cause can let the
release go on with hotcode resume TARGET --key ... (same signing options) and run hotcode wait
again; once the undo started, resume is refused (exit 4, :undone).
A fleet that is not an Erlang cluster
Independent nodes (N releases behind a load balancer, ECS tasks, Fly machines without clustering, boxes behind SSH) get the same signed envelope one by one from the job:
hotcode push patch.hcp --targets targets.txt --key env:HOTCODE_KEY \
--canary 1 --soak 5m --max-parallel 4 --max-failures 0 \
--health-url "https://{host}/healthz" --wait-for-old-code 60s --json > fleet.json
targets.txt has one node's Hotcode endpoint per line, then any key=value metadata you want
to select or group the nodes by (the keys are yours: region, zone, tier...), and an
optional health=URL; # starts a comment:
https://10.0.1.5:4747 region=eu-west tier=canary
https://10.0.1.6:4747 region=eu-west
https://10.0.2.7:4747 region=us-east health=https://10.0.2.7/healthz
--targets - reads the list from standard input, --targets-cmd CMD from a command's output
(see the recipes below), --target URL[,key=value,...] (repeatable) from the command line; they
combine. One --target value is one target: a value with whitespace, a control character (a CI
variable holding a newline) or a health= pair is refused. --targets-cmd runs without HOTCODE_KEY,
HOTCODE_COOKIE, RELEASE_COOKIE and the variables named by --key env:NAME and
--cookie env:NAME in its environment. What happens:
- Survey. Each target is asked its status and a dry run,
--max-parallelat a time. One already on the release (in its history) isskipped: running the same command again after an interruption resumes. A target that refuses the plan or does not answer counts as a failure; more than--max-failuresand nothing is deployed anywhere (exit 4, or 3 when every failure is "unreachable"). - Canaries. The first
--canary Ntargets (default 1), or with--canary-match KEY=VALUE(repeatable) the targets whose metadata matches (all of them, or the first N with--canary), are deployed and checked: the node's status must list the release and accept deploys, and the health URL ({host}is replaced by the target's host) must answer 2xx within--health-timeout(default 30 s). Then--soakpasses and they are checked again. Any canary failure halts the push. (This--canarypicks targets from the list; it is not the spread's canary of a cluster.) - The rest, in the list's order, at most
--max-paralleltargets at a time. With--group-by KEY, group by group of that metadata key's value (order of first appearance, or--group-order eu,usfirst), a group finished before the next starts. When the failures exceed--max-failures(default 0), no new target starts. - Undo. On a halt, every target this push changed is rolled back, newest first, with a
rollback signed by the same
--keys. When one key is below the threshold, sign a rollback in advance and pass it:mix hotcode.rollback https://node-1:4747 --key a.key --out rb.hcp,hotcode sign rb.hcp --key b.key, then--rollback-file rb.hcp(the nodes share the audience, and a rollback names only the version it undoes; mind its expiry). The file is checked before anything is deployed: it must be a rollback of this release's version and audience that does not expire before--soakhas passed (exit 2 otherwise).--no-rollbackleaves the done targets on the release. A target whose request timed out isunknown: it may still finish, so it is not rolled back blindly and is listed underneeds_attention. A target whose ownhealth_checkfailed has already undone its deploy itself.
The JSON (--json, last line of stdout) has status (deployed, no_changes, planned,
failed, halted), halted (why), counts, needs_attention and targets, one entry per
target with its status: deployed, skipped, planned, failed, unknown, not_started,
rolled_back, rollback_failed, and kind and reason for a failure. The exit code is 0
when every target is on the release (or skipped), 3 or 4 when the push changed nothing
anywhere, 5 when a target failed after something was changed (halted and rolled back, or
finished with failures within --max-failures): read targets and needs_attention.
An envelope applied and then rolled back on a node cannot be applied there again (replay
protection): after a halt, build a new patch. After a halt with --no-rollback, or a job that
died, the same command resumes. Build with --ttl-minutes long enough for the whole fleet:
a target the envelope reaches after it expired refuses it, which halts the push.
hotcode status --targets targets.txt --key env:HOTCODE_KEY --json prints each node's version
and history, and exits 3 if any of them did not answer.
Each node is independent: there is no Hotcode.Cluster.applied?/1, no convergence and no
deadman between them. A change to a message or storage format that another node reads needs
its readers on every node before any writer (three releases, as in
Clusters and mixed versions).
Fly.io machines
Without clustering, each machine is its own node. From a runner on the app's private network
(WireGuard, fly wireguard create), each machine is reachable at MACHINE_ID.vm.APP.internal,
an IPv6 address; the hotcode client tries IPv6 first, then IPv4. Bind the server on the IPv6
wildcard with TLS (server: [ip: {0, 0, 0, 0, 0, 0, 0, 0}, port: 4747, tls: [...]]) and a
certificate valid for those names (*.vm.APP.internal from a private CA, --cacert on the
client). List the started machines, with their region as metadata:
fly machines list -a my-app --json \
| jq -r '.[] | select(.state == "started") | "https://\(.id).vm.my-app.internal:4747 region=\(.region)"' \
> targets.txt
hotcode push patch.hcp --targets targets.txt --key env:HOTCODE_KEY --cacert ca.pem \
--group-by region --group-order ams,iad --json
Without a route to the private network, open one fly proxy per machine
(fly proxy 14747:4747 MACHINE_ID.vm.my-app.internal -a my-app &) and list
https://localhost:14747 region=REGION and so on, with a certificate valid for localhost.
A stopped machine (auto_stop_machines) restarts on the image: see
Ephemeral disks and immutable images.
ECS tasks
A self-hosted runner inside the VPC (or a VPN, or Tailscale) reaches each task's private address. List the running tasks of a service with the AWS CLI:
list_tasks() {
arns=$(aws ecs list-tasks --cluster prod --service-name my-app --desired-status RUNNING \
--query 'taskArns[]' --output text)
aws ecs describe-tasks --cluster prod --tasks $arns \
--query 'tasks[].[containers[0].networkInterfaces[0].privateIpv4Address, availabilityZone]' \
--output text | awk '{print "https://" $1 ":4747 zone=" $2}'
}
list_tasks > targets.txt
hotcode push patch.hcp --targets targets.txt --key env:HOTCODE_KEY --cacert ca.pem \
--group-by zone --json
Each task carries its availability zone as metadata, so --group-by zone finishes one zone
before the next starts.
The certificate the node serves must be valid for the address you use (an IP SAN, or a private
DNS name per task). A task replaced later boots the image: use store_fetch or bake the patch
into the next image.
Boxes behind SSH
With the server on loopback (plain HTTP allowed there, no certificate), open one tunnel per box and push through the local ports:
i=0; : > targets.txt
for host in app-1 app-2 app-3; do
port=$((14747 + i)); i=$((i + 1))
ssh -f -N -o ExitOnForwardFailure=yes -L "$port:127.0.0.1:4747" "deploy@$host"
echo "http://127.0.0.1:$port" >> targets.txt
done
hotcode push patch.hcp --targets targets.txt --key env:HOTCODE_KEY --json
The status and --health-url checks run from the job, so a health URL must be reachable from
there too (another forwarded port, or leave it out and rely on each node's own health_check).
GitHub Actions
One signer: build, sign, push in one job
name: hot-deploy
on:
push:
branches: [main]
jobs:
deploy:
runs-on: ubuntu-latest
environment: production # holds HOTCODE_KEY; required reviewers go here
container:
image: ghcr.io/<owner>/hotcode-ci:0.1.0-otp29-elixir1.20
options: --user root
steps:
- uses: actions/checkout@v7
- uses: tailscale/github-action@v4 # skip if the endpoint is reachable otherwise
with:
oauth-client-id: ${{ secrets.TS_OAUTH_CLIENT_ID }}
oauth-secret: ${{ secrets.TS_OAUTH_SECRET }}
tags: tag:ci
# fetching and compiling run your dependencies' code: no key in this step
- run: |
mix local.hex --force && mix local.rebar --force
mix deps.get && mix compile
env:
MIX_ENV: prod
- run: |
status=0
mix hotcode.deploy "$TARGET" --key env:HOTCODE_KEY --json > out.txt || status=$?
tail -n 1 out.txt > result.json # the result is the last line; Mix may print before it
exit $status
env:
MIX_ENV: prod
TARGET: https://app-1.your-tailnet.ts.net:4747
HOTCODE_KEY: ${{ secrets.HOTCODE_KEY }}
- if: always()
uses: actions/upload-artifact@v7
with: { name: deploy-result, path: result.json }
mix hotcode.deploy exits non-zero on any failure, and the step passes that code on (do not pipe
it into tee, whose exit code would replace it), so the job fails the way you expect. A deploy
that finds nothing to do succeeds. (The second step compiles again, which does nothing: the
first step already built everything, so no dependency code runs with the key in the environment.)
Two signers: CI builds, a person approves
jobs:
build:
runs-on: ubuntu-latest
environment: production # the key is NOT a repository secret
container:
image: ghcr.io/<owner>/hotcode-ci:0.1.0-otp29-elixir1.20
options: --user root
steps:
- uses: actions/checkout@v7
- uses: tailscale/github-action@v4
with: { oauth-client-id: "${{ secrets.TS_OAUTH_CLIENT_ID }}", oauth-secret: "${{ secrets.TS_OAUTH_SECRET }}", tags: "tag:ci" }
- run: mix local.hex --force && mix local.rebar --force && mix deps.get && mix compile
env: { MIX_ENV: prod }
- run: mix hotcode.build "$TARGET" --out patch.hcp --key env:HOTCODE_KEY --json
env: { MIX_ENV: prod, TARGET: "https://app-1.your-tailnet.ts.net:4747", HOTCODE_KEY: "${{ secrets.HOTCODE_KEY }}" }
- run: hotcode describe patch.hcp # the log records what is being authorized
- run: hotcode sign patch.hcp --key env:HOTCODE_KEY --yes
env: { HOTCODE_KEY: "${{ secrets.HOTCODE_KEY }}" }
- uses: actions/upload-artifact@v7
with: { name: patch, path: patch.hcp }
Then a person downloads patch.hcp, reads hotcode describe patch.hcp (and, to be sure, rebuilds
the patch themselves and compares the patch sha256), signs with their own key
(hotcode sign patch.hcp --key alice.key) and pushes (hotcode push patch.hcp $TARGET --key alice.key). Nothing deploys until the second signature exists, whatever the pipeline does.
The envelope expires (15 minutes by default, --ttl-minutes to change it), so a stale approval
cannot be replayed later.
Argo
Argo Workflows runs the same steps as pods. Use the image for each, the secret as an
environment variable, and https with the CA that signed the node's certificate (a Secret or
ConfigMap mounted as a file; the pod needs no Tailscale inside the cluster, but the node still
only serves plain HTTP on loopback):
apiVersion: argoproj.io/v1alpha1
kind: WorkflowTemplate
metadata: { name: hotcode-deploy }
spec:
entrypoint: deploy
templates:
- name: deploy
container:
image: ghcr.io/<owner>/your-app-builder:otp29-elixir1.20 # your sources + deps compiled, FROM the CI image
command: [sh, -c]
args: ["mix hotcode.deploy https://app.prod.svc:4747 --cacert /etc/hotcode/ca.pem --key env:HOTCODE_KEY --json"]
env:
- { name: MIX_ENV, value: prod }
- name: HOTCODE_KEY
valueFrom: { secretKeyRef: { name: hotcode-ci, key: private.key } }
volumeMounts:
- { name: ca, mountPath: /etc/hotcode }
volumes:
- name: ca
configMap: { name: hotcode-ca }
The builder image has the app compiled in it, so the key is not present while dependencies compile. The pod's non-zero exit fails the workflow step with the code above.
Argo CD reconciles declared state; a hot deploy is an action, not a state. Run it as a
PostSync hook, a Job that Argo CD starts after a sync and reports on:
apiVersion: batch/v1
kind: Job
metadata:
generateName: hotcode-deploy-
annotations:
argocd.argoproj.io/hook: PostSync
argocd.argoproj.io/hook-delete-policy: HookSucceeded
spec:
backoffLimit: 0 # never retry a deploy automatically: see the exit codes
template:
spec:
restartPolicy: Never
containers:
- name: deploy
image: ghcr.io/<owner>/your-app-builder:otp29-elixir1.20
command: [sh, -c]
args: ["mix hotcode.deploy https://app.prod.svc:4747 --cacert /etc/hotcode/ca.pem --key env:HOTCODE_KEY"]
env:
- { name: MIX_ENV, value: prod }
- name: HOTCODE_KEY
valueFrom: { secretKeyRef: { name: hotcode-ci, key: private.key } }
volumeMounts:
- { name: ca, mountPath: /etc/hotcode }
volumes:
- name: ca
configMap: { name: hotcode-ca }
Argo CD should not compile your code; build the app's builder image in CI, as above, and let the hook only run it. If you do not want a hook, run the deploy from the pipeline that builds the image and leave Argo CD to the manifests.
What is tested, and what is not
Tested, in this repository's suite: every exit code and the JSON of every command, through the
real mix hotcode.* tasks and the real hotcode command against two real nodes (build in the
project, describe, sign with a key from an environment variable, push by HTTP, rollback
by distribution, a second run refused as a replay), and the address selection for
distribution. With docker available (mix test --include docker) a test also runs the image
against a node over https with a private CA: describe, sign, push, a replay refused, an
unreachable node. The image is built and run by this repository's CI (.github/workflows/ci.yml).
Not tested here: the workflow and Argo manifests in this guide were written against the
documented behaviour of those systems, not run on them. Treat them as a starting point. A
hotcode push ... --dry-run --json from your pipeline before the first real deploy checks the
route, the key and the node's plan: it asks one node for a dry run, which verifies one
signature and the analysis, but not the signature threshold, the replay counter or the other
nodes. A real cluster deploy runs a stricter preflight on every node first.