Skip to content

Instantly share code, notes, and snippets.

@cywang117
Created April 27, 2022 00:05
Show Gist options
  • Save cywang117/4237480f9655101df67e7e687f87932a to your computer and use it in GitHub Desktop.
Save cywang117/4237480f9655101df67e7e687f87932a to your computer and use it in GitHub Desktop.
Pinning Supervisor version in the API (this will NOT allow downgrades)
  1. Run update-balena-supervisor or update-resin-supervisor on the device. If that doesn't work...

  2. PATCH the should_be_managed_by__release (or should_be_managed_by__supervisor_release if that doesn't work) field in the device resource (/v6/device) to equal the release ID of the target Supervisor version. To find the release ID of the target Supervisor version: (Replace variables starting with $ with the fields that are relevant to your case, and run this in a dashboard dev console)

await sdk.pine.get({
    resource: 'supervisor_release',
    options: {
        $filter: {
            is_for__device_type: {
                slug: $DEVICE_MACHINE_NAME_SLUG
            },
            supervisor_version: $VERSION
        },
    }
})

It will be listed under id.

Then, to patch the device, run the following from a host OS terminal instance:

curl -X PATCH \
"https://api.balena-cloud.com/v6/device($(cat /mnt/boot/config.json | jq -r '.deviceId'))" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $(cat /mnt/boot/config.json | jq -r '.deviceApiKey')" \
--data '{
    "should_be_managed_by__release": $RELEASE_ID
}'

If the PATCH succeeds, you will receive a 2xx status code with your response. To verify success/failure, after PATCH-ing, check the device resource's should_be_managed... field:

await sdk.models.device.get($UUID)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment