Appearance
Releasing
A ControlFREAK release has up to three parts, shipped in this order:
- Infrastructure, only when a stack in
infrastructure/changed. - Controller, the Docker images built from
rpi-controller. - Mobile app, the store builds of
mobile-controller.
The controller ships before the app because the app carries the controller version it expects. An app that expects a version the registry does not have yet prompts users for an update that cannot land.
Versions
| What | Where it lives | Format |
|---|---|---|
| Controller version | rpi-controller git tag | vX.Y.Z, candidates vX.Y.Z-rcN |
| Controller version the app expects | EXPO_PUBLIC_CONTROLLER_VERSION in mobile-controller | X.Y or X.Y.Z, no v |
| App version | version in mobile-controller/app.config.js | X.Y.Z |
| App Store listing version | apple.version in mobile-controller/store.config.json | X.Y.Z |
| Build number | Managed by EAS (appVersionSource: remote, autoIncrement) | automatic |
EXPO_PUBLIC_CONTROLLER_VERSION must equal the controller tag being released. The app compares it to the version the controller reports. A controller behind on major or minor gets a required update, one behind only on patch gets an optional one, and anything else is current.
The controller does not compute its own version. When an update succeeds, the docker-updater writes the EXPECTED_VERSION it was started with into the controller database, and the app supplies that value from EXPO_PUBLIC_CONTROLLER_VERSION.
Registries and branches
| Staging | Production | |
|---|---|---|
| Docker Hub org | krumware | krumcontrolfreak |
rpi-controller branch | staging | main |
| Build trigger | push to staging | tag vX.Y.Z |
| GitHub secrets and variables | development environment | repository level |
EXPO_PUBLIC_DOCKER_REGISTRY | krumware | unset, or krumcontrolfreak |
EXPO_PUBLIC_BUILD_ENV | dev | prod |
Infrastructure
Skip this section when nothing in infrastructure/ changed.
Every stack deploys on its own, in us-east-2, from its own directory. Deploy in this order, since later stacks take earlier stacks' outputs as parameters:
cognitofleet-provisioningauthenticatorfleet-list
bash
cd infrastructure/cognito
aws cloudformation deploy --template-file template.yaml --stack-name controlfreak-cognito
cd infrastructure/fleet-provisioning # and authenticator, fleet-list
sam build && sam deploysamconfig.toml in each stack holds the parameters, so sam deploy needs no arguments. After each deploy, check the stack outputs against what the app and controllers are configured with:
bash
aws cloudformation describe-stacks --stack-name <stack> --query 'Stacks[0].Outputs'All AWS changes go through these templates. Anything changed in the console is reverted by the next deploy.
Controller release
1. Check compatibility
The controlfreak-docker-updater image is pulled on :latest at the start of every update, so a new updater reaches controllers before the database-api it talks to is updated. The updater has to work against the oldestdatabase-api still in the field. New inputs to the updater go in the environment array of ControllerUpdaterConfig (mobile-controller/src/data/controller.tsx), which every database-api version forwards as is.
database-api migrations must have a single alembic head. tests/api/test_migrations.py fails when there is more than one. Resolve a split with a merge migration whose down_revision is a tuple of both heads.
To see whether a commit is already in a release:
bash
git -C rpi-controller tag --contains <sha>2. Run the tests
CI runs the three suites on every pull request into development, staging and main. To run them locally from rpi-controller/:
bash
python -m venv .venv && . .venv/bin/activate
pip install pytest pytest-cov requests paho-mqtt fastapi sqlalchemy "pydantic>=2" httpx pytz alembic
python -m pytest tests/ --ignore=tests/api --ignore=tests/integration -q
DATABASE_PATH="sqlite:///:memory:" python -m pytest tests/integration/ -q
DATABASE_PATH="sqlite:///:memory:" python -m pytest tests/api/ -qOn NixOS, make test-q, make test-integration-q and make test-api-q do the same inside shell.nix and shell-api.nix.
3. Build a staging candidate
Merge development into staging and push. The build-push-docker-images-staging.yml workflow builds every image for linux/arm64 and linux/amd64 and pushes it to krumware on :latest.
Tag the candidate so it can be traced later:
bash
git -C rpi-controller tag v1.2.0-rc1 staging
git -C rpi-controller push origin v1.2.0-rc14. Test the candidate
Point a development build of the app at staging images by setting EXPO_PUBLIC_DOCKER_REGISTRY="krumware" and EXPO_PUBLIC_CONTROLLER_VERSION to the version being released. Then, on a staging controller:
- Open the app and start the update from the prompt.
- Watch
GET http://<host>:8000/healthmove through the statuses below and land onhealthywith the new version. - Exercise the controller over both local and remote connections.
success: healthy -> update#preparing -> update#ready -> update#completed -> healthy
failure: healthy -> update#preparing -> update#ready -> update#failed
restore: update#failed -> update#restoring -> update#restored -> healthyTo test a single docker-updater image without the full pipeline, build it, push it to a test org, and point ControllerUpdaterConfig.image_name at it:
bash
docker buildx bake docker-updater --set docker-updater.platform=linux/arm64
docker tag krumcontrolfreak/controlfreak-docker-updater <org>/controlfreak-docker-updater:latest
docker push <org>/controlfreak-docker-updater:latestRepeat with -rc2, -rc3 and so on until the candidate is clean.
5. Release to production
Merge staging into main, then create a GitHub release on main with a tag of the form vX.Y.Z:
bash
gh release create v1.2.0 --repo controlfreakpool/rpi-controller --target main --generate-notesThe tag starts build-push-docker-images-main.yml, which:
- Builds and pushes
krumcontrolfreak/controlfreak-mqtt-builder:latest, the base every MQTT service builds on. - Checks that
AWS_IOT_ENDPOINT,AWS_IOT_FP_TEMPLATE_NAMEandAWS_IOT_THING_PREFIXare set, and fails the run if any is missing. - Writes the claim certificate and key from
AWS_IOT_CLAIM_CERT_B64andAWS_IOT_CLAIM_KEY_B64intocerts/for the aws-installer image. - Builds the
servicesgroup indocker-bake.hcland pushes every image tokrumcontrolfreak.
Images are pushed on :latest. The workflow does not set the bake VERSION variable, so no version tagged image is published.
The workflow needs these on the repository:
| Name | Kind |
|---|---|
DOCKERHUB_USERNAME, DOCKERHUB_TOKEN | secret |
AWS_IOT_ENDPOINT, AWS_IOT_FP_TEMPLATE_NAME, AWS_IOT_THING_PREFIX | variable or secret |
AWS_IOT_CLAIM_CERT_B64, AWS_IOT_CLAIM_KEY_B64 | secret |
The staging workflow reads the same names from the development environment, plus a DOCKER_REGISTRY variable that defaults to krumware.
6. How it reaches controllers
Controllers update when a user accepts the prompt in the app.
- The app calls
POST /prepare-updatewithControllerUpdaterConfig. A503means the controller has no internet and nothing was changed. - The controller pulls and starts
controlfreak-docker-updater. - The updater backs up the database, compares each service image's hash with the registry, snapshots the images that changed, runs the OS updater, pulls and restarts the changed services, and prunes old images.
- It checks that the API answers on the new image, then writes the new version and returns the controller to
healthy.
api-bridge is only updated on controllers where it is running, which is the web enabled ones.
7. Build a Pi image
A fresh image for new hardware is taken from a prepared controller running the release.
bash
cd rpi-controller
DRY_RUN=1 ./scripts/clean_controller.sh
./scripts/clean_controller.shclean_controller.sh clears state, then device identity, then powers the Pi off. Do not boot the drive again, a boot regenerates the machine id and SSH host keys. Move the drive to a workstation and image it:
bash
sudo DRY_RUN=1 ./scripts/make-image.sh /dev/sdX controlfreak.img
sudo ./scripts/make-image.sh /dev/sdX controlfreak.imgmake-image.sh shrinks the root partition on the source drive in place, then copies only the used space. To grow the source drive back afterward:
bash
echo "," | sudo sfdisk -N 2 --force /dev/sdX && sudo resize2fs /dev/sdX2Flash the image to a clean device and run it through setup, pairing and remote control before distributing it.
Mobile release
The app is Expo, built and submitted with EAS under the dimig-digs account. There are no over the air updates, every change ships as a store build.
1. Set versions
EXPO_PUBLIC_CONTROLLER_VERSIONto the controller release.versioninapp.config.js.apple.versioninstore.config.json, to the same value.
2. Set the environment
Cloud builds read variables from the EAS environment named by the build profile (production for the production profile). Local builds read .env through dotenv. .env.template lists every variable.
| Variable | Production value |
|---|---|
EXPO_PUBLIC_BUILD_ENV | prod |
EXPO_PUBLIC_CONTROLLER_VERSION | the controller release |
EXPO_PUBLIC_DOCKER_REGISTRY | unset, or krumcontrolfreak |
EXPO_PUBLIC_DEFAULT_HOST | controlfreak.local |
EXPO_PUBLIC_AWS_POOL_ID, EXPO_PUBLIC_AWS_POOL_CLIENT_ID | cognito stack outputs |
EXPO_PUBLIC_IOT_ENDPOINT, EXPO_PUBLIC_IOT_CUSTOM_AUTH_NAME | IoT Core endpoint, authenticator stack |
EXPO_PUBLIC_FLEET_URL | fleet-list stack base URL |
EXPO_PUBLIC_MQTT_CLIENT_USERNAME, EXPO_PUBLIC_MQTT_CLIENT_PASSWORD | controller broker credentials |
EXPO_PUBLIC_INVITE_SECRET | invite secret |
EXPO_PUBLIC_BUILD_ENV=prod names the app Control Freak instead of Control Freak (Staging) and removes the debugger overlay.
To inspect the EAS side:
bash
eas env:list --environment production3. Check the code
bash
cd mobile-controller
yarn install
yarn check:eslint4. Build
Cloud builds:
bash
eas build --platform ios --profile production
eas build --platform android --profile productionLocal builds, with .env loaded:
bash
yarn build:ios
yarn build-production:androidInstall the production build on a clean device and run setup, pairing, local and remote control, and a controller update end to end.
5. Submit
bash
eas submit --platform ios --profile production
eas submit --platform android --profile production- iOS uploads to App Store Connect. Release to TestFlight or submit for review from there.
- Android uploads to the Play Console
internaltrack as a draft, per thesubmit.productionblock ineas.json. Roll it out and promote it from the Play Console.
To push the App Store listing text in store.config.json:
bash
eas metadata:pushVerifying a release
GET /healthon an updated controller returns the new version andhealthy.- A freshly imaged controller provisions, pairs and is controllable remotely against production.
- An existing field controller still works over local and remote after the release.
- CloudWatch shows no rise in errors on the authorizer and fleet Lambdas, and IoT Core shows no rise in connect or authorization failures.
Rolling back
Controller. The updater snapshots every image it replaces and keeps the most recent snapshot per image, after a failed update and a successful one. GET /restore-update reports whether a restore is available, and POST /restore-update starts the updater in restore mode, which puts the snapshotted images back. It works without internet, since the images are already on the controller. In the app, Restore on the failure screen rolls back a failed run. The Restore Last Update control for rolling back a successful run is hidden on the Help screen, so for now call the endpoint directly:
bash
curl -X POST http://controlfreak.local:8000/restore-updateProduction images are only published on :latest, so rolling the whole fleet back means reverting the change on main and releasing it under a new patch tag.
Infrastructure. Check out the previous commit of the stack and deploy it again.
App. Ship a new build with a higher version. In the Play Console a staged rollout can be halted. In App Store Connect a version in review can be pulled before release.