- A pipeline that releases every merge to
qaand releases toproductionwhen you push a version tag. - A
productionrollout that goes to a few canary devices first, waits for a person to approve, then reaches the rest of the fleet. - A webhook that reports each rollout to your own backend.
- Rollout limits, narrow roles for approvers and CI, and two-factor authentication.
Before you start
You need everything the basic guide left in place:- Devices set up as in Basic Nerves device setup, running firmware that trusts the CI signing key
my_app_ci_key. .github/workflows/firmware.yml, which builds on every push tomainand releases toqa, with the repository secrets and the repository variableDEVICE_SSH_PUBLIC_KEYthat guide had you add.- The
qaandproductiondeployment groups, both on, with devices taggedqaandprod. - A Slack channel that gets notifications for
my_app, and your Slack account linked.
rpi4.
The guide has four parts. Do them in order.
1. Build a two-stage release pipeline
This part adds a second stage to the basic guide’s workflow: pushing a tagv<version> releases that firmware version to production.
The tag job does not build anything. It finds the firmware that qa already received and creates a release of that same firmware on production. The fleet gets the exact file your QA devices ran, and the production job never holds the signing key.
The workflow
Replace the whole of.github/workflows/firmware.yml with the file below. Both jobs switch from the upload action to the nh CLI and create their release with nh deployment release create. The production job only creates a release and has nothing to upload, which the action cannot do. The build steps, the firmware path, and the repository secrets and variable are the ones you already have.
- The
buildjob is nowqa, and it creates its release explicitly. The action’sdeploymentinput andnh firmware upload --deploycannot describe a release. So the job uploads with-o json, reads the firmware UUID, and runsnh deployment release createwith a--description. See the deploy option. - The
productionjob looks the firmware up.nh deployment release list qareturns the group’s releases newest first, so the job takes the newestqarelease whose firmware version matches the tag. - The production release carries a description and notes. Neither can change later.
nh deployment release showprints both. The group’s Releases tab shows the description on each row, and the notes when you open the row.
nh deployment release create call prints the number of the release it created.
The tag only names a version. Bump version in mix.exs, merge, wait for the QA run to finish, and push the tag once you are happy with what qa is running. Every merge needs a new version, because the production job finds firmware by its version.
The nh deployment release commands need a server with the release API, and descriptions and notes need NervesHub 2.5.0. See Releases. If later firmware depends on a release being installed first, add --required to the production job’s nh deployment release create command. See Required releases.
Credentials for CI
NERVES_HUB_TOKEN currently holds your user access token. It works on every NervesHub version, but it can do everything you can do, in every organization you belong to, and it stops working when your account is deleted.
Today, you can move the token to a user that holds a custom role with only the two permissions the pipeline uses. Part 4 creates that role as CI. Later, a product API key is the better fit: it reaches my_app only, holds a role of its own, and keeps working when the person who created it leaves.
Product API keys are on the NervesHub main branch but in no tagged release as of NervesHub 2.5.4. On 2.5.4 and earlier, keep the user access token.
- In
my_app, open Product settings and select the API keys tab. - Click Create key. Enter a Name, such as
CI deploys. - Change the Role from View to Manage, or to the
CIrole from part 4. A View key cannot create a release. - Click Create key, copy the key, and save it as the
NERVES_HUB_TOKENsecret in GitHub. It is shown only once.
nh sends either credential the same way. See API authentication for what a key can and cannot reach.
Check it works
-
Bump the version and merge to
main. When the run finishes, list theqareleases and note the version and firmware UUID of the newest one: -
Tag that commit and push the tag, with the version you merged in place of
<version>: -
When the
productionjob finishes, list theproductionreleases:The newest release is marked with*, shows the version you tagged, and has the same firmware UUID as theqarelease. Runnh deployment release show production <number>to see its description and notes, or open the group’s Releases tab in the web UI.
prod start updating as soon as the release exists, as long as the production group is on.
Go deeper: CI and automation · Releases · Deployment groups · Build, sign, and upload firmware · API authentication · Roles · nh command reference
2. Roll out through canaries with an approval gate
Without a workflow, theproduction group sends each release to every prod device, paced only by the group’s settings. A deployment workflow splits the release into ordered steps: here a few canaries, a human sign-off, then the rest of the fleet. Workflows need NervesHub 2.5.0 or later and are an early release feature.
Tag the canaries
Add thecanary tag to a handful of prod devices that you can reach if an update goes wrong. On the product’s Devices page, run the query tags contains "prod", tick the devices, then choose Tags and Add in the bar at the foot of the list. See Bulk actions.
From the CLI, --tag sets the whole tag list, so repeat prod:
Write the workflow
Save this asproduction-workflow.json:
- Canary claims up to five devices tagged
canaryand completes when all of them run the new firmware. It waits for offline canaries too, so tag devices that connect reliably. - With this
failure_tolerance, the step fails when a second canary lands in the penalty box. Leave it out and the first one fails the step. - Sign-off covers no devices. It holds the rollout until someone approves it.
- Rest of the fleet updates every device no earlier step claimed.
Upload it
Open theproduction group’s Settings tab. On the Workflow card, select Upload and pick the file. Once the group has a workflow, the button reads Replace. The card then lists the three steps. An invalid file is rejected with the path of each problem.
The workflow applies from the next release. The current release carries on as it was.
While the group has a workflow, each step’s concurrent_updates and the step order replace two of the group’s own settings. Part 4 covers which.
Add the workflow events to Slack
On the organization’s Integrations tab, open the row menu of the Slack channel you set up formy_app in the basic guide and choose Edit. Tick Workflow waiting for approval and Workflow step failed, then click Save channel. See Channel notifications.
Anyone who will approve from Slack must have linked their Slack account with /nerveshub link, as you did in the basic guide’s Slack check. The instance needs a Slack app: see Feature prerequisites.
Approve the rollout
Each new release starts at step 1. The group’s Overview tab shows every step with its updated and total device counts. Once every canary runs the new firmware, the group’s badge reads Awaiting approval and the group appears under Needs you on the Deployment groups page. Check the canaries, then approve in either place:- Web UI: on the group’s Overview tab, select Approve and continue and confirm.
- Slack: select Approve on the Workflow waiting for approval message. See Act on deployment workflows from Slack.
Release approver role for people who should hold little else.
If the canary step fails
The badge reads Stopped and nothing further is sent until you choose one of these on the Overview tab:- Retry step lets the failed devices out of the penalty box, clears their attempts, and runs the step again.
- Skip step releases the canaries to the catch-all step, once you confirm. The rollout moves on to Sign-off, which still waits for approval.
Check it works
- Merge a new version, let
qarun it, and push its tag so the pipeline releases it toproduction. - On the Overview tab, confirm that only the canaries update.
- When the badge reads Awaiting approval and the message arrives in Slack, approve.
- Confirm that the count on Rest of the fleet climbs.
3. Report rollouts to your backend with a webhook
A webhook sends each moment of a rollout to an HTTP endpoint you run, as a signed JSONPOST. You use one webhook for two jobs: a rollout dashboard in your backend, and paging someone when a step needs a person.
Webhooks need NervesHub 2.5.0 or later and the Manage or Admin role, or a custom role with the webhook permissions.
Choose the events
The payloads are in the event reference.
Create the webhook
Your endpoint must be on a public address, and should usehttps://. NervesHub refuses loopback, private and other reserved addresses unless the instance’s operator allows them. See Feature prerequisites.
- nh CLI
- Web UI
nh webhook list shows the webhook’s id, which you need for the check below. See nh webhook.Receive and verify deliveries
This receiver uses only the Python standard library (Python 3.9 or later). It verifies the signature over the raw body, answers straight away, and drops any delivery whosewebhook-id it has already seen. Save it as receiver.py.
PORT if you set it. Put it behind the proxy that serves your public https:// URL. The Standard Webhooks libraries can replace verify. See Verify signatures.
Plan for retries and failures
- Answer within 15 seconds with any
2xx. Anything else is a failure, and NervesHub retries it several times over the following hours before it drops the delivery. - Expect duplicates and reordering.
webhook-idis the same on every retry, which is what the receiver deduplicates on. Order events by the body’stimestamp, not by arrival. - A dead endpoint turns the webhook off. This happens when the endpoint has accepted no delivery for 24 hours, or answers
410 Gone.my_appgets a product notification saying why. Fix the endpoint, then choose Turn on from the row menu or runnh webhook update <id> --enabled.
Check it works
1
Send a test event
Run
nh webhook test <id>, or choose Send test event from the webhook’s row menu. NervesHub sends a webhook.test event and reports how your endpoint answered.2
Read the receiver's output
The receiver prints a line starting
test event:. A 401 in its log means the secret does not match the webhook.3
Watch a real rollout
Release the next version to
production. The receiver prints a scheduled and a finished line for each canary, then a PAGE: line when the release reaches the approval step.nh webhook · Product notifications · Feature prerequisites
4. Add guardrails
This part limits the damage a bad release or a leaked credential can do, and shows where to look when a rollout goes wrong.Set the rollout controls
Open a group and select the Settings tab. Each card saves on its own with Save. See Rollout controls for every setting.production has a workflow, so the first two are disabled on it. Set them on qa, and on any group without a workflow. If you ever select Remove workflow on production, later releases go to the whole group, paced by these settings.
Keep the penalty box defaults. A device that reports a failed update goes into the penalty box straight away, whatever the attempt limits are. The limits cover a device that keeps starting an update without finishing it. In a workflow, a device in the penalty box is what counts as a failed device towards its step’s failure_tolerance.
A device in the penalty box gets no updates until the penalty ends, and its page header shows Blocked. Once you have fixed the cause, let it out:
Give approvers and CI their own roles
Custom roles need NervesHub 2.5.4 or later. You need the built-in Admin role to create them. See Custom roles.1
Create the approver role
Open the
acme organization and select the Roles tab. Click Add role, name it Release approver, and tick Create, edit and approve releases and Clear a device’s penalty box. Click Create role.2
Create the CI role
Add a second role named
CI. Tick Upload firmware and Create, edit and approve releases. Those are the two permissions the pipeline uses.3
Assign them
On the Users tab, pick each role in the Role column:
Release approver for the people who approve, CI for the user whose access token the pipeline holds. Custom roles can only be assigned in the web UI.A product API key can take the
CI role instead of a user. Product API keys are on the NervesHub main branch but in no tagged release as of NervesHub 2.5.4. See Credentials for CI.Require two-factor authentication
Two-factor authentication needs NervesHub 2.5.4 or later andSECRETS_ENCRYPTION_KEY set on the instance. See Feature prerequisites.
1
Turn it on for every account first
Each member sets it up on their own account page. Under Two-factor authentication, click Set up beside Authenticator app, scan the QR code, enter the Code from the app and click Turn on. Do this for the CI user too, and for yourself: an admin without it cannot turn the requirement on.
2
Require it
On the organization’s Settings tab, tick Require two-factor authentication for every member and click Save. The page lists the members who would be turned away.
nh user auth fails for any account with two-factor authentication on. Sign in with nh user login, which uses the browser. See Two-factor authentication.
When a rollout misbehaves
Work from the fleet down to the device.- Pause the group. Select Pause on the
productiongroup page and confirm. Devices already updating finish. See Pause a group. - Product Insights. Failing updates lists devices that keep failing, and Stands out names a firmware version that is less healthy than the rest. See Insights and history.
- Product notifications. A workflow that stopped after failures shows here, as does a webhook that was turned off. See Product notifications.
- The device page. The header shows Blocked for a device in the penalty box. The Firmware History tab shows what the device installed, and the Health tab shows current metrics and alarms. See Health monitoring.
- The audit trail. The Activity tab on the device and on the group records who released, approved, retried or skipped. See Audit log.
Check it works
-
Run this before a rollout. It should return no devices:
-
Open the
qagroup’s Activity tab. Your settings changes are listed with your name. Theproductiongroup’s tab lists the workflow upload and every release, approval, retry and skip. -
After the two-factor requirement is on, run any
nhcommand with the CI token, such asnh device list. It still succeeds. -
On the next
productionrollout, have someone with theRelease approverrole select Approve and continue when the canary step finishes.
What you have now
The finished.github/workflows/firmware.yml, unchanged since part 1:
production-workflow.json, uploaded on the production group’s Workflow card:
Where to go next
- Complete Nerves device setup covers the device side of a production fleet: certificate authentication, control over when updates apply, and every extension.
- Deployment workflows has the full workflow file format, for more steps than these three.
- Connecting code and Required releases are the two release features this guide does not use.
- Microsoft Teams and Discord take the same notifications as Slack.

