balena-cli
balena-cli copied to clipboard
Allow setting local mode without cloud access
Expected Behavior
User would like a way to enable local while offline. This is the use case:
While completely offline at all times we should be able too:
- Burn a preloaded or pre-downloaded development Balena image to a sd card
- Boot the device and put it into local-mode
- Update the device using
balena push
(which isn't working at the moment)
Actual Behavior
It seems this is currently not possible.
[lmbarros] This issue has attached support thread https://jel.ly.fish/f41e427a-0614-4e64-8abd-48612060f364
The implementation of the balena device local-mode
command:
https://github.com/balena-io/balena-cli/blob/v12.55.8/lib/commands/device/local-mode.ts#L87-L99
... basically consists of calls to the balena SDK's models.device.enableLocalMode()
and related functions, whose implementation is basically setting a device configuration variable through the balenaCloud API:
https://github.com/balena-io/balena-sdk/blob/v16.3.0/lib/models/device.ts#L1730
configVar.set(device.id, LOCAL_MODE_ENV_VAR, '1');
From there, the balenaCloud API would presumably notify the supervisor on the device through the VPN link, or failing that, the supervisor would regularly poll its "target state" from the balenaCloud API.
Therefore, I gather that the current platform architecture requires the device to be online. I think that for this to be possible offline, the first step would be for the supervisor to offer a local API call to allow itself to be switched into local mode, which raises the question of source of truth: if the cloud states that the device should not be in local mode but the CLI made a local supervisor API call for the supervisor to switch into local mode, what should the supervisor do? I gather that the supervisor currently has local endpoints to get and set its target state: GET /v2/local/target-state POST /v2/local/target-state ... but I understand that those endpoints can only be used while the device is already in local mode, and there is no way to switch the supervisor into and out of local mode other than going through the balenaCloud API. This understanding needs confirmation though.
Anyway, I don't think this issue is actionable in the balena CLI without first going through a platform product / architecture discussion. The JF Pattern attached to the support thread could be a starting point.