Skip to content

Releasing ​

A ControlFREAK release has up to three parts, shipped in this order:

  1. Infrastructure, only when a stack in infrastructure/ changed.
  2. Controller, the Docker images built from rpi-controller.
  3. 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 ​

WhatWhere it livesFormat
Controller versionrpi-controller git tagvX.Y.Z, candidates vX.Y.Z-rcN
Controller version the app expectsEXPO_PUBLIC_CONTROLLER_VERSION in mobile-controllerX.Y or X.Y.Z, no v
App versionversion in mobile-controller/app.config.jsX.Y.Z
App Store listing versionapple.version in mobile-controller/store.config.jsonX.Y.Z
Build numberManaged 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 ​

StagingProduction
Docker Hub orgkrumwarekrumcontrolfreak
rpi-controller branchstagingmain
Build triggerpush to stagingtag vX.Y.Z
GitHub secrets and variablesdevelopment environmentrepository level
EXPO_PUBLIC_DOCKER_REGISTRYkrumwareunset, or krumcontrolfreak
EXPO_PUBLIC_BUILD_ENVdevprod

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:

  1. cognito
  2. fleet-provisioning
  3. authenticator
  4. fleet-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 deploy

samconfig.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/ -q

On 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-rc1

4. 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:

  1. Open the app and start the update from the prompt.
  2. Watch GET http://<host>:8000/health move through the statuses below and land on healthy with the new version.
  3. 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 -> healthy

To 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:latest

Repeat 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-notes

The tag starts build-push-docker-images-main.yml, which:

  1. Builds and pushes krumcontrolfreak/controlfreak-mqtt-builder:latest, the base every MQTT service builds on.
  2. Checks that AWS_IOT_ENDPOINT, AWS_IOT_FP_TEMPLATE_NAME and AWS_IOT_THING_PREFIX are set, and fails the run if any is missing.
  3. Writes the claim certificate and key from AWS_IOT_CLAIM_CERT_B64 and AWS_IOT_CLAIM_KEY_B64 into certs/ for the aws-installer image.
  4. Builds the services group in docker-bake.hcl and pushes every image to krumcontrolfreak.

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:

NameKind
DOCKERHUB_USERNAME, DOCKERHUB_TOKENsecret
AWS_IOT_ENDPOINT, AWS_IOT_FP_TEMPLATE_NAME, AWS_IOT_THING_PREFIXvariable or secret
AWS_IOT_CLAIM_CERT_B64, AWS_IOT_CLAIM_KEY_B64secret

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.

  1. The app calls POST /prepare-update with ControllerUpdaterConfig. A 503 means the controller has no internet and nothing was changed.
  2. The controller pulls and starts controlfreak-docker-updater.
  3. 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.
  4. 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.sh

clean_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.img

make-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/sdX2

Flash 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_VERSION to the controller release.
  • version in app.config.js.
  • apple.version in store.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.

VariableProduction value
EXPO_PUBLIC_BUILD_ENVprod
EXPO_PUBLIC_CONTROLLER_VERSIONthe controller release
EXPO_PUBLIC_DOCKER_REGISTRYunset, or krumcontrolfreak
EXPO_PUBLIC_DEFAULT_HOSTcontrolfreak.local
EXPO_PUBLIC_AWS_POOL_ID, EXPO_PUBLIC_AWS_POOL_CLIENT_IDcognito stack outputs
EXPO_PUBLIC_IOT_ENDPOINT, EXPO_PUBLIC_IOT_CUSTOM_AUTH_NAMEIoT Core endpoint, authenticator stack
EXPO_PUBLIC_FLEET_URLfleet-list stack base URL
EXPO_PUBLIC_MQTT_CLIENT_USERNAME, EXPO_PUBLIC_MQTT_CLIENT_PASSWORDcontroller broker credentials
EXPO_PUBLIC_INVITE_SECRETinvite 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 production

3. Check the code ​

bash
cd mobile-controller
yarn install
yarn check:eslint

4. Build ​

Cloud builds:

bash
eas build --platform ios --profile production
eas build --platform android --profile production

Local builds, with .env loaded:

bash
yarn build:ios
yarn build-production:android

Install 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 internal track as a draft, per the submit.production block in eas.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:push

Verifying a release ​

  • GET /health on an updated controller returns the new version and healthy.
  • 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-update

Production 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.