@runeditrun/rer 0.2.43 → 0.2.45
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/README.md +7 -1
- package/cli/README.md +11 -1
- package/cli/business/command.mjs +1 -1
- package/cli/business/keychain.mjs +1 -1
- package/cli/business/lease.mjs +1 -1
- package/cli/business/questions.mjs +2 -2
- package/cli/contract.mjs +1 -1
- package/cli/deploy-readiness.mjs +2 -2
- package/cli/deploy.mjs +18 -5
- package/cli/local.mjs +6 -2
- package/cli/parse.mjs +9 -3
- package/cli/port.mjs +10 -11
- package/cli/server-limit-file.mjs +21 -0
- package/cli/server-registry.mjs +13 -6
- package/cli/server-resources.mjs +13 -2
- package/global/CHANGELOG.md +17 -0
- package/global/README.md +7 -1
- package/global/launch/capacity.mjs +9 -4
- package/global/launch/facts.mjs +11 -19
- package/modules/demo-host/README.md +3 -0
- package/modules/demo-host/build.mjs +3 -1
- package/modules/demo-host/native/config.mjs +2 -0
- package/modules/demo-host/native/prepare.mjs +3 -1
- package/modules/demo-host/native/warm.mjs +49 -0
- package/modules/demo-host/native/worker.mjs +4 -2
- package/modules/demo-host/pages.mjs +6 -1
- package/modules/dependencies/README.md +5 -2
- package/modules/dependencies/index.mjs +4 -3
- package/modules/dependencies/protocol.mjs +7 -5
- package/modules/deploy-kit/README.md +16 -1
- package/modules/deploy-kit/deploy.mjs +5 -3
- package/modules/deploy-kit/diagnostics.mjs +8 -0
- package/modules/deploy-kit/migration-ledger.mjs +28 -8
- package/modules/deploy-kit/migration-retry.mjs +32 -16
- package/modules/deploy-kit/migrations.mjs +10 -4
- package/modules/deploy-kit/owner-cli.mjs +9 -6
- package/modules/deploy-kit/owner-secret-copy.mjs +38 -0
- package/modules/deploy-kit/owner-secret-names.mjs +1 -1
- package/modules/deploy-kit/owner-secret.mjs +39 -18
- package/modules/deploy-kit/owner.mjs +25 -15
- package/modules/deploy-kit/provider.mjs +20 -3
- package/modules/operator-auth/identity/oidc/config.mjs +10 -8
- package/modules/operator-auth/signin/index.mjs +3 -3
- package/modules/release/catalogue.mjs +1 -1
- package/onboarding/port-probe.mjs +23 -1
- package/onboarding/process-diagnostics.mjs +3 -2
- package/onboarding/schema/setup-validation.mjs +1 -1
- package/onboarding/theme.mjs +1 -1
- package/onboarding/ui/app.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -181,11 +181,17 @@ naming their PIDs.
|
|
|
181
181
|
|
|
182
182
|
Servers started through `rer` (`rer dev`, `rer preview`) get a 10-server limit and a 12-hour idle timeout
|
|
183
183
|
unless you set `RER_SERVER_LIMIT`, `RER_SERVER_IDLE_SECONDS` or `--idle-timeout`.
|
|
184
|
+
`RER_SERVER_LIMIT_FILE=PATH` names a file holding the limit as a positive integer,
|
|
185
|
+
read at every start; it overrides `RER_SERVER_LIMIT` and the limits running servers
|
|
186
|
+
recorded, so a fleet's one current value cannot be capped by an older run's
|
|
187
|
+
environment. An unreadable or non-integer file refuses the start, naming the file.
|
|
184
188
|
`rer` supplies them only to checkouts whose pinned copy applies lower defaults
|
|
185
189
|
or does not report its own (`rer describe` reports `defaults`), so a current
|
|
186
190
|
checkout never records a limit you did not set.
|
|
187
191
|
A start is never refused for machine load alone unless `RER_SERVERS_LOAD_THRESHOLD`
|
|
188
|
-
or `RER_JOBS_LOAD_THRESHOLD` is set; memory and disk guards stay.
|
|
192
|
+
or `RER_JOBS_LOAD_THRESHOLD` is set; memory and disk guards stay. The disk guard
|
|
193
|
+
needs 15 GiB free; `RER_SERVERS_DISK_FLOOR_GIB=N` changes it (CI runners may set
|
|
194
|
+
it lower, for example 4; people should not).
|
|
189
195
|
|
|
190
196
|
## The front door
|
|
191
197
|
|
package/cli/README.md
CHANGED
|
@@ -182,6 +182,13 @@ idle timeout, and they stop with `dev` (explicit stop, idle timeout, Ctrl-C or
|
|
|
182
182
|
an application exit). `preview` does not run schedules. A seed that does not
|
|
183
183
|
want this declares one adapter option: `commandAdapter(lifecycle, { scheduled: false, ... })`.
|
|
184
184
|
|
|
185
|
+
Without `--host`, `setup`, `dev` and `preview` on a fresh checkout bind
|
|
186
|
+
`127.0.0.1`; a seed declares another loopback host with the adapter option
|
|
187
|
+
`commandAdapter(lifecycle, { host: 'localhost', ... })` (one of `127.0.0.1`,
|
|
188
|
+
`localhost`, `::1`). Auth needs `localhost` because WebAuthn refuses an IP
|
|
189
|
+
address as its relying-party ID. A saved origin keeps its own host, and the
|
|
190
|
+
front door and `--host` take precedence.
|
|
191
|
+
|
|
185
192
|
### Local and production sign-in
|
|
186
193
|
|
|
187
194
|
`setup` claims the local owner and stops its temporary runtime. `dev` prints
|
|
@@ -217,6 +224,7 @@ expiry clean up owned descendants before releasing state and capacity.
|
|
|
217
224
|
The private registry defaults to the OS user's `~/.rer/servers` independently
|
|
218
225
|
of checkout and Codex home; `RER_SERVERS_DIR` selects an isolated directory.
|
|
219
226
|
The combined dev/preview cap is 10 (`RER_SERVER_LIMIT`, positive integer). A start that sets `RER_SERVER_LIMIT` is capped by that value, higher or lower, whatever running servers recorded; a start that sets nothing is capped by the lowest limit a running server's person set explicitly, and a limit recorded by a server that did not set it never lowers the cap.
|
|
227
|
+
`RER_SERVER_LIMIT_FILE` names a file holding one positive integer, read afresh at every start: that value is the limit for the start and overrides this process's `RER_SERVER_LIMIT` and every running server's recorded limit (servers started under the file still count). A fleet uses it so one current value, edited in the file, controls every run, including long-lived ones that still export an older `RER_SERVER_LIMIT`. A file that cannot be read or holds anything but a positive integer refuses the start, naming the file; the limit refusal names the file when it set the cap.
|
|
220
228
|
Starting reservations count. At the cap a start is refused with a plain message
|
|
221
229
|
naming each running server, its checkout and its stop command; rer never stops
|
|
222
230
|
another checkout's server to make room, in any mode. A run that declares itself
|
|
@@ -332,7 +340,9 @@ upload.
|
|
|
332
340
|
child build environment and are redacted; the caller environment is restored
|
|
333
341
|
on success and failure. `--remove`, `--set-secret` and `--unset-secret` always go
|
|
334
342
|
through the owner-account controller, without invoking the application's build
|
|
335
|
-
or deploy hook.
|
|
343
|
+
or deploy hook. `--set-secret A,B` (or the flag repeated) changes several
|
|
344
|
+
secrets in one Worker version or none, after checking that each is declared
|
|
345
|
+
and, when set, has its value. Failure reports distinguish deployment, owner claim and token
|
|
336
346
|
retirement and preserve the environment, checkout and env-file in recovery
|
|
337
347
|
commands. Retirement can be finished with `rer deploy --unset-secret SETUP_TOKEN`
|
|
338
348
|
plus the same `--environment`, `--env-file` and `--cwd` arguments.
|
package/cli/business/command.mjs
CHANGED
|
@@ -11,7 +11,7 @@ const usage = `Usage: rer business VERB
|
|
|
11
11
|
run [--once] Run consented local discovery; vendor upload integration pending
|
|
12
12
|
next Return one templated question or nothing yet within 60 seconds
|
|
13
13
|
answer ID VENDOR USAGE [CONFIDENCE]
|
|
14
|
-
|
|
14
|
+
Catalog vendor or none; uses, sells, both, product-dependency
|
|
15
15
|
vendor-key add|remove VENDOR Keep a vendor key in OS credential storage
|
|
16
16
|
token MCP headersHelper output; send directly to the MCP client
|
|
17
17
|
status [--json] Pairing, service, current task and checkpoint
|
|
@@ -94,7 +94,7 @@ export async function readSecret({ input = process.stdin, output = process.stder
|
|
|
94
94
|
input.setRawMode(Boolean(wasRaw)); if (!wasFlowing) input.pause(); output.write('\n');
|
|
95
95
|
if (error) reject(error); else { try { resolve(checkedSecret(secret)); } catch (e) { reject(e); } }
|
|
96
96
|
}
|
|
97
|
-
const interrupted = () => finish(new Error('Credential entry
|
|
97
|
+
const interrupted = () => finish(new Error('Credential entry canceled.'));
|
|
98
98
|
const terminated = () => finish(new Error('Credential entry interrupted.'));
|
|
99
99
|
const ended = () => finish(new Error('Credential input ended before confirmation.'));
|
|
100
100
|
function data(chunk) {
|
package/cli/business/lease.mjs
CHANGED
|
@@ -43,7 +43,7 @@ export class Lease {
|
|
|
43
43
|
this.expires = expires;
|
|
44
44
|
this.cursor = Number.isSafeInteger(result.cursor) ? result.cursor : this.cursor;
|
|
45
45
|
if (result.cancel_requested || result.controls?.some(control => control.kind === 'cancel' || control.instruction === 'pause')) {
|
|
46
|
-
this.controller.abort(Error('Business task was paused or
|
|
46
|
+
this.controller.abort(Error('Business task was paused or canceled in the browser.'));
|
|
47
47
|
this.signal.throwIfAborted();
|
|
48
48
|
}
|
|
49
49
|
// Controls contain only closed enums. A requested checkpoint is already
|
|
@@ -66,7 +66,7 @@ export async function next() {
|
|
|
66
66
|
export async function answer(id, vendorId, choice, rawConfidence = '1') {
|
|
67
67
|
identifier(id);
|
|
68
68
|
// Reject free text before even looking up the question or minting a bearer.
|
|
69
|
-
if (typeof vendorId !== 'string' || !/^[a-z][a-z0-9-]{0,79}$/.test(vendorId) || sensitive(vendorId)) throw Error('Choose a
|
|
69
|
+
if (typeof vendorId !== 'string' || !/^[a-z][a-z0-9-]{0,79}$/.test(vendorId) || sensitive(vendorId)) throw Error('Choose a catalog vendor id from rer business next, or none.');
|
|
70
70
|
if (!classifications.includes(choice)) throw Error(`Choose an enum: ${classifications.join(', ')}.`);
|
|
71
71
|
if (!/^(?:0(?:\.\d+)?|1(?:\.0+)?)$/.test(rawConfidence)) throw Error('Choose a numeric confidence between 0 and 1.');
|
|
72
72
|
const confidence = Number(rawConfidence);
|
|
@@ -75,7 +75,7 @@ export async function answer(id, vendorId, choice, rawConfidence = '1') {
|
|
|
75
75
|
if (summary.runner === 'owner' || ownerKinds.has(summary.kind)) throw Error(`This item requires the owner in the browser: ${ownerLink(state)}`);
|
|
76
76
|
if (summary.kind !== 'classify.row' || summary.runner !== 'executor') throw Error('This item does not accept a CLI classification answer.');
|
|
77
77
|
const { vendors } = classification(summary);
|
|
78
|
-
if (!vendors.includes(vendorId)) throw Error('Choose a
|
|
78
|
+
if (!vendors.includes(vendorId)) throw Error('Choose a catalog vendor id from this question, or none.');
|
|
79
79
|
const tool = await mcpClient(api, { taskId: id, signal });
|
|
80
80
|
let lease = summary;
|
|
81
81
|
if (summary.state === 'ready') lease = await tool('answer', { task_id: id, action: 'claim', client_event_id: randomUUID(), fence: summary.fence });
|
package/cli/contract.mjs
CHANGED
|
@@ -11,7 +11,7 @@ const definitions = {
|
|
|
11
11
|
build: [['--site'], 'Production build with private local settings excluded and restored. --site instead writes the static run site (homepage, /run, docs) to its declared folder and prints that folder.'],
|
|
12
12
|
verify: [[], 'Run the complete internal verification target.'],
|
|
13
13
|
reset: [['--yes'], 'Confirmed removal of the declared local inventory only.'],
|
|
14
|
-
deploy: [['--environment', '--dry-run', '--site', '--demo', '--host', '--env-file', '--image', '--bind-address', '--http-port', '--https-port', '--remove', '--yes', '--set-secret', '--unset-secret', '--rotate-secret'], 'Owner-account deployment and health; dry run performs local validation/build only. Builds and deploy hooks run with the checkout\'s local settings files moved aside, and a build output holding one (.dev.vars, .env) is refused. Declared secrets come from the environment or --env-file (an owned 0600 KEY=VALUE file); a new Worker gets the local setup owner and fresh generated secrets when they are not given. rer keeps the secrets it generates in .rer/deploy/ENVIRONMENT.secrets.env (0600) and reuses them on every redeploy; it refuses to generate a replacement for one a live Worker holds, and --rotate-secret NAME[,NAME] replaces them on purpose. After a healthy deploy rer claims the setup owner on the hosted app with the one-time setup token, then removes the token. --set-secret NAME (value from the environment or --env-file) and --unset-secret NAME change
|
|
14
|
+
deploy: [['--environment', '--dry-run', '--site', '--demo', '--host', '--env-file', '--image', '--bind-address', '--http-port', '--https-port', '--remove', '--yes', '--set-secret', '--unset-secret', '--rotate-secret'], 'Owner-account deployment and health; dry run performs local validation/build only. Builds and deploy hooks run with the checkout\'s local settings files moved aside, and a build output holding one (.dev.vars, .env) is refused. Declared secrets come from the environment or --env-file (an owned 0600 KEY=VALUE file); a new Worker gets the local setup owner and fresh generated secrets when they are not given. rer keeps the secrets it generates in .rer/deploy/ENVIRONMENT.secrets.env (0600) and reuses them on every redeploy; it refuses to generate a replacement for one a live Worker holds, and --rotate-secret NAME[,NAME] replaces them on purpose. After a healthy deploy rer claims the setup owner on the hosted app with the one-time setup token, then removes the token. --set-secret NAME[,NAME] (each value from the environment or --env-file; repeat the flag or join names with commas) and --unset-secret NAME[,NAME] change those secrets of the deployed Worker without a build, all of them in one new Worker version or none, and record that version; a missing value refuses before any change. --remove --yes deletes what this environment\'s deploy record says rer created (Worker, D1, R2, KV, queues), reads back that each is gone, and touches nothing else. --site deploys the run site instead: an assets-only Worker on its custom domain with www redirected; with --dry-run it builds the site and prints the plan with no provider request. --demo deploys the hosted demo instead (deploy-demo.json): a front Worker on demo.<domain> giving each visitor their own signed-in, throwaway native Worker isolate of this seed with real public reads/checks and simulated external writes; --dry-run writes it to .rer/demo-host with no provider request; --demo --remove --yes deletes that demo (its Worker, demo.<domain> Custom Domain, each only while the record its deploy left proves it the demo\'s), reads back that each is gone, and is a no-op once it is.'],
|
|
15
15
|
export: [['--target', '--output', '--origin', '--session-file'], 'Complete supported archive of the local copy on this computer, with integrity and exclusions, written to --output. The hosted install cannot be exported yet: --origin or --target remote refuses (exit 2) before any effect and names the command that saves the hosted database.'],
|
|
16
16
|
import: [['--target', '--input', '--journal', '--origin', '--session-file', '--yes', '--legacy-v1', '--acknowledge-unverified-metadata', '--output'], 'Confirmed atomic restore into an empty destination; --journal LATER_ARCHIVE also fences rows that installation erased since. Backup-only local v1 recovery requires --legacy-v1 --acknowledge-unverified-metadata and a new --output v2 archive; --journal requires normal v2 import.'],
|
|
17
17
|
doctor: [[], 'Read-only installed tool, configuration and state diagnostics.'],
|
package/cli/deploy-readiness.mjs
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// response. Only show that response through the command's existing redactor.
|
|
3
3
|
export function mutationReadinessFailure(error, { again, redact }) {
|
|
4
4
|
if (!error.secretChange) return undefined;
|
|
5
|
-
const {
|
|
5
|
+
const { bindings, present } = error.secretChange, binding = bindings.join(', ');
|
|
6
6
|
const last = error.attempts?.at(-1);
|
|
7
7
|
const status = last?.status == null ? 'no HTTP response' : `HTTP ${last.status}`;
|
|
8
8
|
const first = redact(String(last?.body ?? '').split(/[\r\n]/, 1)[0]).slice(0, 256);
|
|
@@ -11,6 +11,6 @@ export function mutationReadinessFailure(error, { again, redact }) {
|
|
|
11
11
|
: `The secret change for ${binding} was applied and its new Worker version recorded.`;
|
|
12
12
|
const step = error.ownerFinalization ? 'owner claim/token retirement' : `secret change for ${binding}`;
|
|
13
13
|
const reason = /^[a-zA-Z0-9_-]{1,120}$/.test(error.message) ? error.message : 'health-check-failed';
|
|
14
|
-
const retirement = error.ownerFinalization ||
|
|
14
|
+
const retirement = error.ownerFinalization || bindings.includes('SETUP_TOKEN') && !present;
|
|
15
15
|
return redact(`${state} Hosted readiness failed after ${step}. ${status} (${reason}).${first ? ` First response line: ${first}` : ''} Update the seed/app configuration to match the changed secrets and redeploy with ${again}. ${retirement ? 'If the app requires the spent setup token, remove that requirement from its configuration before redeploying; keep the recorded owner and token retirement.' : 'If the secret input was incorrect, correct it and apply the intended secret change again.'}`);
|
|
16
16
|
}
|
package/cli/deploy.mjs
CHANGED
|
@@ -58,6 +58,7 @@ export function ownerDeploy(declarationPath, lifecycle) {
|
|
|
58
58
|
return { dryRun: true, deployed: false };
|
|
59
59
|
}
|
|
60
60
|
const { env, supplied, generated, reused, rotated } = await deployEnvironment({ root, options, declaration, setupManifest, settings: lifecycle.settings, localOnlyKeys });
|
|
61
|
+
if (options.setSecret || options.unsetSecret) secretChangeInputs(declaration, options, env, again);
|
|
61
62
|
const kept = keptSecrets(declaration, setupManifest);
|
|
62
63
|
if (cloudflareCredentials.some(name => !env[name]?.trim())) throw missing(missingCredentialsMessage(declaration, env));
|
|
63
64
|
const { main } = await import('../modules/deploy-kit/owner-cli.mjs');
|
|
@@ -93,10 +94,10 @@ export function ownerDeploy(declarationPath, lifecycle) {
|
|
|
93
94
|
}
|
|
94
95
|
if (change.length) {
|
|
95
96
|
step = 'secrets';
|
|
96
|
-
const
|
|
97
|
-
await owner('secret', [
|
|
98
|
-
store.report(`${options.setSecret ?
|
|
99
|
-
return {
|
|
97
|
+
const bindings = (options.setSecret ?? options.unsetSecret).split(','), flag = options.setSecret ? '--set' : '--unset';
|
|
98
|
+
await owner('secret', [...bindings.flatMap(binding => [flag, binding]), ...(state ? ['--state', state] : [])]);
|
|
99
|
+
store.report(`${options.setSecret ? 'Set' : 'Removed'} ${bindings.join(', ')} on this environment's Worker as one new version, recorded it and verified hosted readiness.`);
|
|
100
|
+
return { bindings, present: Boolean(options.setSecret), deployed: false };
|
|
100
101
|
}
|
|
101
102
|
store.report(`Deploying the ${environment} environment to your Cloudflare account.`);
|
|
102
103
|
deployed = await owner('deploy', [], env, { notice: line => store.report(line), onCreated: resource => created.push(redaction.redact(resource)) });
|
|
@@ -131,6 +132,18 @@ export function ownerDeploy(declarationPath, lifecycle) {
|
|
|
131
132
|
}, { declaration: declarationPath, managesHostedOwner: true });
|
|
132
133
|
}
|
|
133
134
|
|
|
135
|
+
// Every secret named in --set-secret or --unset-secret is declared, and each one set has its
|
|
136
|
+
// value, before any provider request: a group of secrets is changed whole or not at all.
|
|
137
|
+
function secretChangeInputs(declaration, options, env, again) {
|
|
138
|
+
const declared = Array.isArray(declaration.secrets) ? declaration.secrets : [], flag = options.setSecret ? '--set-secret' : '--unset-secret';
|
|
139
|
+
const named = (options.setSecret ?? options.unsetSecret).split(',');
|
|
140
|
+
const undeclared = named.filter(name => !declared.some(item => item?.binding === name));
|
|
141
|
+
if (undeclared.length) throw invalid(`${flag} names ${undeclared.join(', ')}, which the deploy declaration does not list as ${undeclared.length > 1 ? 'secrets' : 'a secret'}${declared.length ? ` (it declares ${declared.map(item => item.binding).join(', ')})` : ''}. Nothing was changed.`);
|
|
142
|
+
if (!options.setSecret) return;
|
|
143
|
+
const absent = named.map(name => declared.find(item => item.binding === name).environment).filter(name => !env[name]?.trim());
|
|
144
|
+
if (absent.length) throw missing(`${flag} ${options.setSecret} needs a value for each secret; ${absent.join(', ')} ${absent.length > 1 ? 'are' : 'is'} not set. Set ${absent.length > 1 ? 'them' : 'it'} in the environment or in an --env-file file (owned, mode 0600, one line per secret), then run ${again} ${flag} ${options.setSecret} again. Nothing was changed.`);
|
|
145
|
+
}
|
|
146
|
+
|
|
134
147
|
// The failing step, its redacted cause, what this run created and the command that continues.
|
|
135
148
|
function failureText({ error, step, created, again, retry, secretChange, deployed, redact }) {
|
|
136
149
|
if (step === 'remove') {
|
|
@@ -165,7 +178,7 @@ function failureText({ error, step, created, again, retry, secretChange, deploye
|
|
|
165
178
|
lines.push(`Resources created this attempt: ${created.join(', ') || 'none'}.`);
|
|
166
179
|
const migration = migrationFailure(error, again);
|
|
167
180
|
if (migration) lines.push(redact(migration));
|
|
168
|
-
if (code !== 'uncertain-migration-claim') lines.push(recovery({ code, at, resource, again, retry, secretChange }));
|
|
181
|
+
if (code !== 'uncertain-migration-claim' && !error.unconfirmedClaim) lines.push(recovery({ code, at, resource, again, retry, secretChange }));
|
|
169
182
|
return lines.join('\n');
|
|
170
183
|
}
|
|
171
184
|
|
package/cli/local.mjs
CHANGED
|
@@ -3,7 +3,7 @@ import { resolve, relative } from 'node:path';
|
|
|
3
3
|
import { createInterface } from 'node:readline/promises';
|
|
4
4
|
import { contained } from './project.mjs';
|
|
5
5
|
import { shared } from './shared.mjs';
|
|
6
|
-
import { origin, loopback } from './parse.mjs';
|
|
6
|
+
import { origin, loopback, listenHost } from './parse.mjs';
|
|
7
7
|
import { refuse } from './errors.mjs';
|
|
8
8
|
import { defaultPort, firstFreePort, busyPortMessage } from './port.mjs';
|
|
9
9
|
import { localSettingKeys } from './settings.mjs';
|
|
@@ -22,7 +22,11 @@ export async function selectedOrigin(project, options, { setup = false } = {}) {
|
|
|
22
22
|
// A front-door origin (saved, or --door on a fresh setup) serves through the door.
|
|
23
23
|
const door = await selectDoor(project, options, previous, { vars, savedOrigin: previous?.origin });
|
|
24
24
|
if (door) return door;
|
|
25
|
-
|
|
25
|
+
// A seed may declare the host a fresh checkout binds (commandAdapter({ host })),
|
|
26
|
+
// such as localhost for a WebAuthn RP ID; a saved origin keeps its own host.
|
|
27
|
+
const declared = project.adapter?.host;
|
|
28
|
+
if (declared !== undefined && !listenHost(declared)) throw refuse('The seed adapter declares host ' + JSON.stringify(String(declared)).slice(0, 80) + '; it must be exactly 127.0.0.1, localhost or ::1.');
|
|
29
|
+
const host = options.host ?? (previous && !doorSite(previous.origin) ? previous.hostname.replace(/^\[|\]$/g, '') : declared ?? '127.0.0.1');
|
|
26
30
|
const savedPort = previous && !doorSite(previous.origin) ? Number(previous.port || 80) : undefined;
|
|
27
31
|
// A first setup with no port asked for takes the first free one, never a busy one.
|
|
28
32
|
let port = options.port ?? savedPort, taken;
|
package/cli/parse.mjs
CHANGED
|
@@ -36,14 +36,16 @@ export function parse(argv, cwd = process.cwd(), { independent = false, deferTai
|
|
|
36
36
|
const suggestion=[...allowed].sort((a,b)=>distance(flag,a)-distance(flag,b))[0];
|
|
37
37
|
throw invalid(`Unsupported flag ${/^--[a-zA-Z-]{1,40}$/.test(flag)?flag:'(invalid)'} for ${verb}.${suggestion?` Did you mean ${suggestion}?`:''} Run rer ${verb} --help.`);
|
|
38
38
|
}
|
|
39
|
-
|
|
39
|
+
// Several secrets change in one deploy: --set-secret A --set-secret B is --set-secret A,B.
|
|
40
|
+
const listed = ['--set-secret', '--unset-secret'].includes(flag);
|
|
41
|
+
if (options.supplied.has(flag) && !listed) throw invalid(`Repeated flag ${flag} for ${verb}. Run rer ${verb} --help.`);
|
|
40
42
|
options.supplied.add(flag);
|
|
41
43
|
const key = flag.slice(2).replace(/-([a-z])/g, (_, c) => c.toUpperCase());
|
|
42
44
|
if (booleans.has(flag)) options[key] = true;
|
|
43
45
|
else {
|
|
44
46
|
const value = args[++i];
|
|
45
47
|
if (value === undefined || value.startsWith('--') || !value.trim()) throw invalid(`A value is required for ${flag}.`);
|
|
46
|
-
options[key] = value;
|
|
48
|
+
options[key] = listed && options[key] !== undefined ? `${options[key]},${value}` : value;
|
|
47
49
|
}
|
|
48
50
|
}
|
|
49
51
|
if (options.help) return options;
|
|
@@ -83,7 +85,11 @@ export function parse(argv, cwd = process.cwd(), { independent = false, deferTai
|
|
|
83
85
|
if (options.target !== undefined && !['local', 'remote'].includes(options.target)) throw invalid('Target must be local or remote.');
|
|
84
86
|
if (options.profile !== undefined && options.profile !== 'first-party') throw invalid('The supported explicit profile is first-party.');
|
|
85
87
|
if (options.environment !== undefined && !/^[a-z][a-z0-9-]{0,39}$/.test(options.environment)) throw invalid('Provide a valid deployment environment name.');
|
|
86
|
-
for (const key of ['setSecret', 'unsetSecret']) if (options[key] !== undefined
|
|
88
|
+
for (const key of ['setSecret', 'unsetSecret']) if (options[key] !== undefined) {
|
|
89
|
+
const names = [...new Set(options[key].split(','))];
|
|
90
|
+
if (names.length > 16 || !names.every(name => /^[A-Z][A-Z0-9_]{0,63}$/.test(name))) throw invalid(`--${key === 'setSecret' ? '' : 'un'}set-secret names declared secret bindings, repeated or separated by commas, such as SESSION_SECRET or MAIL_API_KEY,MAIL_FROM.`);
|
|
91
|
+
options[key] = names.join(',');
|
|
92
|
+
}
|
|
87
93
|
if (options.rotateSecret !== undefined && !/^[A-Z][A-Z0-9_]{0,63}(?:,[A-Z][A-Z0-9_]{0,63}){0,15}$/.test(options.rotateSecret)) throw invalid('--rotate-secret names generated secret bindings, separated by commas, such as SESSION_SECRET.');
|
|
88
94
|
if(verb==='deploy'&&options.demo&&(options.site||['platform','image','bindAddress','httpPort','httpsPort','envFile','host','setSecret','unsetSecret','rotateSecret'].some(key=>options[key]!==undefined)))throw invalid('--demo takes only --environment, --dry-run and --remove --yes: the hosted demo is its own Worker on demo.<domain>.');
|
|
89
95
|
if(verb==='deploy'&&options.demo&&options.remove&&(options.dryRun||!options.yes))throw invalid(options.dryRun?'Use --remove and --dry-run on separate runs.':'deploy --demo --remove deletes the hosted demo\'s Worker, its demo.<domain> Custom Domain. Add --yes to confirm.');
|
package/cli/port.mjs
CHANGED
|
@@ -4,21 +4,20 @@ import { createServer } from 'node:net';
|
|
|
4
4
|
import { readJson } from '../modules/job-queue/storage.mjs';
|
|
5
5
|
import { serversDirectory, stopInstruction } from './server-registry.mjs';
|
|
6
6
|
import { shared } from './shared.mjs';
|
|
7
|
+
import { refuse } from './errors.mjs';
|
|
7
8
|
|
|
8
9
|
export const defaultPort = 8787;
|
|
9
10
|
|
|
10
11
|
// The first port from `from` that nothing listens on, on any address, and that
|
|
11
|
-
// this host can bind
|
|
12
|
-
// which a bind to 127.0.0.1
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
}
|
|
21
|
-
throw Error(`No free port from ${from} upward.`);
|
|
12
|
+
// this host can bind, among the next `searchCandidates` ports. Another
|
|
13
|
+
// checkout's server may listen on every address, which a bind to 127.0.0.1
|
|
14
|
+
// alone does not notice. Only a port in use is skipped; the search never gives
|
|
15
|
+
// up for time or load, only after every candidate was refused.
|
|
16
|
+
export async function firstFreePort(host, from = defaultPort) {
|
|
17
|
+
const { searchPort } = await shared('port-probe.mjs');
|
|
18
|
+
const found = await searchPort({ host, from, verb: 'setup' });
|
|
19
|
+
if (found.port !== undefined) return found.port;
|
|
20
|
+
throw refuse(`No free port from ${found.range[0]} to ${found.range[1]}: all ${found.tried} ports tried were in use. Stop something that holds one, or run rer setup --port PORT with a free port.`);
|
|
22
21
|
}
|
|
23
22
|
|
|
24
23
|
// Who holds a port: a server another checkout registered (its path and the
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { readFile } from 'node:fs/promises';
|
|
2
|
+
import { resolve } from 'node:path';
|
|
3
|
+
import { refuse } from './errors.mjs';
|
|
4
|
+
|
|
5
|
+
// A fleet's server limit as one current value its newest launcher controls.
|
|
6
|
+
// RER_SERVER_LIMIT_FILE names a file holding a positive integer, read afresh at
|
|
7
|
+
// every start; that value is the limit for the start and overrides this process's
|
|
8
|
+
// RER_SERVER_LIMIT and every running server's recorded limit, so a long-lived run
|
|
9
|
+
// that still exports an older RER_SERVER_LIMIT cannot cap the others. Unset, the
|
|
10
|
+
// start behaves as before. A file that cannot be read or holds anything else
|
|
11
|
+
// refuses the start: there is no silent fallback to another limit.
|
|
12
|
+
export async function serverLimitFile(env = process.env) {
|
|
13
|
+
if (env.RER_SERVER_LIMIT_FILE === undefined) return undefined;
|
|
14
|
+
const path = resolve(env.RER_SERVER_LIMIT_FILE);
|
|
15
|
+
let text;
|
|
16
|
+
try { text = await readFile(path, 'utf8'); }
|
|
17
|
+
catch (error) { throw refuse(`Not started: RER_SERVER_LIMIT_FILE names ${path}, which cannot be read (${error.code ?? error.message}). Create it holding a positive whole number such as 10, or unset RER_SERVER_LIMIT_FILE.`); }
|
|
18
|
+
const value = text.trim();
|
|
19
|
+
if (!/^[1-9][0-9]*$/.test(value) || !Number.isSafeInteger(Number(value))) throw refuse(`Not started: ${path} (RER_SERVER_LIMIT_FILE) must hold one positive whole number such as 10, and holds ${JSON.stringify(value.length > 40 ? `${value.slice(0, 40)}...` : value)}. Fix the file, or unset RER_SERVER_LIMIT_FILE.`);
|
|
20
|
+
return { path, limit: Number(value) };
|
|
21
|
+
}
|
package/cli/server-registry.mjs
CHANGED
|
@@ -9,6 +9,7 @@ import { identity, alive } from '../modules/job-queue/identity.mjs';
|
|
|
9
9
|
import { transaction } from '../modules/job-queue/storage.mjs';
|
|
10
10
|
import { refuse, invalid } from './errors.mjs';
|
|
11
11
|
import { serverDefaults } from './contract.mjs';
|
|
12
|
+
import { serverLimitFile } from './server-limit-file.mjs';
|
|
12
13
|
import { availableMemory } from '../modules/job-queue/resources.mjs';
|
|
13
14
|
|
|
14
15
|
export function positive(value, name, fallback) {
|
|
@@ -55,11 +56,13 @@ function memoryMessage(counted,available,floor,mode) {
|
|
|
55
56
|
const list=counted.length?`Running now:\n${counted.map(listing).join('\n')}\nA dev server holds about 0.5-1.3 GiB and a preview 0.4-0.8 GiB; stopping one with its command above frees that.`:'No dev or preview server is running, so something else is using the memory.';
|
|
56
57
|
return `${head}\n${list}\nTo start anyway, lower the floor, for example RER_SERVERS_MIN_MEMORY_BYTES=${Math.floor(floor/2)} rer ${mode} (0 turns it off).`;
|
|
57
58
|
}
|
|
58
|
-
function limitMessage(counted,cap,explicit,mode) {
|
|
59
|
+
function limitMessage(counted,cap,explicit,mode,file) {
|
|
59
60
|
const holders=explicit?[]:counted.filter(item=>item.explicit&&item.limit===cap);
|
|
60
61
|
const head=`Not started: ${counted.length} dev or preview ${counted.length===1?'server is':'servers are'} running on this computer and the limit is ${cap}.`;
|
|
61
62
|
const list=`Running now:\n${counted.map(listing).join('\n')}`;
|
|
62
|
-
const raise=
|
|
63
|
+
const raise=file
|
|
64
|
+
?`The limit is ${cap} because ${file} (RER_SERVER_LIMIT_FILE) says ${cap}; to allow more, raise the number in that file and start again.`
|
|
65
|
+
:holders.length
|
|
63
66
|
?`The limit is ${cap} because ${holders.length===1?'a server was':'servers were'} started with RER_SERVER_LIMIT=${cap} (${holders.map(item=>item.checkout).join(', ')}). Stop ${holders.length===1?'it':'them'} and start again, or start everything with a higher RER_SERVER_LIMIT=N.`
|
|
64
67
|
:explicit?`This start set RER_SERVER_LIMIT=${cap}; to allow more, start it with a higher RER_SERVER_LIMIT=N.`
|
|
65
68
|
:`To allow more, start this one with a higher limit, for example RER_SERVER_LIMIT=${cap*2} rer ${mode}. Servers started without RER_SERVER_LIMIT allow ${defaultServerLimit}.`;
|
|
@@ -78,7 +81,10 @@ function limitMessage(counted,cap,explicit,mode) {
|
|
|
78
81
|
// running server's person set explicitly, so a deliberate "RER_SERVER_LIMIT=3"
|
|
79
82
|
// keeps holding starts that do not say otherwise. A recorded default (including
|
|
80
83
|
// the old default of 2 in records written before this rule) never lowers the cap
|
|
81
|
-
// below the current default.
|
|
84
|
+
// below the current default. When RER_SERVER_LIMIT_FILE names a file holding a
|
|
85
|
+
// positive integer, that value (read at this start) is the cap and overrides both
|
|
86
|
+
// RER_SERVER_LIMIT and every running record's limit: records started under the
|
|
87
|
+
// file are counted, and the limit they recorded lowers nothing.
|
|
82
88
|
export const defaultServerLimit=serverDefaults.serverLimit;
|
|
83
89
|
export const serversDirectory=(env=process.env)=>resolve(env.RER_SERVERS_DIR??join((env.HOME || homedir()),'.rer/servers'));
|
|
84
90
|
export async function serverRegistry(root,{env=process.env,memory=availableMemory}={}) {
|
|
@@ -140,12 +146,13 @@ export async function serverRegistry(root,{env=process.env,memory=availableMemor
|
|
|
140
146
|
const same=state.running.find(item=>item.checkout===checkout);
|
|
141
147
|
if(same)return {existing:same};
|
|
142
148
|
// Journeys are listed but uncounted: they neither use nor lower the cap.
|
|
143
|
-
const counted=state.running.filter(item=>!item.journey)
|
|
144
|
-
|
|
149
|
+
const fileLimit=await serverLimitFile(env),counted=state.running.filter(item=>!item.journey);
|
|
150
|
+
const cap=fileLimit?fileLimit.limit:explicit?limit:Math.min(limit,...counted.filter(item=>item.explicit).map(item=>item.limit));
|
|
151
|
+
if(!journey&&counted.length>=cap)throw refuse(limitMessage(counted,cap,explicit||Boolean(fileLimit),mode,fileLimit?.path));
|
|
145
152
|
// Unreadable memory is not a reason to refuse; only a reading below the floor is.
|
|
146
153
|
const available=journey||floor===0?NaN:await memory();
|
|
147
154
|
if(available<floor)throw refuse(memoryMessage(counted,available,floor,mode));
|
|
148
|
-
owned={checkout,mode,journey,generation:randomUUID(),token:randomUUID(),owner:lifetime.info,limit,explicit,startedAt:Number(process.hrtime.bigint()/1000000n),idleTimeout:options.idleTimeout};
|
|
155
|
+
owned={checkout,mode,journey,generation:randomUUID(),token:randomUUID(),owner:lifetime.info,limit:fileLimit?fileLimit.limit:limit,explicit:explicit||Boolean(fileLimit),startedAt:Number(process.hrtime.bigint()/1000000n),idleTimeout:options.idleTimeout};
|
|
149
156
|
owned.lastActivity=owned.startedAt;owned.active=0;
|
|
150
157
|
const name=`rer-server-${createHash('sha256').update(owned.generation).digest('hex').slice(0,20)}.sock`;
|
|
151
158
|
owned.control=join(tmpdir(),name);if(Buffer.byteLength(owned.control)>=100)owned.control=join('/tmp',name);
|
package/cli/server-resources.mjs
CHANGED
|
@@ -5,18 +5,29 @@ import {refuse} from './errors.mjs';
|
|
|
5
5
|
// after finite preparation, while its canonical server reservation is held.
|
|
6
6
|
// The 1-minute-load guard is a fleet's rule, set in the fleet's environment:
|
|
7
7
|
// without RER_SERVERS_LOAD_THRESHOLD a person's start is never refused for load.
|
|
8
|
+
// The free-disk floor is 15 GiB; a CI or managed build runner on a smaller disk
|
|
9
|
+
// sets RER_SERVERS_DISK_FLOOR_GIB, in GiB with decimals allowed and 0 for no floor.
|
|
8
10
|
export function servingLoadThreshold(env=process.env){
|
|
9
11
|
if(env.RER_SERVERS_LOAD_THRESHOLD===undefined)return Infinity;
|
|
10
12
|
const threshold=Number(env.RER_SERVERS_LOAD_THRESHOLD);
|
|
11
13
|
if(!Number.isFinite(threshold)||threshold<0)throw refuse('Invalid server load threshold.');
|
|
12
14
|
return threshold;
|
|
13
15
|
}
|
|
16
|
+
const gibibyte=1024n**3n;
|
|
17
|
+
export function serversDiskFloor(env=process.env){
|
|
18
|
+
const value=env.RER_SERVERS_DISK_FLOOR_GIB;
|
|
19
|
+
if(value===undefined)return {gib:15,bytes:15n*gibibyte};
|
|
20
|
+
const gib=Number(value);
|
|
21
|
+
if(!/^(\d+\.?\d*|\.\d+)$/.test(value)||!Number.isFinite(gib))throw refuse('Invalid server disk floor. RER_SERVERS_DISK_FLOOR_GIB must be a number of GiB such as 4 or 2.5, 0 for no floor.');
|
|
22
|
+
return {gib,bytes:BigInt(Math.round(gib*Number(gibibyte)))};
|
|
23
|
+
}
|
|
14
24
|
export async function serverResources(root,{load=()=>loadavg()[0],disk=statfs,env=process.env}={}){
|
|
15
|
-
const threshold=servingLoadThreshold(env);
|
|
25
|
+
const threshold=servingLoadThreshold(env),floor=serversDiskFloor(env);
|
|
16
26
|
const measured=threshold===Infinity?0:await load();
|
|
17
27
|
if(!Number.isFinite(measured)||measured>threshold)throw refuse(`Not started: this computer is busy. Its 1-minute load is ${Number.isFinite(measured)?measured.toFixed(1):'unknown'} and a server starts only at ${threshold} or below.\nTry again in a few minutes, or start it anyway with a higher threshold, for example RER_SERVERS_LOAD_THRESHOLD=${Math.ceil(Math.max(threshold,Number.isFinite(measured)?measured:0)*2)} rer dev.`);
|
|
18
28
|
for(const path of new Set([root,tmpdir()])){
|
|
19
29
|
const state=await disk(path,{bigint:true});
|
|
20
|
-
|
|
30
|
+
const free=state.bavail*state.bsize;
|
|
31
|
+
if(free<floor.bytes)throw refuse(`Server startup requires ${floor.gib} GiB free on checkout and temporary volumes, and ${path} has ${(Number(free*10n/gibibyte)/10).toFixed(1)} GiB free. Recover owned space before retrying.\nA CI runner on a small disk can lower the floor with RER_SERVERS_DISK_FLOOR_GIB (for example 4).`);
|
|
21
32
|
}
|
|
22
33
|
}
|
package/global/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,22 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.2.45
|
|
4
|
+
|
|
5
|
+
- **`RER_SERVER_LIMIT_FILE` sets the server limit from a file.** A start that sees it reads the positive integer in the named file and uses that as the limit, over its own `RER_SERVER_LIMIT` and over the limits running servers recorded, in both the launcher's check and the dispatcher's registry. A fleet's launcher points every run at one file, so a long-lived run that still exports an older `RER_SERVER_LIMIT` can no longer cap the rest. An unreadable file or a non-integer refuses the start naming the file; the limit refusal names it when it set the cap. Without the variable nothing changes (#205).
|
|
6
|
+
- **`rer deploy` retries a migration that D1 rolled back, when a reviewed rewrite replaced its bytes.** If a hosted D1 import fails, D1 rolls it back, but rer's ledger keeps an `applying` claim on the old bytes. Before, a reviewed rewrite in `migrations/rewrites.json` covered only an `applied` row, so `rer deploy` refused with `changed-or-uncertain-migration-history`. Now, holding its deploy state lock, `rer deploy` reruns a claim whose bytes are a declared `rewrites[].from`, using the current bytes. It does so only after the same proof that none of the effects are present, and it prints `Migrations: retried <name>: the earlier attempt was rolled back`. A claim on any other bytes is still refused, and the refusal now gives the exact `wrangler d1 execute` command, filled in, and says when running it is safe. A table the migration rebuilds no longer blocks the retry. The absence check also now fits within D1's limit on compound SELECT terms (#208).
|
|
7
|
+
- **A seed can declare the host a fresh checkout binds.** A seed's `commandAdapter({ host })` names `127.0.0.1`, `localhost` or `::1`, and a fresh checkout binds that host. Any other value is refused. A saved origin keeps its own host, and `--host` and the front door still take precedence. Auth declares `localhost`, because WebAuthn refuses an IP address as a passkey relying-party ID. In package mode Auth no longer needs the `pnpm patch` of `@runeditrun/rer`, which `rer check` SC-13 refused as a patched pin (#204).
|
|
8
|
+
- **`RER_SERVERS_DISK_FLOOR_GIB` sets `rer dev`'s free-disk floor.** The value is a number of GiB (decimals allowed, 0 for no floor). Unset, the floor is 15, as before. An invalid value refuses with exit 4 and names the variable. The disk refusal states the floor it used, the free space it measured and the path it measured, and names the variable. CI or managed build runners on small disks may set it lower, for example 4 (#210).
|
|
9
|
+
- **The hosted demo start page prefetches the console's chunks while the visitor waits.** `rer deploy --demo` writes an ordered list of the seed's hashed `/assets` chunks into the native demo bundle. The root and console layouts come first, then the console's own views, capped at 1 MiB gzip. The start page names them as `<link rel="prefetch">`. The first visit to each console view then finds its chunks already at the edge (Mango's first-visit navigation p50 went from about 380 ms to about 90 ms on a cold colo). The start request, the sign-in redirect and the CSP are unchanged (#207).
|
|
10
|
+
- **`rer dev` and `rer setup` no longer give up on a free port because the computer is busy.** Before, both free-port searches stopped on a wall-clock deadline. Under heavy load, `rer dev` could stop with "Could not find a free port … in time (system busy)" even with free ports ahead. Now both try the next 1000 ports and wait for each bind's own answer. They give up only when every candidate was refused, and the message names the range and the count (#211).
|
|
11
|
+
|
|
12
|
+
## 0.2.44
|
|
13
|
+
|
|
14
|
+
- **Under `rer dev`, a seed can link to another local seed over http.** The dependencies module accepts a provider address of `http://127.0.0.1`, `http://[::1]` or `http://localhost`, on any port, for the RER auth preset, but only when the app runs under `rer dev`. That lets a local Balm link to a local Auth. Every other `http` address, and every hosted deploy, still requires https (#196).
|
|
15
|
+
- **`rer deploy` sets or removes a group of secrets in one Worker version.** Name the secrets with the flag repeated, `rer deploy --set-secret A --set-secret B`, or as a comma list, `--set-secret A,B`, and the same for `--unset-secret`. Either every named secret changes in one new Worker version, or none does, so a seed page can give one copy-paste command for the whole group. Every named secret must be declared, and each one being set needs its value in the environment or `--env-file`. Otherwise rer names each missing secret and changes nothing. An unchanged repeat writes nothing. Other repeated flags are still refused (#199).
|
|
16
|
+
- **A seed's first hosted change no longer trips the credential scan on the /contract styles.** `contract-style.ts` renames its `TOKENS` constant to `DEFAULTS`. The CSS bytes are unchanged. The old name, given a long CSS value, matched the hosted change scan's credential rule (SEC-3). A seed that carries `src/base/runtime/contract-style.ts` picks this up on its next Base refresh (#203).
|
|
17
|
+
- **A test host now moves a seed's secondary demo hosts too.** Before, the run-demo template's "Scope the test host" step moved only the demo domain. Now it also moves every deploy-demo.json setting that equals `demo.<domain>` or ends in `.demo.<domain>`, placing each under `demo.test.<domain>`. A seed such as Lamp, whose demo has a secondary page host, can now plan a test-host demo. Production runs are unchanged (#200).
|
|
18
|
+
- **Base's user-facing copy uses US spelling.** The /run footer reads "MIT license". The sign-in alerts read "Your organization requires…" and "Sign-in was canceled at the provider." Setup's "Brand color" label, "Choose a color", the color validation messages and other CLI messages now use color, catalog and canceled. Identifiers, status codes and data keys are unchanged (#206).
|
|
19
|
+
|
|
3
20
|
## 0.2.43
|
|
4
21
|
|
|
5
22
|
- **The installer ends with the line that puts `rer` on PATH.** `install.sh` and `rer cli install` end with `Next, start an app: rer dev <owner>/<repo>`. When new terminals will not find `rer`, the last line is the one command that adds `~/.local/bin` for your shell, for example `echo 'export PATH="$HOME/.local/bin:$PATH"' >> ~/.zshrc && export PATH="$HOME/.local/bin:$PATH"` (bash: `~/.bash_profile` on macOS and `~/.bashrc` elsewhere; fish: `fish_add_path ~/.local/bin`; otherwise `~/.profile`). Once a startup file already adds it, no line is printed. The installer still never edits a shell profile itself (#190).
|
package/global/README.md
CHANGED
|
@@ -181,11 +181,17 @@ naming their PIDs.
|
|
|
181
181
|
|
|
182
182
|
Servers started through `rer` (`rer dev`, `rer preview`) get a 10-server limit and a 12-hour idle timeout
|
|
183
183
|
unless you set `RER_SERVER_LIMIT`, `RER_SERVER_IDLE_SECONDS` or `--idle-timeout`.
|
|
184
|
+
`RER_SERVER_LIMIT_FILE=PATH` names a file holding the limit as a positive integer,
|
|
185
|
+
read at every start; it overrides `RER_SERVER_LIMIT` and the limits running servers
|
|
186
|
+
recorded, so a fleet's one current value cannot be capped by an older run's
|
|
187
|
+
environment. An unreadable or non-integer file refuses the start, naming the file.
|
|
184
188
|
`rer` supplies them only to checkouts whose pinned copy applies lower defaults
|
|
185
189
|
or does not report its own (`rer describe` reports `defaults`), so a current
|
|
186
190
|
checkout never records a limit you did not set.
|
|
187
191
|
A start is never refused for machine load alone unless `RER_SERVERS_LOAD_THRESHOLD`
|
|
188
|
-
or `RER_JOBS_LOAD_THRESHOLD` is set; memory and disk guards stay.
|
|
192
|
+
or `RER_JOBS_LOAD_THRESHOLD` is set; memory and disk guards stay. The disk guard
|
|
193
|
+
needs 15 GiB free; `RER_SERVERS_DISK_FLOOR_GIB=N` changes it (CI runners may set
|
|
194
|
+
it lower, for example 4; people should not).
|
|
189
195
|
|
|
190
196
|
## The front door
|
|
191
197
|
|
|
@@ -8,6 +8,8 @@ import { existsSync } from 'node:fs';
|
|
|
8
8
|
import { join } from 'node:path';
|
|
9
9
|
import { pathToFileURL } from 'node:url';
|
|
10
10
|
import { liveServers, stopCommand } from '../registry.mjs';
|
|
11
|
+
import { RerError } from '../../cli/errors.mjs';
|
|
12
|
+
import { serverLimitFile } from '../../cli/server-limit-file.mjs';
|
|
11
13
|
import { LaunchFailure } from './failure.mjs';
|
|
12
14
|
|
|
13
15
|
export const personDefaults = { limit: 10, idleSeconds: 43200 };
|
|
@@ -44,7 +46,8 @@ export function personEnvironment(env, args, pin) {
|
|
|
44
46
|
const listing = record => ` ${record.mode} on port ${record.port ?? '(starting)'} in ${record.checkout} (PID ${record.owner?.pid})\n stop it with: ${stopCommand(record)}`;
|
|
45
47
|
|
|
46
48
|
// Refuse in seconds, before any install or setup, when the pinned dispatcher
|
|
47
|
-
// would refuse the start for the server limit.
|
|
49
|
+
// would refuse the start for the server limit. RER_SERVER_LIMIT_FILE, when set,
|
|
50
|
+
// is the cap alone, as in the dispatcher's registry. Returns this checkout's own
|
|
48
51
|
// running server when there is one.
|
|
49
52
|
export async function checkCapacity(checkout, env, pin) {
|
|
50
53
|
const running = await liveServers(env);
|
|
@@ -52,8 +55,9 @@ export async function checkCapacity(checkout, env, pin) {
|
|
|
52
55
|
if (own) return { own };
|
|
53
56
|
if (env.RER_SERVER_JOURNEY === '1') return {};
|
|
54
57
|
const counted = running.filter(record => !record.journey);
|
|
55
|
-
const
|
|
56
|
-
const
|
|
58
|
+
const file = await serverLimitFile(env).catch(error => { throw error instanceof RerError ? new LaunchFailure(error.exitCode, error.message) : error; });
|
|
59
|
+
const limit = file ? file.limit : Number(env.RER_SERVER_LIMIT ?? pin.limit);
|
|
60
|
+
const binding = file ? [] : pin.explicitOnly ? counted.filter(record => record.explicit) : counted;
|
|
57
61
|
const cap = Math.min(limit, ...binding.map(record => record.limit));
|
|
58
62
|
if (counted.length < cap) return {};
|
|
59
63
|
const holders = cap < limit ? binding.filter(record => record.limit === cap) : [];
|
|
@@ -67,6 +71,7 @@ export async function checkCapacity(checkout, env, pin) {
|
|
|
67
71
|
throw new LaunchFailure(4, [
|
|
68
72
|
`Not started: ${counted.length} dev or preview ${counted.length === 1 ? 'server is' : 'servers are'} running on this computer and the limit is ${cap}.`,
|
|
69
73
|
'Running now:', ...counted.map(listing),
|
|
70
|
-
`To make room, stop one with its command above, or
|
|
74
|
+
file ? `The limit is ${cap} because ${file.path} (RER_SERVER_LIMIT_FILE) says ${cap}. To make room, stop one with its command above, or raise the number in that file.`
|
|
75
|
+
: `To make room, stop one with its command above, or start this one with a higher limit, for example RER_SERVER_LIMIT=${cap * 2} rer dev.`,
|
|
71
76
|
].join('\n'));
|
|
72
77
|
}
|
package/global/launch/facts.mjs
CHANGED
|
@@ -3,8 +3,7 @@ import { execFile } from 'node:child_process';
|
|
|
3
3
|
import { stat } from 'node:fs/promises';
|
|
4
4
|
import { join } from 'node:path';
|
|
5
5
|
import { promisify } from 'node:util';
|
|
6
|
-
import {
|
|
7
|
-
import { probePort } from '../../onboarding/port-probe.mjs';
|
|
6
|
+
import { probePort, searchPort } from '../../onboarding/port-probe.mjs';
|
|
8
7
|
import { LaunchFailure } from './failure.mjs';
|
|
9
8
|
|
|
10
9
|
const run = promisify(execFile);
|
|
@@ -69,24 +68,17 @@ export async function portTaken(port) {
|
|
|
69
68
|
return Boolean((await probePort('127.0.0.1', port, { hosts: ['127.0.0.1', '::1'], anyAddress: true })).listener);
|
|
70
69
|
}
|
|
71
70
|
|
|
72
|
-
// The first port from 8787 (RER_DEV_PORT_FROM moves the start)
|
|
73
|
-
// `held` (by a registered server, or saved
|
|
74
|
-
// nothing listens on, binds on both
|
|
75
|
-
// ::1
|
|
76
|
-
// another launch choosing it at the
|
|
71
|
+
// The first port from 8787 (RER_DEV_PORT_FROM moves the start), among the next
|
|
72
|
+
// `searchCandidates` ports, that is not `held` (by a registered server, or saved
|
|
73
|
+
// by another checkout that is stopped), nothing listens on, binds on both
|
|
74
|
+
// 127.0.0.1 and ::1 (a browser that tries ::1 first never reaches another
|
|
75
|
+
// server) and that `claim` secures against another launch choosing it at the
|
|
76
|
+
// same time. The search is bounded by that count, never by time or load.
|
|
77
77
|
export async function freePort(ports, claim, env = process.env) {
|
|
78
78
|
const from = Number(env.RER_DEV_PORT_FROM ?? 8787);
|
|
79
79
|
if (!Number.isInteger(from) || from < 1 || from > 65535) throw new LaunchFailure(2, 'RER_DEV_PORT_FROM must be a port number.');
|
|
80
|
-
const held = new Set(ports.filter(Boolean))
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
if (!result.available) {
|
|
85
|
-
if (performance.now() >= context.deadline) throw new LaunchFailure(4, `Could not find a free port from ${from} in time (system busy). Run rer dev again or pass rer dev --port PORT with a free port.`);
|
|
86
|
-
continue;
|
|
87
|
-
}
|
|
88
|
-
const claimed = await claim(port);
|
|
89
|
-
if (claimed) return { port, ...claimed };
|
|
90
|
-
}
|
|
91
|
-
throw new LaunchFailure(4, `No free port from ${from} upward. Pass one with rer dev --port PORT.`);
|
|
80
|
+
const held = new Set(ports.filter(Boolean));
|
|
81
|
+
const found = await searchPort({ host: '127.0.0.1', from, hosts: ['127.0.0.1', '::1'], skip: port => held.has(port), claim, verb: 'dev' });
|
|
82
|
+
if (found.port !== undefined) return found;
|
|
83
|
+
throw new LaunchFailure(4, `No free port from ${found.range[0]} to ${found.range[1]}: all ${found.tried} ports tried were in use. Stop something that holds one, or pass rer dev --port PORT with a free port.`);
|
|
92
84
|
}
|
|
@@ -12,6 +12,9 @@ host. See [adoption and deployment](../../export/DEMO.md#hosting-the-demo).
|
|
|
12
12
|
outbound requests return to the same visitor, including declared secondary hosts.
|
|
13
13
|
- `worker.mjs`, `pages.mjs`, `start-script.mjs`: Turnstile start, progress,
|
|
14
14
|
cancellation and visitor routing. Static assets are served at the edge.
|
|
15
|
+
- `native/warm.mjs`: the start page's prefetch list, built from `dist/client`
|
|
16
|
+
and TanStack Start's route manifest, the console's views first, capped by
|
|
17
|
+
compressed size.
|
|
15
18
|
- `capacity.mjs`: concurrent visitor admission and operator diagnostics. This
|
|
16
19
|
is used by the native host as well as retained during legacy upgrades.
|
|
17
20
|
- `upgrade.mjs`: verifies ownership, removes the old Container application and
|
|
@@ -40,7 +40,9 @@ export async function buildDemo(root, output, declaration) {
|
|
|
40
40
|
await rm(output, { recursive: true, force: true });
|
|
41
41
|
await mkdir(join(output, 'app'), { recursive: true });
|
|
42
42
|
await cp(join(root, 'dist'), join(output, 'app/dist'), { recursive: true });
|
|
43
|
-
|
|
43
|
+
// Where the console is mounted orders what the start page prefetches (native/warm.mjs).
|
|
44
|
+
const { operatorPath } = JSON.parse(await readFile(join(root, 'seed.json'), 'utf8').catch(() => '{}')).deploy ?? {};
|
|
45
|
+
await writeFile(join(output, 'app/demo.json'), JSON.stringify({ config: workerConfig, migrations, operatorPath }) + '\n');
|
|
44
46
|
}
|
|
45
47
|
|
|
46
48
|
if (process.argv[1] === import.meta.filename) {
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { parseCron } from './cron.mjs';
|
|
2
2
|
|
|
3
3
|
export const RUNTIME_FILES = ['config', 'worker', 'visitor', 'loader', 'd1', 'sql', 'r2', 'r2-store', 'queues', 'resources', 'cron', 'bridge', 'alarms'];
|
|
4
|
+
// Hashed build output: served immutable, and what the start page may prefetch.
|
|
5
|
+
export const HASHED_ASSET = /^\/assets\/.*-[\w-]{8,}\.[\w]+$/;
|
|
4
6
|
export const ISOLATE_FILES = ['bindings', 'namespace', 'r2-client', 'd1', 'sql', 'seed-object'];
|
|
5
7
|
export function nativeBindings(config) {
|
|
6
8
|
for (const kind of ['kv_namespaces', 'services', 'workflows', 'ai', 'vectorize', 'hyperdrive', 'analytics_engine_datasets', 'browser', 'images', 'send_email', 'dispatch_namespaces', 'mtls_certificates', 'pipelines', 'secrets_store_secrets', 'unsafe', 'vpc_services', 'vpc_networks', 'ratelimits', 'worker_loaders', 'containers', 'ai_search_namespaces', 'ai_search', 'agent_memory', 'connect', 'artifacts', 'unsafe_hello_world', 'flagship', 'logfwdr', 'version_metadata']) {
|
|
@@ -4,6 +4,7 @@ import { createHash } from 'node:crypto';
|
|
|
4
4
|
import { collectBuildModules } from '../../deploy-kit/build-modules.mjs';
|
|
5
5
|
import { collectFiles, moduleType } from '../../deploy-kit/artifact.mjs';
|
|
6
6
|
import { nativeBindings, ISOLATE_FILES, objectExports } from './config.mjs';
|
|
7
|
+
import { warmList } from './warm.mjs';
|
|
7
8
|
|
|
8
9
|
// The Worker Loader module kind for each upload type deploy-kit gives a build
|
|
9
10
|
// module, so a demo carries what a normal deploy uploads. Binary kinds travel
|
|
@@ -32,7 +33,8 @@ export async function prepareNative(folder) {
|
|
|
32
33
|
const assets = await collectFiles(join(app, 'dist/client'));
|
|
33
34
|
const bundle = { compatibilityDate: config.compatibility_date, compatibilityFlags: [...new Set([...(config.compatibility_flags ?? []), 'nodejs_compat'])], modules,
|
|
34
35
|
bindings, migrations: manifest.migrations, vars: config.vars ?? {}, crons: config.triggers?.crons ?? [],
|
|
35
|
-
assetPaths: assets.filter(file => !file.path.split('/').some(part => part.startsWith('.'))).map(file => '/' + file.path)
|
|
36
|
+
assetPaths: assets.filter(file => !file.path.split('/').some(part => part.startsWith('.'))).map(file => '/' + file.path),
|
|
37
|
+
warm: (await warmList(assets, root, manifest.operatorPath)).paths };
|
|
36
38
|
bundle.digest = createHash('sha256').update(JSON.stringify(bundle)).digest('hex');
|
|
37
39
|
await cp(join(app, 'dist/client'), join(folder, 'assets'), { recursive: true });
|
|
38
40
|
await writeFile(join(folder, 'modules/demo-host/native/bundle.mjs'), `export default ${JSON.stringify(bundle)};\n`);
|