Repository navigation
Add an API for deployment group releases - #3338
Conversation
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>
Rummager review of
|
u7d-bot
left a comment
There was a problem hiding this comment.
Inline findings for f2f0c9adf8. The summary is in the rummager comment.
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>
|
/rummager |
Rummager review of
|
u7d-bot
left a comment
There was a problem hiding this comment.
Inline findings for 7996e282fb. The summary is in the rummager comment.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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>
|
/rummager |
Rummager review of
|
| 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 |
|---|---|
![]() |
![]() |
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 |
|---|---|
![]() |
![]() |
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
left a comment
There was a problem hiding this comment.
Inline findings for e2d885fe66. The summary is in the rummager comment.
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>
|
/rummager |
Rummager review of
|
| 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 |
|---|---|
![]() |
![]() |
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 |
|---|---|
![]() |
![]() |
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
left a comment
There was a problem hiding this comment.
Inline findings for 449d2d0c45. The summary is in the rummager comment.
| 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 |
There was a problem hiding this comment.
[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.
Co-authored-by: U7D Bot <lars+underbot@underjord.io>
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>












Adds
/deployments/:name/releasesto 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/:namewithfirmwareorarchive, and that request ignores every other group setting in its body. ThenhCLI has to split one update into as many as three requests, and it can't list releases or editrequiredor the connecting code on a release that already exists (found in nerves-hub/nh#25). A laternhPR addsnh deployment release list|show|create|updateagainst these endpoints.PUT /deployments/:namekeeps 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/releasesand accept a user token or a product API key. A release is identified by itsnumberwithin the group.GET /releasesGET /releases/:numberPOST /releasesdeployment_group:release:managelocationheader, or 422PATCH /releases/:numberdeployment_group:release:manageEvery 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.POSTbody, flat (not wrapped indeploymentthe way thePUTis):{ "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
firmwareis required; anarchiveleft out or sent as""means none. Anullforrequiredorconnecting_code_modeis a 422; leave them out for the defaults (false,last). Here the connecting code is the release's own; thePUTdrops it because there it means the group's.PATCHbody, every field optional, anything left out keeps its value:{ "required": true, "connecting_code": null, "connecting_code_mode": "first" }nullor""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.DeploymentReleaseholds which fields each changeset casts; the controller passes the body through.A release, under
data(a list forGET /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_byis{"type": "api_key", "name": ...}for a release a product API key made, andnullfor releases made before authors were recorded.connecting_code_modeisfirst,lastoroverride;delta_statusisready,preparingorfailed.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:manageMaking a release used to need
deployment_group:update, the same permission as changing the group's settings. Everything done to a release now needsdeployment_group:release:manageinstead, 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-inmanageandadminroles have it.deployment_group:updatekeeps the group's Settings tab.PUT /deployments/:namewithfirmwareorarchivemakes a release, so it needs the new permission. APUTwithout either still needsdeployment_group:update.Creating a deployment group needs
deployment_group:release:manageas well asdeployment_group:create, in the web UI and inPOST /deployments. A new group starts with a release of the firmware it's given, so without this a role withdeployment_group:createanddeployment_group:togglecould ship firmware.A migration gives
deployment_group:release:manageto every custom role that hasdeployment_group:update, so those roles keep editing and approving releases. A role withdeployment_group:createbut notdeployment_group:updateisn'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
readybefore its deltas are queued would be sent as whole firmware, so a release that will queue deltas now startspreparing: a new release, or one marked required, in a group that's on with delta updates on. The recalculation after the queueing settles it, toreadyif 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:Choices I made without Josh
firmwareorarchiveUUID the product doesn't have gets a 422does not exist. ThePUTinstead drops an unknown archive silently and creates a release without it, which a new endpoint has no reason to copy.deployment_group:release:manage(a member, or amanageAPI key) can set it over the API as well as in the web UI.created_byincludes 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/3takes 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/2is new, and loads a release the same waylist_deployment_releases/1loads 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
archivehas none, even when the current release has one. I left the API that way, and itsPOSTdocs say so, so the CLI can pass the archive along itself. Should the API match the form?🤖 Generated with Claude Code