Set up environments and tenants
Model staging, production and per-tenant builds as channels, promote releases between them, pause one in an incident and see what the public index exposes.
Staging, production and a build per tenant are channels. A build follows one channel, the CLI releases to it, and promoting is a release from one channel to another. HotCodePush creates production with the app. Every other environment is a channel you create, protect and point builds at.
Prerequisites
- Channels explains what a channel serves and how a device picks one.
- Quickstart has run, so the SDK is installed and a first release is live.
- You hold the Owner or Admin role, to protect a channel.
1. Create the channels
If your channels exist already, skip to step 3. A name is letters, digits, - and _, 1 to 64 characters, unique per app.
npx hotcodepush channel create --name stagingchannel has every flag.
2. Protect production
npx hotcodepush channel update --channel production --protectedOnly Owners and Admins change what a protected channel serves, and --protected false turns it off.
3. Point a build at its channel
A build follows the channel hotcodepush.json names:
{
"appId": "7f3c2d1e-9a4b-4c5d-8e6f-0a1b2c3d4e5f",
"channel": "production"
}A build flavour follows another channel through HOTCODEPUSH_CHANNEL in its build environment:
export HOTCODEPUSH_CHANNEL=stagingThe build step resolves the name to the channel's id and writes the id into the binary. Renaming a channel moves no device, and pointing shipped binaries at another channel takes a new store build. A test phone follows staging through a staging build, or through setChannel as step 6 shows.
4. Release to staging
npx hotcodepush release create --channel staging --path distThe CLI states the reach, asks once and uploads.
5. Promote to production
npx hotcodepush release create --from-channel staging --channel production--from-channel takes the newest active release of staging and releases its bundle, uploading nothing. --dry-run prints the reach first. Conditions, a rollout percentage and --progression apply to a promotion like to any release.
The release applies within about a minute. If nothing happens, see Troubleshooting.
6. One channel per tenant
A tenant whose bundle other tenants must not read gets a channel of its own. Every device on a channel can fetch every bundle in it. An attribute chooses a release, never which bytes a device may read. Target devices with attributes spells it out.
npx hotcodepush channel create --name tenant-acmeStore the id the command prints with the tenant in your backend, and hand it to the app at sign-in:
import { HotCodePush } from "@hotcodepush/capacitor-live-updates";
export async function onSignIn(session: { channelId: string }) {
await HotCodePush.setChannel({ id: session.channelId });
await HotCodePush.sync();
}
export async function onSignOut() {
await HotCodePush.setChannel(null);
}A channel id cannot be guessed, and it is the only way to reach a channel nobody flagged discoverable. So a tenant's bundle is as private as the id your backend hands out. Channels explains what setChannel does.
7. Decide what the public index exposes
A device fetches updates before any account exists on it, so what it reads is public to anyone holding the ids. The channel index, release notes and version labels included, is readable with the app id and the channel id. The app's channels index lists the discoverable channels by name and is readable with the app id alone.
Flag a channel discoverable only when setChannel({ name }) needs it:
npx hotcodepush channel update --channel beta --discoverableThe console has the same switch in the channel's Access island. Privacy and device data lists everything the index carries and what is never public.
8. Pause a channel in an incident
npx hotcodepush channel pause --channel productionThe CLI asks once, and --yes answers in a pipeline. The resume command, npx hotcodepush channel resume --channel production, lifts the pause.
A paused channel serves nothing new: devices keep what they have. Both apply within about a minute. To stop one release instead, pause or revoke that release, as Roll back a release covers.
Next steps
- Test with preview channels creates a channel per pull request with an expiry.
- Switch channels by link builds the QR code and the deep-link handler that calls
setChannel. - Target devices with attributes covers choosing a release within a channel.
Last updated on
Target devices with attributes
Set attributes such as userId, tenant or plan in the app, check the reach with the audience preview and release to the devices that match.
Test with preview channels
Create an expiring channel per pull request from CI, release the build to it and hand testers a QR code that points their phone at it.