Skip to main content
A CI pipeline signs the firmware it built, uploads it to a product, and optionally creates a release on a deployment group so devices start updating. To do the same steps by hand first, see the Quickstart.

Authenticate from CI

Give the pipeline one credential, stored as a CI secret. nh reads it from NERVES_HUB_TOKEN. API calls send it as Authorization: Bearer <credential>. Use a product API key where you can. A leaked key exposes one product with the permissions you chose.
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, use a user access token.
  1. In the product, open Product settings and select the API keys tab.
  2. Click Create key. Enter a Name, such as CI deploys.
  3. Choose the Role. Uploading firmware and creating releases need Manage, or a custom role with the Upload firmware and Create, edit and approve releases permissions.
  4. Click Create key, copy the key, and store it as a secret in your CI system. It is shown only once.
See API authentication for everything each credential can and cannot reach.

Configure nh in CI

Set these environment variables in the job. nh reads them without any saved settings. Every variable can also be written with the NERVES_CLOUD_ prefix. See CLI configuration. To install nh on the runner, download the archive for the runner’s platform from the releases page. See Installation.

Sign in CI

NervesHub refuses fwup firmware that is not signed with a key registered to the organization. The other formats have their own signing rules.

fwup and AtomVM firmware

nh firmware upload signs fwup (.fw) and AtomVM (.avm) images with an Ed25519 key before it uploads them. In CI, pass the key in NERVES_HUB_PRIVATE_KEY. The value is the base64 encoding of the 64-byte Ed25519 private key, unencrypted. This is the format of the private key file fwup -g writes.
1

Generate a key pair

On your own machine, generate a key pair with fwup. It writes fwup-key.pub and fwup-key.priv to the current directory.
2

Register the public key

Register the public key with your organization. This needs a user access token, because signing keys belong to the organization.
3

Store the private key as a secret

Store the contents of fwup-key.priv as a secret in your CI system, and expose it to the job as NERVES_HUB_PRIVATE_KEY. Keep the file itself somewhere safe and out of version control.
Signing an fwup image calls fwup, so fwup must be on the runner’s PATH. AtomVM images need nothing else. Other ways to supply the key: If no key is given and --skip-signing is not passed, the upload fails.

ESP-IDF and RAUC firmware

  • ESP-IDF (.bin): nh signs with espsecure.py, which must be on the runner’s PATH, using an RSA-3072 key passed with --key-file <pem>. An image that is already signed is uploaded as it is.
  • RAUC (.raucb): bundles are signed when they are built. nh uploads them as they are.
See Firmware signing, ESP-IDF and RAUC.

Upload and deploy with nh

The command:
  1. Detects the format from the file’s contents.
  2. Reads the image’s metadata and refuses an image built for a different product.
  3. Signs the image.
  4. Uploads it to the product.
  5. For each --deploy, creates a release with the new firmware on that deployment group. The release becomes the group’s current release, with no archive.
Always pass the firmware path in CI. Without a path, nh looks for a single image in _build/<MIX_TARGET>_<MIX_ENV>/nerves/images/ and asks for confirmation, which fails without a terminal unless you also pass --yes.

The deploy option

  • --deploy names an existing deployment group. Repeat it to update several groups.
  • When --deploy is not given, NERVES_HUB_DEPLOYMENT_NAME is used if it is set.
  • If a deployment fails, the firmware stays uploaded. The error names the firmware UUID and the group. Retry that step with nh deployment update <group> --firmware <uuid>.
To set a description, notes, an archive or connecting code on the release, or to mark it required, upload without --deploy and create the release yourself:
See Releases.

Output and exit status

With -o json, nh firmware upload prints one JSON document on stdout: the uploaded firmware, with a deployed list naming the groups it updated. Progress messages go to stderr.
The document has the firmware’s other fields too, such as product, platform, architecture and tool. nh exits 0 on success and non-zero on any failure, including a failed deployment after a successful upload. In JSON mode the document is still printed in that case, so a script can read the UUID.

GitHub Action

The nervescloud/upload-nerves-firmware action downloads nh, signs and uploads a firmware file, and optionally updates a deployment group. fwup must already be on the runner’s PATH. The action does not install it.

Inputs

Outputs

What the action does

  1. Installs nh for the runner’s platform (Linux, macOS or Windows on amd64 or arm64) and caches it.
  2. Exports NERVES_HUB_ORG, NERVES_HUB_PRODUCT, NERVES_HUB_TOKEN and, when uri is set, NERVES_HUB_URI to the job. Later steps can run nh without further setup.
  3. Runs nh firmware upload <firmware> --output json. The signing key is passed to that command only, and is not exported to the job.
  4. When deployment is set, runs nh deployment update <deployment> --firmware <uuid>.
With version: latest, the action asks the GitHub API for the newest nh release. It uses GITHUB_TOKEN for that request when the variable is set in the step’s environment. Pin version to avoid the lookup.

Equivalent API calls

The API does not sign firmware, so sign the file first. Sign an fwup image with fwup:

Upload firmware

Send the file as the firmware field of a multipart/form-data body.
A successful upload returns 201 Created, a Location header for the new firmware, and the firmware in the body.
A refused file returns 422 with the reason in errors.detail, for example a signature that matches none of the organization’s keys, or firmware built for a different product. This call needs the Upload firmware permission.

Create a release

Point a deployment group at the firmware by creating a release.
A successful call returns 201 Created. The request is refused with 422 if the group’s current release already has the same firmware and archive. This call needs the Create, edit and approve releases permission. If the releases route returns 404 although the deployment group exists, the server does not have the release API. Update the group instead, which creates a release the same way:
nh firmware upload --deploy and nh deployment update --firmware make this same choice for you.