Skip to content

Add an API for deployment group releases - #3338

Merged
joshk merged 12 commits into
mainfrom
feature/deployment-release-api
Nov 23, 2026
Merged

joshk merged 12 commits into
mainfrom
feature/deployment-release-api

Conversation

@joshk

@joshk joshk commented Nov 22, 2026 •

Copy link
Copy Markdown
Collaborator

Adds /deployments/:name/releases to the API: list a deployment group's releases, read one, create one, and change whether one is required or what its connecting code is.

Until now the only way to make a release over the API was PUT /deployments/:name with firmware or archive, and that request ignores every other group setting in its body. The nh CLI has to split one update into as many as three requests, and it can't list releases or edit required or the connecting code on a release that already exists (found in nerves-hub/nh#25). A later nh PR adds nh deployment release list|show|create|update against these endpoints.

PUT /deployments/:name keeps working as it does, so older CLIs are unaffected. Its OpenAPI description now points at the new endpoints.

Endpoints

All four sit under /api/orgs/:org_name/products/:product_name/deployments/:name/releases and accept a user token or a product API key. A release is identified by its number within the group.

Method and path Needs Returns
GET /releases membership 200, newest first
GET /releases/:number membership 200, or 404
POST /releases deployment_group:release:manage 201 with a location header, or 422
PATCH /releases/:number deployment_group:release:manage 200, or 404, or 422

Every endpoint returns 404 for a group the product doesn't have. They also check require_every_device, as the group endpoints do, so a role limited to tagged devices can't use them.

POST body, flat (not wrapped in deployment the way the PUT is):

{
  "firmware": "d9f8c63a-1234-5678-abcd-ef0123456789",
  "archive": "6a1f0c2e-...",
  "required": false,
  "description": "Fixes the Wi-Fi reconnect loop",
  "notes": "Roll out after the field test passes",
  "connecting_code": "Logger.info(\"connected\")",
  "connecting_code_mode": "last"
}

Only firmware is required; an archive left out or sent as "" means none. A null for required or connecting_code_mode is a 422; leave them out for the defaults (false, last). Here the connecting code is the release's own; the PUT drops it because there it means the group's.

PATCH body, every field optional, anything left out keeps its value:

{ "required": true, "connecting_code": null, "connecting_code_mode": "first" }

null or "" removes the connecting code. The firmware, archive, description and notes of a release can't change once it's made, so the endpoint ignores them if sent. DeploymentRelease holds which fields each changeset casts; the controller passes the body through.

A release, under data (a list for GET /releases):

{
  "number": 3,
  "firmware": { "uuid": "d9f8...", "version": "1.0.1", "platform": "rpi0", "architecture": "arm" },
  "archive_uuid": null,
  "required": false,
  "description": "Fixes the Wi-Fi reconnect loop",
  "notes": null,
  "connecting_code": null,
  "connecting_code_mode": "last",
  "delta_status": "ready",
  "is_current": true,
  "created_by": { "type": "user", "name": "Jane Doe", "email": "jane@example.com" },
  "inserted_at": "2026-11-22T10:00:00",
  "updated_at": "2026-11-22T10:00:00"
}

The timestamps are UTC written without an offset, as the deployment group's are. created_by is {"type": "api_key", "name": ...} for a release a product API key made, and null for releases made before authors were recorded. connecting_code_mode is first, last or override; delta_status is ready, preparing or failed.

422s use the usual changeset shape, for example {"errors": {"firmware": ["The current release already has this firmware and archive"]}}.

A permission for releases: deployment_group:release:manage

Making a release used to need deployment_group:update, the same permission as changing the group's settings. Everything done to a release now needs deployment_group:release:manage instead, in the web UI, Slack and the API: creating and editing releases, approving, skipping and retrying workflow steps, and retrying or deleting deltas. The built-in manage and admin roles have it. deployment_group:update keeps the group's Settings tab.

PUT /deployments/:name with firmware or archive makes a release, so it needs the new permission. A PUT without either still needs deployment_group:update.

