create-expo-updates-server 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +19 -0
- package/bin/create-expo-updates-server.mjs +5 -0
- package/dist/template/.env.docker.example +15 -0
- package/dist/template/.env.example +35 -0
- package/dist/template/Dockerfile +42 -0
- package/dist/template/LICENSE +21 -0
- package/dist/template/README.md +665 -0
- package/dist/template/app/api/admin/access-tokens/[id]/route.ts +25 -0
- package/dist/template/app/api/admin/access-tokens/route.test.ts +73 -0
- package/dist/template/app/api/admin/access-tokens/route.ts +90 -0
- package/dist/template/app/api/admin/embedded-updates/[embeddedUpdateId]/route.ts +25 -0
- package/dist/template/app/api/admin/embedded-updates/route.test.ts +102 -0
- package/dist/template/app/api/admin/embedded-updates/route.ts +47 -0
- package/dist/template/app/api/admin/emergency-redirects/[id]/route.ts +62 -0
- package/dist/template/app/api/admin/emergency-redirects/route.test.ts +84 -0
- package/dist/template/app/api/admin/emergency-redirects/route.ts +56 -0
- package/dist/template/app/api/admin/login/route.test.ts +55 -0
- package/dist/template/app/api/admin/login/route.ts +52 -0
- package/dist/template/app/api/admin/logout/route.ts +20 -0
- package/dist/template/app/api/admin/session/route.ts +15 -0
- package/dist/template/app/api/admin/updates/[encodedKey]/deactivate/route.ts +33 -0
- package/dist/template/app/api/admin/updates/[encodedKey]/promote/route.ts +29 -0
- package/dist/template/app/api/admin/updates/[encodedKey]/rollback/route.ts +29 -0
- package/dist/template/app/api/admin/updates/[encodedKey]/route.ts +96 -0
- package/dist/template/app/api/admin/updates/route.test.ts +142 -0
- package/dist/template/app/api/admin/updates/route.ts +32 -0
- package/dist/template/app/api/assets/route.ts +6 -0
- package/dist/template/app/api/health/route.test.ts +26 -0
- package/dist/template/app/api/health/route.ts +42 -0
- package/dist/template/app/api/manifest/route.ts +6 -0
- package/dist/template/app/api/update-complete/route.ts +6 -0
- package/dist/template/app/favicon.ico +0 -0
- package/dist/template/app/globals.css +26 -0
- package/dist/template/app/layout.tsx +34 -0
- package/dist/template/app/login/page.tsx +77 -0
- package/dist/template/app/page.tsx +12 -0
- package/dist/template/app/updates/[encodedKey]/page.tsx +482 -0
- package/dist/template/app/updates/embedded/page.tsx +164 -0
- package/dist/template/app/updates/emergency-redirects/page.tsx +430 -0
- package/dist/template/app/updates/layout.tsx +14 -0
- package/dist/template/app/updates/page.tsx +281 -0
- package/dist/template/docker-compose.yml +100 -0
- package/dist/template/docs/expo-app-setup.md +497 -0
- package/dist/template/docs/getting-started.md +502 -0
- package/dist/template/docs/getting-started.ru.md +623 -0
- package/dist/template/docs/index.md +57 -0
- package/dist/template/docs/migrations/schema.sql +363 -0
- package/dist/template/docs/npm-installer.md +83 -0
- package/dist/template/docs/operations-guide.md +270 -0
- package/dist/template/docs/ota-emergency-recovery.md +109 -0
- package/dist/template/docs/supabase-setup.md +133 -0
- package/dist/template/eslint.config.mjs +30 -0
- package/dist/template/gitignore.template +58 -0
- package/dist/template/next.config.ts +7 -0
- package/dist/template/package-lock.json +12156 -0
- package/dist/template/package.json +50 -0
- package/dist/template/postcss.config.mjs +7 -0
- package/dist/template/public/file.svg +1 -0
- package/dist/template/public/globe.svg +1 -0
- package/dist/template/public/next.svg +1 -0
- package/dist/template/public/vercel.svg +1 -0
- package/dist/template/public/window.svg +1 -0
- package/dist/template/scripts/configure-expo-app.mjs +145 -0
- package/dist/template/scripts/create-access-token.mjs +135 -0
- package/dist/template/scripts/create-admin.mjs +169 -0
- package/dist/template/scripts/import-emergency-redirects.mjs +126 -0
- package/dist/template/scripts/lib/embedded-update-registrar.test.ts +64 -0
- package/dist/template/scripts/lib/expo-app-configurator.mjs +666 -0
- package/dist/template/scripts/lib/expo-app-configurator.test.ts +463 -0
- package/dist/template/scripts/lib/expo-app-prompts.mjs +139 -0
- package/dist/template/scripts/lib/expo-app-prompts.test.ts +97 -0
- package/dist/template/scripts/lib/expo-export-command.test.ts +31 -0
- package/dist/template/scripts/lib/ota-publish-retry.test.ts +33 -0
- package/dist/template/scripts/manage-emergency-redirect.mjs +483 -0
- package/dist/template/scripts/sync-docker-database-password.sh +16 -0
- package/dist/template/src/client/admin-api.ts +174 -0
- package/dist/template/src/client/admin-types.ts +93 -0
- package/dist/template/src/client/logout-button.tsx +31 -0
- package/dist/template/src/server/controllers/assets.ts +216 -0
- package/dist/template/src/server/controllers/manifest.test.ts +403 -0
- package/dist/template/src/server/controllers/manifest.ts +626 -0
- package/dist/template/src/server/controllers/update-complete.ts +36 -0
- package/dist/template/src/server/lib/admin-access-tokens.ts +169 -0
- package/dist/template/src/server/lib/admin-api.ts +101 -0
- package/dist/template/src/server/lib/admin-auth.ts +208 -0
- package/dist/template/src/server/lib/admin-embedded-updates.ts +150 -0
- package/dist/template/src/server/lib/admin-updates.ts +1282 -0
- package/dist/template/src/server/lib/common.js +24 -0
- package/dist/template/src/server/lib/emergency-channel-redirects.ts +310 -0
- package/dist/template/src/server/lib/env.js +8 -0
- package/dist/template/src/server/lib/manifest-helpers.js +91 -0
- package/dist/template/src/server/lib/response.js +11 -0
- package/dist/template/src/server/lib/signing.js +55 -0
- package/dist/template/src/server/lib/supabase.js +763 -0
- package/dist/template/src/server/manifest/manifest-repository.ts +269 -0
- package/dist/template/src/server/manifest/manifest-request.ts +21 -0
- package/dist/template/src/server/manifest/manifest-response.ts +235 -0
- package/dist/template/src/server/manifest/manifest-values.ts +62 -0
- package/dist/template/templates/expo-app/.env.ota.example +18 -0
- package/dist/template/templates/expo-app/ci_scripts/ci_post_xcodebuild.sh +6 -0
- package/dist/template/templates/expo-app/ci_scripts/register-embedded-update.sh +36 -0
- package/dist/template/templates/expo-app/plugins/with-ota-embedded-registration.js +33 -0
- package/dist/template/templates/expo-app/scripts/ota-publish/api/database-client.mjs +87 -0
- package/dist/template/templates/expo-app/scripts/ota-publish/api/storage-client.mjs +57 -0
- package/dist/template/templates/expo-app/scripts/ota-publish/index.mjs +182 -0
- package/dist/template/templates/expo-app/scripts/ota-publish/lib/common.mjs +84 -0
- package/dist/template/templates/expo-app/scripts/ota-publish/lib/expo-export-command.mjs +24 -0
- package/dist/template/templates/expo-app/scripts/ota-publish/lib/retry.mjs +25 -0
- package/dist/template/templates/expo-app/scripts/ota-publish/shared/config.mjs +48 -0
- package/dist/template/templates/expo-app/scripts/ota-register-embedded/android-register-embedded-update.sh +18 -0
- package/dist/template/templates/expo-app/scripts/ota-register-embedded/index.mjs +275 -0
- package/dist/template/tsconfig.json +36 -0
- package/dist/template/vitest.config.mts +20 -0
- package/dist/template-manifest.json +564 -0
- package/lib/cli.mjs +549 -0
- package/package.json +41 -0
|
@@ -0,0 +1,497 @@
|
|
|
1
|
+
# Expo Application Setup
|
|
2
|
+
|
|
3
|
+
This guide connects an Expo application to the self-hosted OTA server for
|
|
4
|
+
receiving and publishing updates.
|
|
5
|
+
|
|
6
|
+
## Automatic configuration
|
|
7
|
+
|
|
8
|
+
Applications using a static `app.json` can be configured from the OTA server
|
|
9
|
+
repository:
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
npm run configure-app
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
The interactive CLI asks for each required value and confirms the final plan
|
|
16
|
+
before changing the application.
|
|
17
|
+
|
|
18
|
+
For non-interactive CI usage:
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
npm run configure-app -- \
|
|
22
|
+
--app /full/path/to/expo-app \
|
|
23
|
+
--certificate /full/path/code-signing-certificate.pem \
|
|
24
|
+
--server-url https://updates.example.com \
|
|
25
|
+
--channel production \
|
|
26
|
+
--runtime-version 1.0.0
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
The command patches `app.json` and `package.json`, copies the public
|
|
30
|
+
certificate, installs `expo-updates`, adds the portable publisher and runs
|
|
31
|
+
`expo prebuild`. It supports npm, pnpm, Yarn and Bun lockfiles.
|
|
32
|
+
|
|
33
|
+
Options:
|
|
34
|
+
|
|
35
|
+
```text
|
|
36
|
+
--platform all|ios|android
|
|
37
|
+
--force
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
The CLI intentionally refuses dynamic `app.config.*` projects and refuses to
|
|
41
|
+
replace generated files unless `--force` is provided. The sections below
|
|
42
|
+
document the equivalent manual configuration.
|
|
43
|
+
|
|
44
|
+
## 1. Install Expo Updates
|
|
45
|
+
|
|
46
|
+
Install the Expo-compatible version of `expo-updates`:
|
|
47
|
+
|
|
48
|
+
```bash
|
|
49
|
+
npx expo install expo-updates
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
The application does not send an admin access token when checking for an
|
|
53
|
+
update. `/api/manifest` and `/api/assets` are public runtime endpoints. Admin
|
|
54
|
+
sessions and access tokens are only for operators, CI and administrative
|
|
55
|
+
automation.
|
|
56
|
+
|
|
57
|
+
## 2. Create the code-signing certificate
|
|
58
|
+
|
|
59
|
+
Create one RSA private key and a self-signed public certificate:
|
|
60
|
+
|
|
61
|
+
```bash
|
|
62
|
+
mkdir -p certificates
|
|
63
|
+
|
|
64
|
+
openssl req \
|
|
65
|
+
-x509 \
|
|
66
|
+
-newkey rsa:2048 \
|
|
67
|
+
-nodes \
|
|
68
|
+
-sha256 \
|
|
69
|
+
-days 3650 \
|
|
70
|
+
-subj "/CN=expo-updates" \
|
|
71
|
+
-addext "basicConstraints=critical,CA:FALSE" \
|
|
72
|
+
-addext "keyUsage=critical,digitalSignature" \
|
|
73
|
+
-addext "extendedKeyUsage=codeSigning" \
|
|
74
|
+
-keyout certificates/code-signing-private-key.pem \
|
|
75
|
+
-out certificates/code-signing-certificate.pem
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
The two files have different owners and deployment rules:
|
|
79
|
+
|
|
80
|
+
| File | Location | May be committed |
|
|
81
|
+
|---|---|---|
|
|
82
|
+
| `code-signing-certificate.pem` | Expo application | Yes, it is public |
|
|
83
|
+
| `code-signing-private-key.pem` | OTA server only | No |
|
|
84
|
+
|
|
85
|
+
For Docker Compose, copy only the private key to the server repository:
|
|
86
|
+
|
|
87
|
+
```bash
|
|
88
|
+
mkdir -p secrets
|
|
89
|
+
cp /secure/path/code-signing-private-key.pem \
|
|
90
|
+
secrets/code-signing-private-key.pem
|
|
91
|
+
chmod 600 secrets/code-signing-private-key.pem
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
The Compose stack mounts `./secrets` read-only and reads the key from
|
|
95
|
+
`/run/secrets/ota/code-signing-private-key.pem`.
|
|
96
|
+
|
|
97
|
+
For a non-container deployment, configure either:
|
|
98
|
+
|
|
99
|
+
```env
|
|
100
|
+
CODE_SIGNING_PRIVATE_KEY_PATH=/run/secrets/code-signing-private-key.pem
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
or an inline PEM:
|
|
104
|
+
|
|
105
|
+
```env
|
|
106
|
+
CODE_SIGNING_PRIVATE_KEY="-----BEGIN PRIVATE KEY-----\n...\n-----END PRIVATE KEY-----"
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
Never rotate the server private key without shipping a new binary containing
|
|
110
|
+
the matching public certificate. Existing binaries reject manifests signed by
|
|
111
|
+
an unknown key.
|
|
112
|
+
|
|
113
|
+
## 3. Configure the Expo application
|
|
114
|
+
|
|
115
|
+
Use a dynamic Expo config so the channel cannot accidentally remain
|
|
116
|
+
`development` in a production binary.
|
|
117
|
+
|
|
118
|
+
Example `app.config.ts`:
|
|
119
|
+
|
|
120
|
+
```ts
|
|
121
|
+
import type { ConfigContext, ExpoConfig } from "expo/config";
|
|
122
|
+
|
|
123
|
+
const CHANNELS = ["development", "preview", "production"] as const;
|
|
124
|
+
type UpdateChannel = (typeof CHANNELS)[number];
|
|
125
|
+
|
|
126
|
+
function getUpdateChannel(): UpdateChannel {
|
|
127
|
+
const value = process.env.EXPO_UPDATE_CHANNEL?.trim().toLowerCase();
|
|
128
|
+
|
|
129
|
+
if (!CHANNELS.includes(value as UpdateChannel)) {
|
|
130
|
+
throw new Error(
|
|
131
|
+
`EXPO_UPDATE_CHANNEL must be one of: ${CHANNELS.join(", ")}`,
|
|
132
|
+
);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
return value as UpdateChannel;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
export default ({ config }: ConfigContext): ExpoConfig => {
|
|
139
|
+
const channel = getUpdateChannel();
|
|
140
|
+
const runtimeVersion = process.env.EXPO_RUNTIME_VERSION?.trim();
|
|
141
|
+
const otaServerUrl = process.env.EXPO_OTA_SERVER_URL?.trim();
|
|
142
|
+
|
|
143
|
+
if (!runtimeVersion) {
|
|
144
|
+
throw new Error("EXPO_RUNTIME_VERSION is required");
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
if (!otaServerUrl) {
|
|
148
|
+
throw new Error("EXPO_OTA_SERVER_URL is required");
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
return {
|
|
152
|
+
...config,
|
|
153
|
+
name: config.name ?? "My App",
|
|
154
|
+
slug: config.slug ?? "my-app",
|
|
155
|
+
runtimeVersion,
|
|
156
|
+
updates: {
|
|
157
|
+
enabled: true,
|
|
158
|
+
url: `${otaServerUrl.replace(/\/$/, "")}/api/manifest`,
|
|
159
|
+
checkAutomatically: "NEVER",
|
|
160
|
+
fallbackToCacheTimeout: 0,
|
|
161
|
+
codeSigningCertificate:
|
|
162
|
+
"./certificates/code-signing-certificate.pem",
|
|
163
|
+
codeSigningMetadata: {
|
|
164
|
+
alg: "rsa-v1_5-sha256",
|
|
165
|
+
keyid: "main",
|
|
166
|
+
},
|
|
167
|
+
requestHeaders: {
|
|
168
|
+
"expo-channel-name": channel,
|
|
169
|
+
},
|
|
170
|
+
},
|
|
171
|
+
extra: {
|
|
172
|
+
...config.extra,
|
|
173
|
+
updateChannel: channel,
|
|
174
|
+
},
|
|
175
|
+
};
|
|
176
|
+
};
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
The server currently signs with `keyid="main"`, so the application's
|
|
180
|
+
`codeSigningMetadata.keyid` must also be `main`.
|
|
181
|
+
|
|
182
|
+
### How updates are isolated
|
|
183
|
+
|
|
184
|
+
Each native binary requests an update using three selection keys:
|
|
185
|
+
|
|
186
|
+
```text
|
|
187
|
+
runtimeVersion + channel + platform
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
The server looks up only the latest active update inside that exact scope.
|
|
191
|
+
Updates do not cross runtime versions, channels, or platforms.
|
|
192
|
+
|
|
193
|
+
```mermaid
|
|
194
|
+
flowchart TD
|
|
195
|
+
Client[Native binary] --> Headers["runtimeVersion=1.1<br/>channel=production<br/>platform=ios"]
|
|
196
|
+
Headers --> Match["Exact scope:<br/>1.1 / production / ios"]
|
|
197
|
+
Match --> Active[Latest active update]
|
|
198
|
+
|
|
199
|
+
Runtime10["1.0 / production / ios"] -. different runtime .-> Rejected[Not eligible]
|
|
200
|
+
Development["1.1 / development / ios"] -. different channel .-> Rejected
|
|
201
|
+
Android["1.1 / production / android"] -. different platform .-> Rejected
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
Example release history:
|
|
205
|
+
|
|
206
|
+
| Event | Result |
|
|
207
|
+
|---|---|
|
|
208
|
+
| App `1.0.0` is built with runtime `1.0` and channel `production` | It receives only active `1.0 / production` updates for its platform |
|
|
209
|
+
| App `1.1.0` is built with runtime `1.1` and channel `production` | It cannot receive an update published for runtime `1.0` |
|
|
210
|
+
| A runtime `1.1` update is published to `development` | Production builds do not receive it |
|
|
211
|
+
| The same update is approved and published to `production` | Runtime `1.1` production builds become eligible |
|
|
212
|
+
|
|
213
|
+
Introducing runtime `1.1` does not delete or globally disable runtime `1.0`.
|
|
214
|
+
Older binaries still report runtime `1.0` and may continue receiving its
|
|
215
|
+
active updates. If support for those binaries must end, deactivate the
|
|
216
|
+
corresponding runtime `1.0` updates explicitly.
|
|
217
|
+
|
|
218
|
+
Do not confuse the store-facing application version with Expo
|
|
219
|
+
`runtimeVersion`. The server uses `runtimeVersion` for compatibility. A
|
|
220
|
+
runtime change requires a new native binary because an OTA update cannot
|
|
221
|
+
change its own runtime, channel, or signing certificate.
|
|
222
|
+
|
|
223
|
+
### Local device testing through HTTPS
|
|
224
|
+
|
|
225
|
+
A physical device cannot reach the computer through `localhost`. Do not use a
|
|
226
|
+
plain HTTP LAN address for OTA testing. Prefer temporary HTTPS port forwarding
|
|
227
|
+
such as
|
|
228
|
+
[Microsoft Dev Tunnels](https://learn.microsoft.com/en-us/azure/developer/dev-tunnels/get-started).
|
|
229
|
+
|
|
230
|
+
For a Docker installation, forward only the application port:
|
|
231
|
+
|
|
232
|
+
```bash
|
|
233
|
+
devtunnel user login -g
|
|
234
|
+
devtunnel host -p 3000 --allow-anonymous
|
|
235
|
+
```
|
|
236
|
+
|
|
237
|
+
Set the generated `https://...devtunnels.ms` URL as both
|
|
238
|
+
`OTA_PUBLIC_BASE_URL` on the server and `EXPO_OTA_SERVER_URL` in the
|
|
239
|
+
application. Recreate the server container after changing `.env`:
|
|
240
|
+
|
|
241
|
+
```bash
|
|
242
|
+
docker compose up -d --force-recreate app
|
|
243
|
+
```
|
|
244
|
+
|
|
245
|
+
Keep database and storage connections local. In particular, retain
|
|
246
|
+
`R2_ENDPOINT=http://127.0.0.1:9000` for the local publisher instead of routing
|
|
247
|
+
signed S3 requests through the tunnel.
|
|
248
|
+
|
|
249
|
+
Anonymous tunnel access is necessary when the mobile application cannot
|
|
250
|
+
complete the Dev Tunnels login flow. It also exposes the forwarded application
|
|
251
|
+
port publicly, so use a temporary tunnel, strong admin credentials, and stop
|
|
252
|
+
it after testing.
|
|
253
|
+
|
|
254
|
+
Example EAS profiles:
|
|
255
|
+
|
|
256
|
+
```json
|
|
257
|
+
{
|
|
258
|
+
"build": {
|
|
259
|
+
"development": {
|
|
260
|
+
"developmentClient": true,
|
|
261
|
+
"distribution": "internal",
|
|
262
|
+
"env": {
|
|
263
|
+
"EXPO_UPDATE_CHANNEL": "development",
|
|
264
|
+
"EXPO_RUNTIME_VERSION": "1.0.0",
|
|
265
|
+
"EXPO_OTA_SERVER_URL": "https://updates.example.com"
|
|
266
|
+
}
|
|
267
|
+
},
|
|
268
|
+
"preview": {
|
|
269
|
+
"distribution": "internal",
|
|
270
|
+
"env": {
|
|
271
|
+
"EXPO_UPDATE_CHANNEL": "preview",
|
|
272
|
+
"EXPO_RUNTIME_VERSION": "1.0.0",
|
|
273
|
+
"EXPO_OTA_SERVER_URL": "https://updates.example.com"
|
|
274
|
+
}
|
|
275
|
+
},
|
|
276
|
+
"production": {
|
|
277
|
+
"env": {
|
|
278
|
+
"EXPO_UPDATE_CHANNEL": "production",
|
|
279
|
+
"EXPO_RUNTIME_VERSION": "1.0.0",
|
|
280
|
+
"EXPO_OTA_SERVER_URL": "https://updates.example.com"
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
```
|
|
286
|
+
|
|
287
|
+
`runtimeVersion` and channel are native configuration. They cannot be changed
|
|
288
|
+
by an OTA update. A native rebuild is required whenever either value or the
|
|
289
|
+
certificate changes.
|
|
290
|
+
|
|
291
|
+
## 4. Generate and verify native configuration
|
|
292
|
+
|
|
293
|
+
Generate native projects or synchronize existing ones:
|
|
294
|
+
|
|
295
|
+
```bash
|
|
296
|
+
EXPO_UPDATE_CHANNEL=production \
|
|
297
|
+
EXPO_RUNTIME_VERSION=1.0.0 \
|
|
298
|
+
EXPO_OTA_SERVER_URL=https://updates.example.com \
|
|
299
|
+
npx expo prebuild
|
|
300
|
+
```
|
|
301
|
+
|
|
302
|
+
Verify the resolved Expo config before building:
|
|
303
|
+
|
|
304
|
+
```bash
|
|
305
|
+
EXPO_UPDATE_CHANNEL=production \
|
|
306
|
+
EXPO_RUNTIME_VERSION=1.0.0 \
|
|
307
|
+
EXPO_OTA_SERVER_URL=https://updates.example.com \
|
|
308
|
+
npx expo config --type public
|
|
309
|
+
```
|
|
310
|
+
|
|
311
|
+
For projects that commit `ios/` and `android/`, also inspect the generated
|
|
312
|
+
native values:
|
|
313
|
+
|
|
314
|
+
- iOS `Expo.plist`:
|
|
315
|
+
- `EXUpdatesURL`;
|
|
316
|
+
- `EXUpdatesRuntimeVersion`;
|
|
317
|
+
- `EXUpdatesRequestHeaders`;
|
|
318
|
+
- `EXUpdatesCodeSigningCertificate`.
|
|
319
|
+
- Android manifest/resources:
|
|
320
|
+
- `expo.modules.updates.EXPO_UPDATE_URL`;
|
|
321
|
+
- `expo.modules.updates.EXPO_RUNTIME_VERSION`;
|
|
322
|
+
- `expo.modules.updates.UPDATES_CONFIGURATION_REQUEST_HEADERS_KEY`;
|
|
323
|
+
- `expo.modules.updates.CODE_SIGNING_CERTIFICATE`.
|
|
324
|
+
|
|
325
|
+
Do not rely only on `eas.json`. The final native binary must contain the
|
|
326
|
+
expected URL, runtime, channel and certificate.
|
|
327
|
+
|
|
328
|
+
## 5. Check and install updates in the application
|
|
329
|
+
|
|
330
|
+
With `checkAutomatically: "NEVER"`, the application controls the user
|
|
331
|
+
experience:
|
|
332
|
+
|
|
333
|
+
```ts
|
|
334
|
+
import * as Updates from "expo-updates";
|
|
335
|
+
|
|
336
|
+
export async function checkForOtaUpdate() {
|
|
337
|
+
if (__DEV__) {
|
|
338
|
+
return { available: false };
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
const result = await Updates.checkForUpdateAsync();
|
|
342
|
+
return { available: result.isAvailable };
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
export async function installOtaUpdate() {
|
|
346
|
+
const result = await Updates.fetchUpdateAsync();
|
|
347
|
+
|
|
348
|
+
if (!result.isNew) {
|
|
349
|
+
return;
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
await Updates.reloadAsync();
|
|
353
|
+
}
|
|
354
|
+
```
|
|
355
|
+
|
|
356
|
+
Expo Updates automatically sends the runtime headers used by the server,
|
|
357
|
+
including:
|
|
358
|
+
|
|
359
|
+
- `expo-platform`;
|
|
360
|
+
- `expo-runtime-version`;
|
|
361
|
+
- `expo-current-update-id`;
|
|
362
|
+
- `expo-embedded-update-id`;
|
|
363
|
+
- the configured `expo-channel-name`.
|
|
364
|
+
|
|
365
|
+
These headers allow normal selection, rollback protection and exact emergency
|
|
366
|
+
redirect matching without custom device authentication.
|
|
367
|
+
|
|
368
|
+
## 6. Register embedded updates
|
|
369
|
+
|
|
370
|
+
Emergency redirects and downgrade protection work best when every released
|
|
371
|
+
native binary registers its embedded update:
|
|
372
|
+
|
|
373
|
+
```text
|
|
374
|
+
embedded_update_id
|
|
375
|
+
created_at
|
|
376
|
+
channel
|
|
377
|
+
platform
|
|
378
|
+
is_embedded=true
|
|
379
|
+
```
|
|
380
|
+
|
|
381
|
+
Register the value after each iOS and Android release build in
|
|
382
|
+
`ota_embedded_updates`. The embedded ID and creation time must come from the
|
|
383
|
+
generated Expo embedded manifest, not from a random value created before the
|
|
384
|
+
build.
|
|
385
|
+
|
|
386
|
+
The MIEX application contains a reference implementation:
|
|
387
|
+
|
|
388
|
+
```text
|
|
389
|
+
scripts/build-update/register-embedded-update.mjs
|
|
390
|
+
android/ci_scripts/register_embedded_update_android.sh
|
|
391
|
+
```
|
|
392
|
+
|
|
393
|
+
Registration should be a required CI step for production builds. If it fails,
|
|
394
|
+
the binary should not be distributed.
|
|
395
|
+
|
|
396
|
+
## 7. Publish an OTA update
|
|
397
|
+
|
|
398
|
+
This repository currently serves and manages updates; it does not yet expose
|
|
399
|
+
an HTTP upload endpoint. The publisher therefore runs from the Expo
|
|
400
|
+
application repository and needs PostgreSQL plus S3-compatible storage
|
|
401
|
+
credentials.
|
|
402
|
+
|
|
403
|
+
A publisher performs these steps:
|
|
404
|
+
|
|
405
|
+
1. Resolve the exact channel and runtime used by the target native binary.
|
|
406
|
+
2. Run `npx expo export --platform ios` and/or `--platform android`.
|
|
407
|
+
3. Read Expo `metadata.json`.
|
|
408
|
+
4. Calculate hashes and content types for the launch asset and all assets.
|
|
409
|
+
5. Upload immutable files to the configured bucket.
|
|
410
|
+
6. Insert the update into `ota_updates`.
|
|
411
|
+
7. Update `ota_update_channels.latest_update_id`.
|
|
412
|
+
8. Leave the update inactive when manual activation is required.
|
|
413
|
+
9. Activate or roll back from the admin panel after validation.
|
|
414
|
+
|
|
415
|
+
The MIEX application already implements this workflow under:
|
|
416
|
+
|
|
417
|
+
```text
|
|
418
|
+
scripts/build-update/
|
|
419
|
+
```
|
|
420
|
+
|
|
421
|
+
Its relevant environment is:
|
|
422
|
+
|
|
423
|
+
```env
|
|
424
|
+
EXPO_UPDATE_CHANNEL=production
|
|
425
|
+
OTA_DATABASE_URL=postgresql://...
|
|
426
|
+
OTA_DATABASE_SSL=true
|
|
427
|
+
OTA_SYNC_UPDATES_DB=true
|
|
428
|
+
|
|
429
|
+
R2_ENDPOINT=https://...
|
|
430
|
+
R2_ACCESS_KEY_ID=...
|
|
431
|
+
R2_SECRET_ACCESS_KEY=...
|
|
432
|
+
R2_BUCKET=expo-updates
|
|
433
|
+
```
|
|
434
|
+
|
|
435
|
+
Example publish command in that application:
|
|
436
|
+
|
|
437
|
+
```bash
|
|
438
|
+
npm run local-update:production -- -m "Fix checkout validation"
|
|
439
|
+
```
|
|
440
|
+
|
|
441
|
+
The application's configured channel, exported runtime, uploaded storage path
|
|
442
|
+
and database records must all use the same values. Publishing JavaScript for a
|
|
443
|
+
different `runtimeVersion` is safe but the binary will not select it.
|
|
444
|
+
|
|
445
|
+
Direct database and storage credentials are acceptable for a trusted local
|
|
446
|
+
publisher. Do not distribute them in the mobile binary. Embedded build
|
|
447
|
+
registration can use the authenticated endpoint:
|
|
448
|
+
|
|
449
|
+
```text
|
|
450
|
+
POST /api/admin/embedded-updates
|
|
451
|
+
Authorization: Bearer ota_...
|
|
452
|
+
```
|
|
453
|
+
|
|
454
|
+
Create a dedicated access token with `npm run create-access-token` (or
|
|
455
|
+
`docker compose exec app npm run create-access-token`) and keep only
|
|
456
|
+
`updates:write`. Set `OTA_SERVER_URL` and `OTA_ACCESS_TOKEN` as CI secrets.
|
|
457
|
+
|
|
458
|
+
The app configurator installs:
|
|
459
|
+
|
|
460
|
+
- Android APK/AAB build commands that register `app.manifest` after Gradle;
|
|
461
|
+
- an iOS Xcode Build Phase for local Release/Archive builds;
|
|
462
|
+
- `ci_scripts/ci_post_xcodebuild.sh` for Xcode Cloud.
|
|
463
|
+
|
|
464
|
+
Registered binaries are visible at `/updates/embedded`.
|
|
465
|
+
|
|
466
|
+
## 8. End-to-end verification
|
|
467
|
+
|
|
468
|
+
Check server readiness:
|
|
469
|
+
|
|
470
|
+
```bash
|
|
471
|
+
curl -fsS https://updates.example.com/api/health
|
|
472
|
+
```
|
|
473
|
+
|
|
474
|
+
Check a signed manifest response:
|
|
475
|
+
|
|
476
|
+
```bash
|
|
477
|
+
curl -i \
|
|
478
|
+
-H "expo-protocol-version: 1" \
|
|
479
|
+
-H "expo-platform: ios" \
|
|
480
|
+
-H "expo-runtime-version: 1.0.0" \
|
|
481
|
+
-H "expo-channel-name: production" \
|
|
482
|
+
-H 'expo-expect-signature: sig, keyid="main"' \
|
|
483
|
+
https://updates.example.com/api/manifest
|
|
484
|
+
```
|
|
485
|
+
|
|
486
|
+
The response must be `200`, use `multipart/mixed`, and include an
|
|
487
|
+
`expo-signature` part for the manifest or directive.
|
|
488
|
+
|
|
489
|
+
Final device test:
|
|
490
|
+
|
|
491
|
+
1. Install a release binary, not Expo Go.
|
|
492
|
+
2. Confirm its runtime and native channel in application diagnostics.
|
|
493
|
+
3. Publish an OTA for the same platform/runtime/channel.
|
|
494
|
+
4. Activate it in `/updates`.
|
|
495
|
+
5. Run the application's update check.
|
|
496
|
+
6. Download, reload and confirm the new update ID.
|
|
497
|
+
7. Test rollback and an exact emergency redirect before production launch.
|