Skip to content

Updates ​

Controllers update over the air, from Docker Hub, when a user accepts the prompt in the mobile app. The update is carried out on the controller by controlfreak-docker-updater, a short lived container started for each run.

For publishing the images an update installs, see Releasing.

When the app offers an update ​

The app compares EXPO_PUBLIC_CONTROLLER_VERSION, the version it was built against, with the version in GET /health.

Controller isResult
Behind on major or minorrequired, the app shows the update screen
Behind on patch onlyavailable, the app shows a banner and a row on the Help screen
Equal or aheadcurrent

What the controller does ​

Starting a run ​

The app calls POST /prepare-update with the updater's container config, ControllerUpdaterConfig in mobile-controller/src/data/controller.tsx.

  1. With no internet, the API answers 503 and changes nothing.
  2. The API sets status to update#preparing, removes any old updater container, pulls the updater image and starts it detached.
  3. Any error sets update#failed and answers 500.

The updater image is always pulled on :latest. The version the run installs comes from EXPECTED_VERSION in the container environment, which the app fills from EXPO_PUBLIC_CONTROLLER_VERSION. A run with no EXPECTED_VERSION fails.

The steps ​

The updater sets status to update#ready, then runs each step in order, publishing the step name to controller/update/status.

StepWhat it does
db_backupCopies controller.db to controller.db.bak
hashPulls every managed image and compares it with the one on disk. Changed images make up the run.
snapshotCommits each running container that will change as <container>-backup:pre-update-<hash>
os_updaterPulls and runs os-updater, which refreshes packages and applies board settings
image_bootStops the changed containers and starts them on the new images
pruningRemoves old snapshots, keeping the newest per container, and prunes unused images

image_boot runs in a set order. Services that send device commands, the scheduler, tether, themer and freeze protection, stop first and start last, so nothing drives hardware while the rest restart. controlfreak-api starts before the others, and the updater waits up to 90 seconds for it to answer /health. An API that never answers fails the run.

Containers listed under retired in config.prod.json are stopped and not started again. That is how a service is removed from the fleet.

api-bridge is only included when it is running, which means the controller is web enabled.

Finishing ​

ResultWhat happens
SuccessPublishes completed, and writes the new version and update#completed through POST /controller-config. The status stays there until the app calls POST /clean-update, which sets healthy and removes the updater.
FailurePublishes failure and sets update#failed. Snapshots and the database backup are kept so a restore can be offered.
success:  healthy -> update#preparing -> update#ready -> update#completed -> healthy
failure:  healthy -> update#preparing -> update#ready -> update#failed
restore:  update#failed -> update#restoring -> update#restored -> healthy
no net:   healthy, 503, nothing written

Restoring ​

GET /restore-update reports whether any container has a snapshot it is not already running. POST /restore-update starts the updater with RESTORE=1, which:

  1. Sets update#restoring.
  2. Copies controller.db.bak back over controller.db, when there is one.
  3. Starts every container with a snapshot on that snapshot.
  4. Sets update#restored.

Snapshots outlive the run that took them, so a restore also rolls back an update that succeeded. It works without internet, and only pulls the updater image when it is missing.

A failed updater also stays running and listens on controller/update/restore, which triggers the same restore.

How the app follows a run ​

StageWhat the app reads
StartingPOST /prepare-update. 200 or 504 moves on, 503 shows no internet, anything else shows the update failed to start.
Waiting for the updaterPolls GET /health every 3 seconds until update#ready, or update#failed
RunningFollows controller/update/status over MQTT, one step at a time
On launchReads GET /health. A saved update# status lands on the matching screen, so a relaunch mid run picks up where it was.

A 504 counts as started because over remote, pulling the updater often outlasts the 15 second api-bridge timeout while the controller carries on.

controller/update/status is retained, so a new subscriber first receives the result of the last run. The app ignores a finished result until it has seen update#ready for the current run.

image_boot restarts the API and the broker, so the connection drops for a while during every run. The app reconnects on its own and picks the status back up.

ButtonWhat it does
Restore, after a failed runPublishes {} to controller/update/restore, which the failed updater picks up
Restore Last Update, ControllerRestoreStatusPOST /restore-update, for rolling back a run that succeeded. Hidden on the Help screen in the current app.
Done, or dismissing a failurePOST /clean-update, which clears the saved result. The app then reconnects and reads the new version.

The logic lives in src/services/updater.ts and src/stores/updateStatusStore.ts in mobile-controller, with the screen in src/components/controller/ControllerUpdater.tsx.

Where containers are defined ​

After an update, containers are run from the configs in shared-lib/cfp_shared/configs/config.prod.json, not from docker-compose.yaml. Each entry is a full container definition: image, container name, ports, volumes, environment and restart policy.

KeyWhat it holds
targetsEvery always running container, in restart order
api_bridgeapi-bridge, only updated when running
aws_installerThe installer the API runs on web enablement
os_updater, docker_updaterThe two update containers
retiredContainer names to stop and never start again
mosquittoThe broker

A change to how a service runs, such as a new volume or environment variable, has to go in config.prod.json to reach controllers in the field. The compose files only matter when a Pi is flashed.

DOCKER_REGISTRY rewrites the org on every image name in these configs, which is how a staging controller pulls from krumware.

Compatibility ​

The updater image reaches controllers before the database-api it talks to has been updated. New updater code has to work against the oldest database-api in the field.

  • Pass new inputs to the updater through the environment array in ControllerUpdaterConfig. Every database-api version forwards it as is.
  • Do not rely on a new API endpoint from the updater until every controller is running a database-api that has it.

To check whether a change has reached a release:

bash
git -C rpi-controller tag --contains <sha>

Testing an update ​

Use a staging controller and staging images. See Releasing for the full flow, and Onboard development for reaching the Pi.

bash
curl http://controlfreak.local:8000/health
curl http://controlfreak.local:8000/restore-update
sudo docker logs -f controlfreak-docker-updater
sudo docker images | grep backup