Creating a deployment group needs deployment_group:release:manage as well as deployment_group:create, in the web UI and in POST /deployments. A new group starts with a release of the firmware it's given, so without this a role with deployment_group:create and deployment_group:toggle could ship firmware.

A migration gives deployment_group:release:manage to every custom role that has deployment_group:update, so those roles keep editing and approving releases. A role with deployment_group:create but not deployment_group:update isn't given it, since that would let it approve steps and send releases on every existing group. Such a role can't create groups until an admin adds the permission. An API key with a custom role gets the permission through that role.

Deltas are queued after a release is saved

Queueing deltas for a new release, for one marked required, or for a group whose delta updates were turned on, ran inside that save's own transaction. Queueing a delta runs a transaction of its own, and when that one failed, Ecto rolled back the outer one too. The release or setting was never saved, and the API answered 500 (or the group's Settings tab crashed, on a MatchError). It now happens after the commit, as the web UI's comment always said it did. A delta that can't be queued is logged and sent to Sentry, and devices that need it get the whole firmware. An error raised while queueing is caught the same way, so the save still answers with what it saved and the orchestrator is still told about it.

A release that reads ready before its deltas are queued would be sent as whole firmware, so a release that will queue deltas now starts preparing: a new release, or one marked required, in a group that's on with delta updates on. The recalculation after the queueing settles it, to ready if it has nothing to wait for. If the node goes down between the commit and that recalculation, the group's orchestrator settles the release on its two-minute tick, so the worst case is a rollout held back for a few minutes rather than for good. The tick leaves a release changed in the last minute alone, since its deltas may still be on their way into the queue. When a release's delta status changes, the orchestrator reads the group again, so it picks up a release whose own announcement never went out.

Deploying

Saving a custom role on a node still running the old code drops deployment_group:release:manage, because that node's role editor has no checkbox for it. If roles might be edited during the rollout, run the migration's statement again once every node is on the new code. It only adds the permission where it's missing:

UPDATE org_roles
SET permissions = ARRAY(
  SELECT DISTINCT p FROM unnest(permissions || ARRAY['deployment_group:release:manage']) AS p ORDER BY p
)
WHERE 'deployment_group:update' = ANY(permissions)
  AND NOT 'deployment_group:release:manage' = ANY(permissions);

Choices I made without Josh

  • A firmware or archive UUID the product doesn't have gets a 422 does not exist. The PUT instead drops an unknown archive silently and creates a release without it, which a new endpoint has no reason to copy.
  • Connecting code runs on devices, and editing it takes the same permission as the rest of a release. Anyone holding deployment_group:release:manage (a member, or a manage API key) can set it over the API as well as in the web UI.
  • created_by includes the user's email. Any member can already list the organization's users with their emails. A product API key can't reach that list, so a key now sees the email of whoever made a release in its product. Say if that should be the name only.
  • update_deployment_release/3 takes an API key as well as a user, and its audit entries name the key ("API key CI marked release 2 as required ...").
  • ManagedDeployments.get_deployment_release_by_number/2 is new, and loads a release the same way list_deployment_releases/1 loads each release.

Open question: should a new release keep the previous release's archive?

The web UI's New release form starts with the current release's archive selected, so a release made there keeps it unless someone clears it. The API doesn't: a release made without an archive has none, even when the current release has one. I left the API that way, and its POST docs say so, so the CLI can pass the archive along itself. Should the API match the form?

🤖 Generated with Claude Code

joshk and others added 2 commits November 22, 2026 17:12
A release could only be made over the API as a side effect of
PUT /deployments/:name, which ignores the rest of the body when it names
firmware, and there was no way to list releases or change one once made.

GET, POST /deployments/:name/releases and GET, PATCH
/deployments/:name/releases/:number now do that, with the same
permissions as the Releases tab. update_deployment_release/3 takes a
product API key as well as a user, so a key can use PATCH and its audit
entries name it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Such a number can't be encoded into the query, so it raised and the
request got a 500.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@u7d-bot

u7d-bot commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

Rummager review of f2f0c9adf8

Replaced by a newer review of 7996e282fb.

The earlier review

Sensitive areas

  • Authorization: deployment_group:update permission on release create and edit, membership checks, tagged-device role restriction, product API key as actor
  • Access control: new deployment release API routes, product scoping of deployment groups, firmware and archive lookups
  • Personal data: release author name and email exposed to members and product API keys
  • Other: connecting code run on devices, now settable over the API by users and API keys

Pass with warnings: 2 warnings, 2 suggestions.

  • Correctness: 1 finding, inline at lib/nerves_hub_web/controllers/api/deployment_release_controller.ex:102.
  • Prose, comments and docs: 3 findings, inline at lib/nerves_hub/managed_deployments.ex:1037-1040, lib/nerves_hub_web/controllers/api/deployment_group_controller.ex:105-110, lib/nerves_hub_web/controllers/api/deployment_release_controller.ex:27.
  • No findings: Security, Code quality.

The inline comments are in this review.

Screenshots: no UI changes in this PR.

rummager · prompts 885379605730 · automated, verify before acting.

@u7d-bot u7d-bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inline findings for f2f0c9adf8. The summary is in the rummager comment.

Comment thread lib/nerves_hub/managed_deployments.ex Resolved
The controller filtered each body down to a list of its own before
handing it on. The fields a release takes when it's made, and those it
can still change, now live in DeploymentRelease beside the casts that
use them, and the controller passes params through.

new_changeset/5 also requires required and connecting_code_mode, so a
null for either in a request is a 422 rather than a not-null violation
and a 500.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@joshk

joshk commented Nov 22, 2026

Copy link
Copy Markdown
Collaborator Author

/rummager

@u7d-bot

u7d-bot commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

Rummager review of 7996e282fb

Replaced by a newer review of e2d885fe66.

The earlier review

Sensitive areas: authorization, access control, personal data, other. Unchanged since the earlier review of f2f0c9adf8.

Pass with warnings: 1 warning.

  • Prose, comments and docs: 1 finding, inline at lib/nerves_hub/managed_deployments/deployment_release.ex:63-68.
  • No findings: Correctness, Security, Code quality.

The inline comments are in this review.

Screenshots: no UI changes in this PR.

rummager · prompts 885379605730 · automated, verify before acting.

@u7d-bot u7d-bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inline findings for 7996e282fb. The summary is in the rummager comment.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@joshk
joshk requested a review from a team November 22, 2026 07:02
joshk and others added 5 commits November 23, 2026 15:09
Creating, editing and approving a release needed deployment_group:update,
the same as changing the group's settings. Everything done to a release
now needs deployment_group:release:manage: the Releases tab, approving,
skipping and retrying workflow steps (group page, groups list, home page,
Slack), retrying and deleting deltas, the release API, and a PUT to a
deployment group that names firmware or an archive. The manage and admin
roles have it, and a migration gives it to every custom role that has
deployment_group:update, so none loses what it can do today.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- Release timestamps are naive, so the spec now says so with
  naive_timestamp, and api_spec_test checks every release endpoint.
- Deltas for a new or newly required release are queued after the
  release commits. Queueing runs a transaction of its own, and a failed
  one rolled the release back with it, as a 500.
- Creating a deployment group needs deployment_group:release:manage too,
  since a group starts with a release. The migration grants it to custom
  roles with deployment_group:create as well.
- One guard picks both the PUT clause that makes a release and the
  permission it needs.
- The migration says how to re-run its grant after a rolling deploy.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Turning a group's delta updates on (or turning the group on, or a new
firmware) queued deltas inside update_deployment_group's transaction,
with a {:ok, _} match. A delta that couldn't be queued crashed the save
on the match, and its own failed transaction would have rolled the
change back anyway. It now runs after the commit, before the broadcast,
as release creation does.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Deltas are queued after a release commits, so for a moment a new release
read ready with nothing queued for it to wait on, and could be sent as
whole firmware. A release that will queue deltas, new or just marked
required, in a group that's on with delta updates on, now starts
preparing, and the recalculation after the queueing settles it.

If the node goes down before that recalculation, the release would hold
its devices back for good, since statuses are otherwise recalculated only
when a delta changes. The group's orchestrator now settles any release
reading preparing on its two-minute tick (settle_delta_statuses/1).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@joshk

