Appearance
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 is | Result |
|---|---|
| Behind on major or minor | required, the app shows the update screen |
| Behind on patch only | available, the app shows a banner and a row on the Help screen |
| Equal or ahead | current |
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.
- With no internet, the API answers
503and changes nothing. - The API sets status to
update#preparing, removes any old updater container, pulls the updater image and starts it detached. - Any error sets
update#failedand answers500.
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.
| Step | What it does |
|---|---|
db_backup | Copies controller.db to controller.db.bak |
hash | Pulls every managed image and compares it with the one on disk. Changed images make up the run. |
snapshot | Commits each running container that will change as <container>-backup:pre-update-<hash> |
os_updater | Pulls and runs os-updater, which refreshes packages and applies board settings |
image_boot | Stops the changed containers and starts them on the new images |
pruning | Removes 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
| Result | What happens |
|---|---|
| Success | Publishes 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. |
| Failure | Publishes 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 writtenRestoring
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:
- Sets
update#restoring. - Copies
controller.db.bakback overcontroller.db, when there is one. - Starts every container with a snapshot on that snapshot.
- 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
| Stage | What the app reads |
|---|---|
| Starting | POST /prepare-update. 200 or 504 moves on, 503 shows no internet, anything else shows the update failed to start. |
| Waiting for the updater | Polls GET /health every 3 seconds until update#ready, or update#failed |
| Running | Follows controller/update/status over MQTT, one step at a time |
| On launch | Reads 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.
| Button | What it does |
|---|---|
| Restore, after a failed run | Publishes {} to controller/update/restore, which the failed updater picks up |
Restore Last Update, ControllerRestoreStatus | POST /restore-update, for rolling back a run that succeeded. Hidden on the Help screen in the current app. |
| Done, or dismissing a failure | POST /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.
| Key | What it holds |
|---|---|
targets | Every always running container, in restart order |
api_bridge | api-bridge, only updated when running |
aws_installer | The installer the API runs on web enablement |
os_updater, docker_updater | The two update containers |
retired | Container names to stop and never start again |
mosquitto | The 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
environmentarray inControllerUpdaterConfig. Everydatabase-apiversion forwards it as is. - Do not rely on a new API endpoint from the updater until every controller is running a
database-apithat 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