joshk commented Nov 23, 2026

Copy link
Copy Markdown
Collaborator Author

/rummager

@u7d-bot

u7d-bot commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Rummager review of e2d885fe66

Replaced by a newer review of 449d2d0c45.

The earlier review

Sensitive areas: authorization, access control, personal data, other. Unchanged since the earlier review of 7996e282fb.

Requires changes: 1 blocker, 10 warnings.

  • Correctness: 4 findings, inline at priv/repo/migrations/20261123150100_grant_release_manage_to_custom_roles.exs:20-21, lib/nerves_hub/managed_deployments.ex:423-424, lib/nerves_hub/managed_deployments.ex:509-514, lib/nerves_hub/managed_deployments/orchestrator.ex:86-92.
  • Security: 1 finding, inline at priv/repo/migrations/20261123150100_grant_release_manage_to_custom_roles.exs:20.
  • Code quality: 3 findings, inline at priv/repo/migrations/20261123150100_grant_release_manage_to_custom_roles.exs:20, lib/nerves_hub/managed_deployments.ex:417-424, lib/nerves_hub/managed_deployments.ex:509-514.
  • Prose, comments and docs: 3 findings, inline at priv/repo/migrations/20261123150100_grant_release_manage_to_custom_roles.exs:20, lib/nerves_hub/accounts/permissions.ex:142, lib/nerves_hub/managed_deployments/deployment_release.ex:119-130.

The inline comments are in this review.

Screenshots of the UI changes, before and after (3 views)

Role editor deployment group permissions

Before After
Before After

The Deployment groups section gains a "Create, edit and approve releases" checkbox, "Edit deployment groups and their releases" becomes "Edit deployment group settings", and create now reads "Create deployment groups, along with managing releases"; both shots sit at the bottom of the page, so the extra row moves the section up a little.

Releases tab, settings-only role

Before After
Before After

Signed in as a member whose custom role has only deployment_group:update: the New release button (top right) and the release's Edit release button are gone after the change.

Deployment groups list, create-only role

Before After
Before After

Signed in as a member whose custom role has deployment_group:create and deployment_group:toggle but not deployment_group:release:manage: the New deployment group button in the header is hidden after the change.

rummager · prompts 885379605730 · automated, verify before acting.

@u7d-bot u7d-bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inline findings for e2d885fe66. The summary is in the rummager comment.

Comment thread lib/nerves_hub/accounts/permissions.ex Resolved
Comment thread lib/nerves_hub/managed_deployments.ex Resolved
Comment thread lib/nerves_hub/managed_deployments.ex Resolved
joshk and others added 2 commits November 24, 2026 09:08
Queueing deltas after a save commits now catches what it raises, logs it
and reports it to Sentry, so the save still answers with what it saved
and the deployments/update broadcast still goes out. Without it the
group's orchestrator kept working from the release before.

The orchestrator also reads its group again when a release's delta
status changes, so a release settled by the backup tick reaches it even
when the node that saved it went down before announcing it. The tick
leaves a release changed in the last minute alone, since its deltas may
still be on their way into the queue.

The migration gives deployment_group:release:manage only to roles with
deployment_group:update. A role with only deployment_group:create would
otherwise have gained approving steps and sending releases on every
group. The create permission's label now says it needs the release one.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@joshk

joshk commented Nov 23, 2026

Copy link
Copy Markdown
Collaborator Author

/rummager

@u7d-bot

u7d-bot commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Rummager review of 449d2d0c45

Sensitive areas: authorization, access control, personal data, other. Unchanged since the earlier review of e2d885fe66.

Pass: 5 suggestions.

  • Code quality: 1 finding, inline at lib/nerves_hub/managed_deployments/orchestrator.ex:233-241.
  • Prose, comments and docs: 4 findings, inline at AGENTS.md:398-399, lib/nerves_hub/managed_deployments.ex:353-358, lib/nerves_hub/managed_deployments.ex:421-425, lib/nerves_hub/managed_deployments.ex:1080-1084.
  • No findings: Correctness, Security.

The inline comments are in this review.

Screenshots of the UI changes, before and after (3 views)

Role editor permission list

Before After
Before After

In the Deployment groups section of the New role form, there is a new "Create, edit and approve releases" checkbox, "Edit deployment groups and their releases" now reads "Edit deployment group settings", and the create label now says it also needs the release permission.

Releases tab, settings-only role

Before After
Before After

This user's custom role has only deployment_group:update: "New release" (top right) and the expanded release's "Edit release" button show before the PR and are gone after it.

Deployment groups list, create-only role

Before After
Before After

This user's custom role has deployment_group:create but not deployment_group:release:manage, and the "New deployment group" button in the top right is no longer shown.

  • Note: On head, the two custom roles were created after the PR's migration ran, so the "settings only" role really has only deployment_group:update. A role that already existed when the migration ran would also have been given deployment_group:release:manage, and would keep its buttons.

rummager · prompts 885379605730 · automated, verify before acting.

u7d-bot added a commit to lawik/rummager-screenshots that referenced this pull request Nov 23, 2026
u7d-bot added a commit to lawik/rummager-screenshots that referenced this pull request Nov 23, 2026
u7d-bot added a commit to lawik/rummager-screenshots that referenced this pull request Nov 23, 2026
u7d-bot added a commit to lawik/rummager-screenshots that referenced this pull request Nov 23, 2026
u7d-bot added a commit to lawik/rummager-screenshots that referenced this pull request Nov 23, 2026
u7d-bot added a commit to lawik/rummager-screenshots that referenced this pull request Nov 23, 2026

@u7d-bot u7d-bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inline findings for 449d2d0c45. The summary is in the rummager comment.

Comment thread AGENTS.md Resolved
Comment thread lib/nerves_hub/managed_deployments.ex Resolved
Comment thread lib/nerves_hub/managed_deployments.ex Resolved
Comment thread lib/nerves_hub/managed_deployments.ex Resolved
Comment on lines 233 to 241
def handle_info(%Broadcast{topic: "deployment:" <> _, event: "release/delta_status"}, state) do
maybe_trigger_update(state)
{:ok, deployment_group} = ManagedDeployments.get_deployment_group(state.deployment_group)

maybe_trigger_update(%{
state
| deployment_group: deployment_group,
coordinator: select_coordinator(deployment_group)
})
end

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[SUGGESTION] The release/delta_status handler now repeats the deployments/update handler's body line for line. Code quality · definite

Both clauses re-read the group, pick the coordinator again and call maybe_trigger_update/1. Pull that into one private function, e.g. reload_and_trigger(state), and call it from both clauses. Then a later change to how the group is reloaded can't land in only one of them.

u7d-bot added a commit to lawik/rummager-screenshots that referenced this pull request Nov 23, 2026
u7d-bot added a commit to lawik/rummager-screenshots that referenced this pull request Nov 23, 2026
u7d-bot added a commit to lawik/rummager-screenshots that referenced this pull request Nov 23, 2026
u7d-bot added a commit to lawik/rummager-screenshots that referenced this pull request Nov 23, 2026
u7d-bot added a commit to lawik/rummager-screenshots that referenced this pull request Nov 23, 2026
u7d-bot added a commit to lawik/rummager-screenshots that referenced this pull request Nov 23, 2026
Co-authored-by: U7D Bot <lars+underbot@underjord.io>
@joshk
joshk merged commit 4456808 into main Nov 23, 2026
9 checks passed
@joshk
joshk deleted the feature/deployment-release-api branch November 23, 2026 20:44
joshk added a commit to nerves-hub/nh that referenced this pull request Nov 23, 2026
NervesHub now has endpoints for a deployment group's releases
(nerves-hub/nerves_hub_web#3338). These commands use them, and
`nh deployment update` and `nh firmware upload --deploy` create their
release with POST .../releases where the server has it, falling back to
the release PUT on older servers. The request order stays the same:
settings first, then the release, then --state on.

An older server answers every release route with the same 404 body as a
missing group or release, so a 404 is explained by asking for the group
(and, for one release, the group's release list).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants