@runeditrun/rer 0.2.29 → 0.2.31
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 +16 -0
- package/cli/README.md +17 -0
- package/cli/business/command.mjs +27 -0
- package/cli/business/detector.mjs +42 -0
- package/cli/business/parsers-config.mjs +91 -0
- package/cli/business/parsers-infrastructure.mjs +68 -0
- package/cli/business/parsers-packages.mjs +84 -0
- package/cli/business/parsers-pulumi.mjs +64 -0
- package/cli/business/parsers-syntax.mjs +113 -0
- package/cli/business/parsers-terraform.mjs +53 -0
- package/cli/business/parsers.mjs +62 -0
- package/cli/business/policy.mjs +46 -0
- package/cli/business/scan.mjs +67 -0
- package/cli/contract.mjs +2 -2
- package/cli/demo-build.mjs +23 -0
- package/cli/demo-host.mjs +10 -70
- package/cli/demo-native.mjs +74 -0
- package/cli/lifecycle.mjs +1 -1
- package/cli/main.mjs +1 -0
- package/cli/parse.mjs +1 -1
- package/cli/release.mjs +5 -2
- package/global/CHANGELOG.md +30 -0
- package/global/README.md +16 -0
- package/global/main.mjs +3 -0
- package/modules/container/README.md +2 -15
- package/modules/container/host.mjs +1 -3
- package/modules/container/ingress.mjs +1 -15
- package/modules/container/worker-engine.mjs +2 -3
- package/modules/demo-host/README.md +23 -156
- package/modules/demo-host/build.mjs +49 -0
- package/modules/demo-host/capacity.mjs +8 -2
- package/modules/demo-host/claim.mjs +2 -2
- package/modules/demo-host/diagnostics.mjs +1 -18
- package/modules/demo-host/native/alarms.mjs +51 -0
- package/modules/demo-host/native/bindings.mjs +24 -0
- package/modules/demo-host/native/bridge.mjs +17 -0
- package/modules/demo-host/native/config.mjs +35 -0
- package/modules/demo-host/native/cron.mjs +31 -0
- package/modules/demo-host/native/d1.mjs +37 -0
- package/modules/demo-host/native/deploy-r2.mjs +43 -0
- package/modules/demo-host/native/isolate.mjs +36 -0
- package/modules/demo-host/native/loader.mjs +30 -0
- package/modules/demo-host/native/namespace.mjs +35 -0
- package/modules/demo-host/native/prepare.mjs +35 -0
- package/modules/demo-host/native/queues.mjs +62 -0
- package/modules/demo-host/native/r2-client.mjs +37 -0
- package/modules/demo-host/native/r2.mjs +43 -0
- package/modules/demo-host/native/resources.mjs +37 -0
- package/modules/demo-host/native/seed-object.mjs +22 -0
- package/modules/demo-host/native/sql.mjs +17 -0
- package/modules/demo-host/native/visitor.mjs +147 -0
- package/modules/demo-host/native/worker.mjs +22 -0
- package/modules/demo-host/pages.mjs +1 -1
- package/modules/demo-host/plan.mjs +9 -30
- package/modules/demo-host/remove.mjs +13 -23
- package/modules/demo-host/upgrade.mjs +41 -0
- package/modules/demo-host/worker.mjs +3 -4
- package/modules/owner-claim/verify.d.mts +5 -0
- package/modules/release/README.md +11 -1
- package/modules/release/github-verify.mjs +30 -26
- package/modules/release/produce.mjs +2 -2
- package/modules/release/source-verification.mjs +2 -2
- package/modules/release/verify-workflow.mjs +23 -0
- package/package.json +1 -1
- package/modules/demo-host/container.mjs +0 -221
- package/modules/demo-host/entrypoint.sh +0 -9
- package/modules/demo-host/image.mjs +0 -18
- package/modules/demo-host/placement.mjs +0 -37
- package/modules/demo-host/prepare.mjs +0 -28
- package/modules/demo-host/startup.mjs +0 -27
- package/modules/demo-host/template.mjs +0 -71
|
@@ -1,35 +1,25 @@
|
|
|
1
|
+
import { ownedBucket, removeBucket } from './native/deploy-r2.mjs';
|
|
1
2
|
import { assert } from '../deploy-kit/validation.mjs';
|
|
2
3
|
import { workerSettings } from '../deploy-kit/owner.mjs';
|
|
3
4
|
import { servedVersion } from '../deploy-kit/site.mjs';
|
|
4
5
|
import { deleteWorker } from '../deploy-kit/teardown.mjs';
|
|
5
6
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
* deploy made: the front Worker (its Durable Object namespaces go with it), the
|
|
9
|
-
* Workers Custom Domains on the primary demo hostname and declared descendants
|
|
10
|
-
* (Cloudflare adds and removes their DNS records with them), and the Container application `wrangler deploy` created for
|
|
11
|
-
* the Worker's DemoContainer namespace. It makes no D1, KV, R2, queue or DNS
|
|
12
|
-
* record of its own: the domain's record is Cloudflare's, and goes with it.
|
|
13
|
-
*
|
|
14
|
-
* The Worker is the demo's own only while it serves the version carrying the
|
|
15
|
-
* demo's record (plan.mjs `demoRecord`). The domain is the demo's only while it
|
|
16
|
-
* routes to that Worker, the Container application only while it belongs to
|
|
17
|
-
* that Worker's DemoContainer namespace. Anything else of those names, or
|
|
18
|
-
* attached to that Worker, is refused before the first delete. The Worker goes
|
|
19
|
-
* last, so a run cut short leaves the record for the next one; once everything
|
|
20
|
-
* is gone a second run is a no-op. */
|
|
7
|
+
// Exact-id teardown and ownership inventory, shared by native upgrades.
|
|
8
|
+
// The Worker is deleted last so interrupted removal retains its ownership record.
|
|
21
9
|
|
|
22
10
|
function refuse(code, resource) { const error = new Error(code); error.resource = resource; return error; }
|
|
23
11
|
const rows = value => { assert(Array.isArray(value), 'provider-invalid-list'); return value; };
|
|
24
12
|
|
|
25
13
|
/** What exists of the demo now, each with its exact id; refuses whatever is not provably the demo's. */
|
|
26
|
-
async function
|
|
14
|
+
export async function demoInventory(api, plan) {
|
|
27
15
|
const named = (await Promise.all(plan.hostnames.map(async hostname =>
|
|
28
16
|
rows(await api.request(`/workers/domains?hostname=${hostname}`)).filter(row => row?.hostname === hostname)))).flat();
|
|
29
17
|
const attached = rows(await api.request(`/workers/domains?service=${plan.worker}`)).filter(row => row?.service === plan.worker);
|
|
30
|
-
const apps = rows(await api.request('/containers/applications')).filter(row => row?.name === plan.container);
|
|
31
18
|
const namespaces = rows(await api.list('/workers/durable_objects/namespaces')).filter(row => row?.script === plan.worker);
|
|
32
|
-
const
|
|
19
|
+
const settings = await workerSettings(api, plan.worker);
|
|
20
|
+
const worker = settings !== null;
|
|
21
|
+
const container = namespaces.find(row => row.class === 'DemoContainer')?.id;
|
|
22
|
+
const apps = container ? rows(await api.request('/containers/applications')).filter(row => row?.name === plan.container || row?.durable_objects?.namespace_id === container) : [];
|
|
33
23
|
for (const row of named) if (row.service !== plan.worker) throw refuse('resource-name-collision', `domain:${row.hostname}`);
|
|
34
24
|
if (worker) {
|
|
35
25
|
const served = await servedVersion(api, plan.worker);
|
|
@@ -40,13 +30,12 @@ async function inventory(api, plan) {
|
|
|
40
30
|
// Without the Worker nothing proves these are the demo's.
|
|
41
31
|
throw refuse('uncertain-resource-create', named[0] || attached[0] ? `domain:${(named[0] ?? attached[0]).hostname}` : `container:${plan.container}`);
|
|
42
32
|
}
|
|
43
|
-
const
|
|
44
|
-
|
|
45
|
-
return { worker, domains: named, apps };
|
|
33
|
+
for (const app of apps) if (app.name !== plan.container || !container || app.durable_objects?.namespace_id !== container) throw refuse('resource-name-collision', `container:${plan.container}`);
|
|
34
|
+
return { worker, settings, namespaces, domains: named, apps, bucket: worker ? await ownedBucket(api, plan, settings) : null };
|
|
46
35
|
}
|
|
47
36
|
|
|
48
37
|
export async function demoRemove({ api, plan, sleep }) {
|
|
49
|
-
const found = await
|
|
38
|
+
const found = await demoInventory(api, plan);
|
|
50
39
|
if (!found.worker) return { worker: plan.worker, removed: [], remaining: [], alreadyRemoved: true };
|
|
51
40
|
const removed = [];
|
|
52
41
|
for (const domain of found.domains) {
|
|
@@ -54,6 +43,7 @@ export async function demoRemove({ api, plan, sleep }) {
|
|
|
54
43
|
removed.push(`domain:${domain.hostname}`);
|
|
55
44
|
}
|
|
56
45
|
for (const app of found.apps) { await api.request(`/containers/applications/${app.id}`, { method: 'DELETE' }); removed.push(`container:${plan.container}`); }
|
|
46
|
+
if (found.bucket) { await removeBucket(api, found.bucket); removed.push(`r2:${found.bucket.name}`); }
|
|
57
47
|
await deleteWorker({ api, worker: plan.worker, ...sleep ? { sleep } : {} });
|
|
58
48
|
removed.push(`worker:${plan.worker}`);
|
|
59
49
|
// Read back: nothing of the demo is listed any more.
|
|
@@ -62,7 +52,7 @@ export async function demoRemove({ api, plan, sleep }) {
|
|
|
62
52
|
for (const row of rows(await api.list('/workers/durable_objects/namespaces'))) if (row?.script === plan.worker) remaining.push(`durable-object:${row.class}`);
|
|
63
53
|
const domains = await Promise.all(plan.hostnames.map(async hostname => ({ hostname, rows: rows(await api.request(`/workers/domains?hostname=${hostname}`)) })));
|
|
64
54
|
for (const { hostname, rows: listed } of domains) if (listed.some(row => row?.hostname === hostname)) remaining.push(`domain:${hostname}`);
|
|
65
|
-
const apps = rows(await api.request('/containers/applications'));
|
|
55
|
+
const apps = found.apps.length ? rows(await api.request('/containers/applications')) : [];
|
|
66
56
|
for (const app of found.apps) if (apps.some(row => row?.id === app.id)) remaining.push(`container:${plan.container}`);
|
|
67
57
|
if (remaining.length) { const error = new Error('remove-incomplete'); error.remaining = remaining; error.removed = removed.filter(item => !remaining.includes(item)); throw error; }
|
|
68
58
|
return { worker: plan.worker, removed, remaining: [] };
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { demoInventory } from './remove.mjs';
|
|
2
|
+
|
|
3
|
+
// Keep the Worker and custom domains throughout the transition. Container apps
|
|
4
|
+
// must go before deleting their backing class; Wrangler then applies the class
|
|
5
|
+
// migration atomically with the native code. A failed upload can be rerun.
|
|
6
|
+
export async function upgradeDemo({ api, plan }) {
|
|
7
|
+
const found = await demoInventory(api, plan);
|
|
8
|
+
const classes = found.namespaces.map(row => row.class);
|
|
9
|
+
const unknown = classes.filter(name => !['DemoContainer', 'NativeDemo', 'DemoCapacity'].includes(name));
|
|
10
|
+
if (unknown.length) throw new Error('demo-upgrade-unknown-class');
|
|
11
|
+
const service = found.worker ? await api.request(`/workers/services/${plan.worker}`) : null;
|
|
12
|
+
const tag = service?.default_environment?.script?.migration_tag;
|
|
13
|
+
if (found.worker && classes.length && !tag) throw new Error('demo-upgrade-missing-migration-tag');
|
|
14
|
+
const migration = { tag: 'native-v2' };
|
|
15
|
+
const added = ['NativeDemo', 'DemoCapacity'].filter(name => !classes.includes(name));
|
|
16
|
+
if (added.length) migration.new_sqlite_classes = added;
|
|
17
|
+
if (classes.includes('DemoContainer')) migration.deleted_classes = ['DemoContainer'];
|
|
18
|
+
if (tag === migration.tag && (added.length || migration.deleted_classes)) throw new Error('demo-upgrade-inconsistent-migration');
|
|
19
|
+
for (const app of found.apps) await api.request(`/containers/applications/${app.id}`, { method: 'DELETE' });
|
|
20
|
+
if (found.apps.length) {
|
|
21
|
+
const remaining = await api.request('/containers/applications');
|
|
22
|
+
if (remaining.some(row => found.apps.some(app => app.id === row.id))) throw new Error('demo-upgrade-container-remove-incomplete');
|
|
23
|
+
}
|
|
24
|
+
if (classes.includes('DemoContainer')) {
|
|
25
|
+
// The API checks the currently deployed bindings before class deletion.
|
|
26
|
+
// Detach the retired binding first; inherit every other value by name,
|
|
27
|
+
// including secrets, and retain the ownership annotation for a rerun.
|
|
28
|
+
const body = new FormData();
|
|
29
|
+
body.set('settings', new Blob([JSON.stringify({
|
|
30
|
+
annotations: { 'workers/message': plan.record },
|
|
31
|
+
bindings: found.settings.bindings.filter(binding => !(binding.type === 'durable_object_namespace' && binding.class_name === 'DemoContainer'))
|
|
32
|
+
.map(binding => ({ name: binding.name, type: 'inherit' })),
|
|
33
|
+
})], { type: 'application/json' }));
|
|
34
|
+
await api.request(`/workers/scripts/${plan.worker}/settings`, { method: 'PATCH', body });
|
|
35
|
+
}
|
|
36
|
+
// Wrangler validates the full declared history locally, even though only
|
|
37
|
+
// steps after the deployed tag are sent. Describe the existing classes in
|
|
38
|
+
// that historical step so a deletion resolves without shipping old code.
|
|
39
|
+
if (tag === migration.tag) return [{ tag, new_sqlite_classes: classes }];
|
|
40
|
+
return tag ? [{ tag, new_sqlite_classes: classes }, migration] : [migration];
|
|
41
|
+
}
|
|
@@ -1,16 +1,15 @@
|
|
|
1
1
|
// A seed's hosted demo at demo.<domain>, generated by `rer deploy --demo`.
|
|
2
2
|
// GET / shows the start page (a Turnstile managed widget that starts the demo by itself).
|
|
3
3
|
// POST /__demo/start checks the visitor's IP rate limit, Turnstile and capacity,
|
|
4
|
-
// then starts a
|
|
4
|
+
// then starts a native isolate of their own, signs its owner in and sets the
|
|
5
5
|
// rer_demo cookie. The page's script asks for JSON (Accept: application/json) to
|
|
6
6
|
// show its progress and failures; a plain form post gets the 303 or the page. Every request with that cookie goes to the visitor's
|
|
7
|
-
//
|
|
7
|
+
// isolate; nothing else on this host is reachable.
|
|
8
8
|
import { operatorPage } from './operator.mjs';
|
|
9
9
|
import { measured, testHost } from './measurement.mjs';
|
|
10
10
|
import { bounded, category, report } from './diagnostics.mjs';
|
|
11
11
|
import { startPage, demoCookie, clearCookie } from './pages.mjs';
|
|
12
12
|
|
|
13
|
-
export { DemoContainer } from './container.mjs';
|
|
14
13
|
export { DemoCapacity } from './capacity.mjs';
|
|
15
14
|
|
|
16
15
|
const HOUR = 60 * 60_000;
|
|
@@ -106,7 +105,7 @@ async function start(request, env, ctx) {
|
|
|
106
105
|
// Who holds the place: automated browsers pass Turnstile's testing keys.
|
|
107
106
|
report(correlation, started, 'admitted', { agent: (request.headers.get('user-agent') ?? '').slice(0, 160), network: request.cf?.asOrganization ?? null });
|
|
108
107
|
demo = env.DEMO.get(id);
|
|
109
|
-
const begun = demo.begin({ correlation, origin: env.DEMO_ORIGIN, originVar: env.DEMO_ORIGIN_VAR, ends, endsLocal: localTime(ends, request.cf?.timezone), settings: JSON.parse(env.DEMO_SETTINGS) });
|
|
108
|
+
const begun = demo.begin({ correlation, clientIp: ip, origin: env.DEMO_ORIGIN, originVar: env.DEMO_ORIGIN_VAR, ends, endsLocal: localTime(ends, request.cf?.timezone), settings: JSON.parse(env.DEMO_SETTINGS) });
|
|
110
109
|
// A new object can take seconds to answer. That is a slow start, not a
|
|
111
110
|
// failed one: the page polls this copy, and a begin that later fails ends
|
|
112
111
|
// it and releases its place.
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { OwnerClaimConfig } from './index.mjs';
|
|
2
|
+
|
|
3
|
+
export type { OwnerClaim, OwnerClaimConfig } from './index.mjs';
|
|
4
|
+
export { OwnerClaimError, verifyOwnerClaim } from './index.mjs';
|
|
5
|
+
export function configureClaim(input: OwnerClaimConfig): Readonly<OwnerClaimConfig>;
|
|
@@ -56,9 +56,19 @@ it is independent of the publication destination. Only a completed successful
|
|
|
56
56
|
tag qualifies. The run and head repository must both match the source repository,
|
|
57
57
|
and a release tag must resolve remotely to the exact source commit. PR merge runs,
|
|
58
58
|
other SHAs, repositories, branches and unsuccessful runs cannot authorize release.
|
|
59
|
-
`gates.verify` records the source repository and commit,
|
|
59
|
+
`gates.verify` records the source repository and commit, `workflowId`,
|
|
60
|
+
`workflowFile`, `workflowName`, `runId`,
|
|
60
61
|
`runUrl`, event, branch and conclusion in both receipt and site provenance.
|
|
61
62
|
|
|
63
|
+
Workflow selection uses `--verify-workflow NAME_OR_FILE` first, then the
|
|
64
|
+
optional top-level `verifyWorkflow` from committed `rer-project.json`, then
|
|
65
|
+
`.github/workflows/verify.yml` or `verify.yaml`, then a single workflow named
|
|
66
|
+
`verify`. Names, full file paths and basenames match case-insensitively. For
|
|
67
|
+
example, `"verifyWorkflow": "Verify Slate"` or
|
|
68
|
+
`--verify-workflow .github/workflows/candidate.yml` selects a seed's own gate.
|
|
69
|
+
An explicit selection that is missing or ambiguous blocks; multiple conventional
|
|
70
|
+
files or matching names also block, naming the candidates and the flag.
|
|
71
|
+
|
|
62
72
|
CI is the verification wall: this path skips both local `verify` targets. It
|
|
63
73
|
still installs frozen dependencies and runs the committed `pnpm run build`
|
|
64
74
|
script, when declared, in a disposable clone. `gates.verify.install` and
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { execFileSync } from 'node:child_process';
|
|
2
2
|
import { git } from './source.mjs';
|
|
3
|
+
import { verifyWorkflow } from './verify-workflow.mjs';
|
|
3
4
|
|
|
4
5
|
const same = (left, right) => typeof left === 'string' && left.toLowerCase() === right.toLowerCase();
|
|
5
6
|
function identity(value) {
|
|
@@ -39,7 +40,7 @@ function tagCommit(repository, tag) {
|
|
|
39
40
|
return object?.type === 'commit' ? object.sha : null;
|
|
40
41
|
}
|
|
41
42
|
|
|
42
|
-
export function githubVerify(source, repository) {
|
|
43
|
+
export function githubVerify(source, repository, selector) {
|
|
43
44
|
const result = { status: 'FAIL', provider: 'github', repository, commit: source.commit,
|
|
44
45
|
reason: 'github-verify-not-successful',
|
|
45
46
|
message: `No successful Verify run exists for ${repository} at exact source commit ${source.commit}. Push this commit to the default branch or release tag, or re-run Verify for this SHA with workflow_dispatch. Use --local-verify to run verification locally.` };
|
|
@@ -47,35 +48,38 @@ export function githubVerify(source, repository) {
|
|
|
47
48
|
const metadata = api(`repos/${repository}`);
|
|
48
49
|
if (!same(metadata.full_name, repository) || typeof metadata.default_branch !== 'string' || !metadata.default_branch) throw Error('repository');
|
|
49
50
|
const workflows = api(`repos/${repository}/actions/workflows?per_page=100`, true)
|
|
50
|
-
.flatMap(page => page.workflows).filter(workflow =>
|
|
51
|
+
.flatMap(page => page.workflows).filter(workflow => Number.isSafeInteger(workflow.id));
|
|
52
|
+
const selected = verifyWorkflow(source, workflows, selector);
|
|
53
|
+
if (selected.error) return { ...result, details: selected.error };
|
|
54
|
+
const workflow = selected.workflow;
|
|
55
|
+
Object.assign(result, { workflowId: workflow.id, workflowFile: workflow.path, workflowName: workflow.name });
|
|
51
56
|
const rejected = new Set();
|
|
52
57
|
let checkedTag = false, tagSHA;
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
rejected.add('different source repository'); continue;
|
|
60
|
-
}
|
|
61
|
-
if (run.workflow_id !== workflow.id) { rejected.add('different workflow'); continue; }
|
|
62
|
-
if (!['push', 'workflow_dispatch'].includes(run.event)) { rejected.add('event must be push or workflow_dispatch'); continue; }
|
|
63
|
-
if (run.status !== 'completed' || run.conclusion !== 'success') {
|
|
64
|
-
rejected.add(run.status === 'completed' ? `conclusion ${['failure', 'cancelled', 'skipped', 'timed_out', 'neutral', 'action_required', 'stale'].includes(run.conclusion) ? run.conclusion : 'not success'}` : 'run not completed');
|
|
65
|
-
continue;
|
|
66
|
-
}
|
|
67
|
-
if (run.head_branch !== metadata.default_branch) {
|
|
68
|
-
if (run.head_branch !== source.tag) { rejected.add('neither default branch nor release tag'); continue; }
|
|
69
|
-
if (!checkedTag) { tagSHA = tagCommit(repository, source.tag); checkedTag = true; }
|
|
70
|
-
if (tagSHA !== source.commit) { rejected.add('release tag points at a different commit'); continue; }
|
|
71
|
-
}
|
|
72
|
-
if (!Number.isSafeInteger(run.id) || run.id <= 0) throw Error('run');
|
|
73
|
-
return { status: 'PASS', provider: 'github', repository: metadata.full_name, commit: source.commit,
|
|
74
|
-
workflowId: workflow.id, runId: run.id, runUrl: `https://github.com/${metadata.full_name}/actions/runs/${run.id}`,
|
|
75
|
-
event: run.event, branch: run.head_branch, conclusion: run.conclusion };
|
|
58
|
+
const runs = api(`repos/${repository}/actions/workflows/${workflow.id}/runs?head_sha=${source.commit}&per_page=100`, true)
|
|
59
|
+
.flatMap(page => page.workflow_runs);
|
|
60
|
+
for (const run of runs) {
|
|
61
|
+
if (run.head_sha !== source.commit) { rejected.add('different source SHA'); continue; }
|
|
62
|
+
if (!same(run.repository?.full_name, repository) || !same(run.head_repository?.full_name, repository)) {
|
|
63
|
+
rejected.add('different source repository'); continue;
|
|
76
64
|
}
|
|
65
|
+
if (run.workflow_id !== workflow.id) { rejected.add('different workflow'); continue; }
|
|
66
|
+
if (!['push', 'workflow_dispatch'].includes(run.event)) { rejected.add('event must be push or workflow_dispatch'); continue; }
|
|
67
|
+
if (run.status !== 'completed' || run.conclusion !== 'success') {
|
|
68
|
+
rejected.add(run.status === 'completed' ? `conclusion ${['failure', 'cancelled', 'skipped', 'timed_out', 'neutral', 'action_required', 'stale'].includes(run.conclusion) ? run.conclusion : 'not success'}` : 'run not completed');
|
|
69
|
+
continue;
|
|
70
|
+
}
|
|
71
|
+
if (run.head_branch !== metadata.default_branch) {
|
|
72
|
+
if (run.head_branch !== source.tag) { rejected.add('neither default branch nor release tag'); continue; }
|
|
73
|
+
if (!checkedTag) { tagSHA = tagCommit(repository, source.tag); checkedTag = true; }
|
|
74
|
+
if (tagSHA !== source.commit) { rejected.add('release tag points at a different commit'); continue; }
|
|
75
|
+
}
|
|
76
|
+
if (!Number.isSafeInteger(run.id) || run.id <= 0) throw Error('run');
|
|
77
|
+
return { status: 'PASS', provider: 'github', repository: metadata.full_name, commit: source.commit,
|
|
78
|
+
workflowId: workflow.id, workflowFile: workflow.path, workflowName: workflow.name,
|
|
79
|
+
runId: run.id, runUrl: `https://github.com/${metadata.full_name}/actions/runs/${run.id}`,
|
|
80
|
+
event: run.event, branch: run.head_branch, conclusion: run.conclusion };
|
|
77
81
|
}
|
|
78
|
-
result.details =
|
|
82
|
+
result.details = rejected.size ? [...rejected].join('; ') : 'No runs found for this SHA.';
|
|
79
83
|
} catch {
|
|
80
84
|
result.reason = 'github-verify-unavailable';
|
|
81
85
|
result.details = 'GitHub Verify could not be resolved. Check gh authentication and repository access, then try again; no local verification was substituted.';
|
|
@@ -14,7 +14,7 @@ import { placeholderMarks, placeholderMessage } from '../../cli/placeholder-mark
|
|
|
14
14
|
// Failure output belongs to the private receipt, not the site preview.
|
|
15
15
|
const withoutOutput = gates => JSON.parse(JSON.stringify(gates, (key, value) => key === 'output' ? undefined : value));
|
|
16
16
|
|
|
17
|
-
export async function release({ repo, ref = 'HEAD', output, project, repository, dryRun = false, tag = false, cleanHistory: clean = false, envFile, onto, publicBase, localVerify = false, allowPlaceholderMark = false }) {
|
|
17
|
+
export async function release({ repo, ref = 'HEAD', output, project, repository, dryRun = false, tag = false, cleanHistory: clean = false, envFile, onto, publicBase, localVerify = false, allowPlaceholderMark = false, verifyWorkflow }) {
|
|
18
18
|
if (!/^[\w.-]+\/[\w.-]+$/.test(project ?? '')) throw Error('--project must be publisher/name');
|
|
19
19
|
if (!/^https:\/\/github\.com\/[\w.-]+\/[\w.-]+(?:\.git)?$/i.test(repository ?? '')) throw Error('--repository must be a credential-free GitHub repository URL');
|
|
20
20
|
if (onto !== undefined && clean) throw Error('--onto and --clean-history are mutually exclusive');
|
|
@@ -47,7 +47,7 @@ export async function release({ repo, ref = 'HEAD', output, project, repository,
|
|
|
47
47
|
const checkout = resolve(temporary, 'seed');
|
|
48
48
|
git(source.repo, 'clone', '--no-hardlinks', '--no-checkout', '--', source.repo, checkout);
|
|
49
49
|
git(checkout, 'checkout', '--detach', source.commit);
|
|
50
|
-
const verify = await verifySource(source, checkout, localVerify);
|
|
50
|
+
const verify = await verifySource(source, checkout, localVerify, verifyWorkflow);
|
|
51
51
|
// Explicit clean-history publication scans every byte and ref of the actual
|
|
52
52
|
// parentless export. Exact-source releases classify against public history
|
|
53
53
|
// when available, retaining the selected source commit and tag identity.
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { command, git } from './source.mjs';
|
|
2
2
|
import { githubSource, githubVerify } from './github-verify.mjs';
|
|
3
3
|
|
|
4
|
-
export async function verifySource(source, checkout, localVerify) {
|
|
4
|
+
export async function verifySource(source, checkout, localVerify, verifyWorkflow) {
|
|
5
5
|
const repository = localVerify ? null : githubSource(source);
|
|
6
|
-
const verify = repository ? githubVerify(source, repository) : null;
|
|
6
|
+
const verify = repository ? githubVerify(source, repository, verifyWorkflow) : null;
|
|
7
7
|
// Refuse missing CI evidence before spending time installing or building.
|
|
8
8
|
if (verify?.status === 'FAIL') return verify;
|
|
9
9
|
const install = await command('pnpm', ['install', '--frozen-lockfile'], checkout, { dependencies: true });
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
const same = (left, right) => typeof left === 'string' && left.toLowerCase() === right.toLowerCase();
|
|
2
|
+
const filename = path => typeof path === 'string' ? path.split('/').at(-1) : undefined;
|
|
3
|
+
const describe = workflow => `${workflow.name} (${workflow.path ?? 'file unknown'})`;
|
|
4
|
+
|
|
5
|
+
// A selector is authoritative: a typo must never silently choose another gate.
|
|
6
|
+
export function verifyWorkflow(source, workflows, override) {
|
|
7
|
+
const declared = override === undefined && source.entries.has('rer-project.json')
|
|
8
|
+
? JSON.parse(source.bytes('rer-project.json')).verifyWorkflow : undefined;
|
|
9
|
+
const selector = override ?? declared;
|
|
10
|
+
let matches;
|
|
11
|
+
if (selector !== undefined) {
|
|
12
|
+
if (typeof selector !== 'string' || !selector.trim()) {
|
|
13
|
+
return { error: 'verifyWorkflow must be a nonempty workflow name or file; use --verify-workflow <name|file>.' };
|
|
14
|
+
}
|
|
15
|
+
matches = workflows.filter(workflow => same(workflow.name, selector) || same(workflow.path, selector) || same(filename(workflow.path), selector));
|
|
16
|
+
} else {
|
|
17
|
+
matches = workflows.filter(workflow => ['.github/workflows/verify.yml', '.github/workflows/verify.yaml'].some(path => same(workflow.path, path)));
|
|
18
|
+
if (!matches.length) matches = workflows.filter(workflow => same(workflow.name, 'verify'));
|
|
19
|
+
}
|
|
20
|
+
if (matches.length === 1) return { workflow: matches[0] };
|
|
21
|
+
if (matches.length > 1) return { error: `Ambiguous Verify workflows: ${matches.map(describe).join('; ')}. Select one with --verify-workflow <name|file>.` };
|
|
22
|
+
return { error: `${selector === undefined ? 'No Verify workflow found' : `No Verify workflow matches ${JSON.stringify(selector)}`}. Select a workflow with --verify-workflow <name|file>.` };
|
|
23
|
+
}
|
package/package.json
CHANGED
|
@@ -1,221 +0,0 @@
|
|
|
1
|
-
import { DurableObject } from 'cloudflare:workers';
|
|
2
|
-
import { claimKeys, signClaim } from './claim.mjs';
|
|
3
|
-
import { bounded, boundedFetch, category, report } from './diagnostics.mjs';
|
|
4
|
-
import { endedPage, clearCookie } from './pages.mjs';
|
|
5
|
-
import { finishStart } from './startup.mjs';
|
|
6
|
-
import { placeContainer } from './placement.mjs';
|
|
7
|
-
import { fingerprint } from './capacity.mjs';
|
|
8
|
-
|
|
9
|
-
// One visitor's demo: a Durable Object (newUniqueId) and its container, the
|
|
10
|
-
// seed's image from `rer build --platform container` on the workerd engine.
|
|
11
|
-
// The container starts with public internet in demo mode. withDemo simulates
|
|
12
|
-
// external effects; the engine also refuses direct mail/SMS transports. The
|
|
13
|
-
// front signs the owner in through the existing signed owner claim. The demo ends at its hour or after
|
|
14
|
-
// 15 idle minutes: the alarm destroys the container and deletes everything.
|
|
15
|
-
// Container lifetime is independent of the object's JS lifetime. Configure the
|
|
16
|
-
// platform's inactivity grace on every object instance; persisted alarms and
|
|
17
|
-
// request-time checks enforce the visitor's exact idle and absolute deadlines.
|
|
18
|
-
const PORT = 8080, IDLE = 15 * 60_000, OWNER = 'owner@demo.invalid';
|
|
19
|
-
// The container's port speaks plain HTTP; the app takes its public origin from RER_INGRESS_ORIGIN.
|
|
20
|
-
const inside = url => `http://container${url.pathname}${url.search}`;
|
|
21
|
-
const random = () => [...crypto.getRandomValues(new Uint8Array(32))].map(byte => byte.toString(16).padStart(2, '0')).join('');
|
|
22
|
-
|
|
23
|
-
export class DemoContainer extends DurableObject {
|
|
24
|
-
constructor(ctx, env) {
|
|
25
|
-
super(ctx, env);
|
|
26
|
-
ctx.blockConcurrencyWhile(async () => {
|
|
27
|
-
const state = await ctx.storage.get(['correlation', 'started', 'startup']);
|
|
28
|
-
this.correlation = state.get('correlation'); this.started = state.get('started');
|
|
29
|
-
if (state.get('startup')?.phase === 'starting') {
|
|
30
|
-
// An interrupted start has lost its private claim key and cannot be
|
|
31
|
-
// resumed after object eviction. End it instead of polling forever.
|
|
32
|
-
await ctx.storage.put('startup', { phase: 'starting', failure: state.get('startup').failure ?? { phase: 'failed' } });
|
|
33
|
-
ctx.waitUntil(this.end().catch(cause => report(this.correlation, this.started, 'cleanup', { error: category(cause) })));
|
|
34
|
-
} else if (this.container.running) {
|
|
35
|
-
await this.container.setInactivityTimeout(this.idle);
|
|
36
|
-
this.watch();
|
|
37
|
-
}
|
|
38
|
-
});
|
|
39
|
-
}
|
|
40
|
-
watch() {
|
|
41
|
-
if (!this.watching) {
|
|
42
|
-
this.watching = true;
|
|
43
|
-
this.ctx.waitUntil(this.container.monitor().then(() => this.exited(), error => this.exited(error)));
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
records = [];
|
|
47
|
-
record(event, detail = {}) {
|
|
48
|
-
const row = { event, at: new Date().toISOString(), elapsedMs: this.now() - this.started, ...detail };
|
|
49
|
-
this.records.push(row); if (this.records.length > 8) this.records.shift();
|
|
50
|
-
report(this.correlation, this.started, event, detail);
|
|
51
|
-
}
|
|
52
|
-
diagnostic() { return { correlation: this.correlation, tail: this.records, stdout: 'Provider container logs; not exposed by the lifecycle API.' }; }
|
|
53
|
-
idle = IDLE;
|
|
54
|
-
startTimeout = 45_000;
|
|
55
|
-
placementTimeout = 90_000;
|
|
56
|
-
probeTimeout = 5000;
|
|
57
|
-
cleanupRetry = 30_000;
|
|
58
|
-
now() { return Date.now(); }
|
|
59
|
-
get container() { return this.ctx.container; }
|
|
60
|
-
get owner() { return this.env.DEMO_OWNER_EMAIL || OWNER; }
|
|
61
|
-
port() { return this.container.getTcpPort(PORT); }
|
|
62
|
-
|
|
63
|
-
async begin(options) {
|
|
64
|
-
if (!await this.ctx.storage.get('startup')) {
|
|
65
|
-
await this.ctx.storage.put('startup', { phase: 'starting' });
|
|
66
|
-
this.ctx.waitUntil(finishStart(this, options));
|
|
67
|
-
}
|
|
68
|
-
return this.status();
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
/** The start's state; `wait` holds a pending answer until it changes (at most 1.5 s), so the page learns of the sign-in without its own polling delay.
|
|
72
|
-
* A poll can also reach a new copy before its slow begin has landed. */
|
|
73
|
-
async status(wait = 0) {
|
|
74
|
-
const until = Date.now() + Math.min(wait, 1500);
|
|
75
|
-
let startup = await this.ctx.storage.get('startup');
|
|
76
|
-
while ((!startup || (startup.phase === 'starting' && !startup.failure)) && Date.now() < until) {
|
|
77
|
-
await new Promise(resolve => setTimeout(resolve, 100));
|
|
78
|
-
startup = await this.ctx.storage.get('startup');
|
|
79
|
-
}
|
|
80
|
-
return { ...(startup ?? { phase: 'failed' }), correlation: this.correlation };
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
/** Start the container, wait for /health, claim the owner; returns the claim's 303. */
|
|
84
|
-
async start({ origin, originVar, ends, endsLocal, settings, correlation }) {
|
|
85
|
-
this.correlation = correlation; this.started = this.now(); this.stopped = false; this.cancelled = false;
|
|
86
|
-
let deadline = this.started + this.startTimeout;
|
|
87
|
-
const id = this.ctx.id.toString(), keys = await claimKeys(), now = this.now();
|
|
88
|
-
await this.ctx.storage.put({ ends, seen: now, correlation, started: this.started, startDeadline: deadline });
|
|
89
|
-
report(correlation, this.started, 'start');
|
|
90
|
-
if (this.stopped) throw new Error('container-stopped');
|
|
91
|
-
deadline = await placeContainer(this, { enableInternet: true, env: { ...settings, RER_DEMO: '1', [originVar]: origin, RER_INGRESS_ORIGIN: origin, RER_INGRESS_ORIGINS: JSON.stringify([origin, ...JSON.parse(this.env.DEMO_SECONDARY_ORIGINS ?? '[]')]),
|
|
92
|
-
SESSION_SECRET: random(), SETUP_TOKEN: random(), OWNER_EMAIL: this.owner, RER_OWNER_CLAIM_ISSUER: origin, RER_OWNER_CLAIM_INSTALLATION_ID: id,
|
|
93
|
-
RER_OWNER_CLAIM_PUBLIC_KEYS: JSON.stringify(keys.publicKeys), RER_DEMO_EXPIRES: endsLocal } }, deadline);
|
|
94
|
-
await this.container.setInactivityTimeout(this.idle);
|
|
95
|
-
await this.ctx.storage.setAlarm(deadline);
|
|
96
|
-
const token = await signClaim(keys, { origin, installationId: id, email: this.owner, now: this.now() });
|
|
97
|
-
// Hold the place to the demo's end while the owner claim runs; a failed claim releases it in cleanup.
|
|
98
|
-
const held = bounded(this.env.CAPACITY.get(this.env.CAPACITY.idFromName('capacity')).extend(id, ends), 2000).catch(() => false);
|
|
99
|
-
const claimed = await boundedFetch(this.port(), 'http://container/auth/owner-claim', { method: 'POST', redirect: 'manual',
|
|
100
|
-
headers: { origin, 'content-type': 'application/x-www-form-urlencoded' }, body: new URLSearchParams({ token }) }, Math.max(1, Math.min(10_000, deadline - this.now())));
|
|
101
|
-
void claimed.body?.cancel().catch(() => {});
|
|
102
|
-
this.record('claim', { status: claimed.status });
|
|
103
|
-
if (this.stopped) throw new Error('container-stopped');
|
|
104
|
-
if (claimed.status !== 303) throw new Error(`owner claim answered ${claimed.status}`);
|
|
105
|
-
if (!await held) throw new Error('start-reservation-expired');
|
|
106
|
-
await this.ctx.storage.put('seen', this.now());
|
|
107
|
-
await this.ctx.storage.setAlarm(Math.min(ends, this.now() + this.idle));
|
|
108
|
-
return { location: claimed.headers.get('location'), cookies: claimed.headers.getSetCookie() };
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
async healthy(deadline) {
|
|
112
|
-
let attempt = 0;
|
|
113
|
-
while (this.now() < deadline) {
|
|
114
|
-
if (this.stopped) throw new Error('container-stopped');
|
|
115
|
-
const probe = this.now();
|
|
116
|
-
try {
|
|
117
|
-
const response = await boundedFetch(this.port(), 'http://container/health', {}, Math.min(this.probeTimeout, deadline - this.now()));
|
|
118
|
-
void response.body?.cancel().catch(() => {});
|
|
119
|
-
this.record('health', { attempt: ++attempt, durationMs: this.now() - probe, status: response.status });
|
|
120
|
-
if (response.ok && !this.stopped) return;
|
|
121
|
-
} catch (error) {
|
|
122
|
-
this.record('health', { attempt: ++attempt, durationMs: this.now() - probe, error: category(error) });
|
|
123
|
-
}
|
|
124
|
-
await new Promise(resolve => setTimeout(resolve, Math.min(100, Math.max(0, deadline - this.now()))));
|
|
125
|
-
}
|
|
126
|
-
throw new Error('health-deadline');
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
async exited(error) {
|
|
130
|
-
this.watching = false;
|
|
131
|
-
this.stopReason = error ? category(error) : 'container-stopped';
|
|
132
|
-
this.stopped = true;
|
|
133
|
-
this.record('exit', { outcome: error ? category(error) : 'exited', ...(Number.isInteger(error?.exitCode) ? { exitCode: error.exitCode } : {}) });
|
|
134
|
-
if ((await this.ctx.storage.get('startup'))?.phase === 'starting') return;
|
|
135
|
-
try { await this.end(); } catch (cause) { report(this.correlation, this.started, 'cleanup', { error: category(cause) }); }
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
/** Every request carrying this demo's cookie: proxied while the demo lives, else the ended page. */
|
|
139
|
-
async fetch(request) {
|
|
140
|
-
const state = await this.ctx.storage.get(['ends', 'seen']), now = this.now();
|
|
141
|
-
if (!state.get('ends') || now >= Math.min(state.get('ends'), state.get('seen') + this.idle)) {
|
|
142
|
-
try { await this.end(); }
|
|
143
|
-
catch (cause) { report(this.correlation, this.started, 'cleanup', { error: category(cause) }); }
|
|
144
|
-
return this.ended();
|
|
145
|
-
}
|
|
146
|
-
if (!this.container.running) return this.gone();
|
|
147
|
-
await this.ctx.storage.put('seen', now);
|
|
148
|
-
await this.ctx.storage.setAlarm(Math.min(state.get('ends'), now + this.idle));
|
|
149
|
-
const forwarded = new Request(inside(new URL(request.url)), request);
|
|
150
|
-
// The front admits only declared hosts. Never let a visitor choose the
|
|
151
|
-
// container's public origin through a transport header.
|
|
152
|
-
forwarded.headers.set('x-rer-ingress-origin', new URL(request.url).origin);
|
|
153
|
-
try { return await this.port().fetch(forwarded); }
|
|
154
|
-
catch (error) { if (this.container.running && !this.stopped) throw error; return this.gone(); }
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
ended() { return endedPage(this.env, { status: 410, headers: { 'set-cookie': clearCookie(this.env) } }); }
|
|
158
|
-
|
|
159
|
-
/** A container the platform stopped while nothing watched it: end the demo (the alarm retries a failed cleanup). */
|
|
160
|
-
async gone() {
|
|
161
|
-
this.record('exit', { outcome: 'gone' });
|
|
162
|
-
try { await this.end(); } catch (cause) { report(this.correlation, this.started, 'cleanup', { error: category(cause) }); }
|
|
163
|
-
return this.ended();
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
async alarm() {
|
|
167
|
-
const state = await this.ctx.storage.get(['ends', 'seen', 'startDeadline']), now = this.now();
|
|
168
|
-
if (await this.ctx.storage.get('stopping')) return this.end();
|
|
169
|
-
if (!state.get('ends')) return this.ctx.storage.deleteAll();
|
|
170
|
-
const due = Math.min(state.get('ends'), state.get('seen') + this.idle, state.get('startDeadline') ?? Infinity);
|
|
171
|
-
if (now >= due || !this.container.running) {
|
|
172
|
-
if ((await this.ctx.storage.get('startup'))?.phase === 'starting') { this.stopped = true; return; }
|
|
173
|
-
return this.end();
|
|
174
|
-
}
|
|
175
|
-
await this.ctx.storage.setAlarm(due);
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
/** Destroy the container and delete this demo's state and place; safe to repeat. */
|
|
179
|
-
async end() {
|
|
180
|
-
if (this.ending) return this.ending;
|
|
181
|
-
this.ending = this.cleanup();
|
|
182
|
-
try { await this.ending; } finally { this.ending = null; }
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
async cleanup() {
|
|
186
|
-
this.cancelled = true; this.stopped = true;
|
|
187
|
-
const startup = await this.ctx.storage.get('startup');
|
|
188
|
-
const failure = startup?.failure ?? (startup?.phase === 'failed' ? startup : null);
|
|
189
|
-
// A failed start has no live visitor. Release it even if destruction needs
|
|
190
|
-
// another alarm; a live demo keeps its place until destruction succeeds.
|
|
191
|
-
await this.ctx.storage.put('stopping', true);
|
|
192
|
-
await this.ctx.storage.setAlarm(this.now() + this.cleanupRetry);
|
|
193
|
-
if (failure) {
|
|
194
|
-
await this.releasePlace();
|
|
195
|
-
await this.ctx.storage.put('startup', failure);
|
|
196
|
-
}
|
|
197
|
-
if (this.container.running) {
|
|
198
|
-
if (!failure) {
|
|
199
|
-
try { await bounded(this.env.CAPACITY.get(this.env.CAPACITY.idFromName('capacity')).extend(this.ctx.id.toString(), this.now() + 60_000), 2000); }
|
|
200
|
-
catch (cause) { report(this.correlation, this.started, 'cleanup-reservation', { error: category(cause) }); }
|
|
201
|
-
}
|
|
202
|
-
await bounded(this.container.destroy(), 5000);
|
|
203
|
-
}
|
|
204
|
-
if (!failure) await this.releasePlace();
|
|
205
|
-
await this.ctx.storage.deleteAlarm();
|
|
206
|
-
await this.ctx.storage.deleteAll();
|
|
207
|
-
// Retain only the terminal answer briefly, so polling survives a fresh DO.
|
|
208
|
-
if (failure) {
|
|
209
|
-
await this.ctx.storage.put({ startup: failure, correlation: this.correlation, started: this.started });
|
|
210
|
-
await this.ctx.storage.setAlarm(this.now() + 60_000);
|
|
211
|
-
}
|
|
212
|
-
report(this.correlation, this.started, 'ended');
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
async releasePlace() {
|
|
216
|
-
const id = this.ctx.id.toString();
|
|
217
|
-
if (await bounded(this.env.CAPACITY.get(this.env.CAPACITY.idFromName('capacity')).release(id), 2000)) {
|
|
218
|
-
report(this.correlation, this.started, 'released', { releasedId: await fingerprint(id) });
|
|
219
|
-
}
|
|
220
|
-
}
|
|
221
|
-
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
#!/bin/sh
|
|
2
|
-
set -eu
|
|
3
|
-
umask 077
|
|
4
|
-
mkdir -p /data
|
|
5
|
-
# Keep this same lock inode held through template copying and the host lifetime.
|
|
6
|
-
exec flock --nonblock --no-fork /data/host.lock sh -ec '
|
|
7
|
-
node /runtime/modules/demo-host/template.mjs /template /data
|
|
8
|
-
exec node /runtime/modules/container/host.mjs "$@"
|
|
9
|
-
' sh "$@"
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { cp, mkdir, readFile, writeFile } from 'node:fs/promises';
|
|
2
|
-
import { join } from 'node:path';
|
|
3
|
-
|
|
4
|
-
/** Add demo-only preparation to an ordinary workerd image build folder. */
|
|
5
|
-
export async function prepareDemoImage(image) {
|
|
6
|
-
const manifest = JSON.parse(await readFile(join(image, 'app/container.json'), 'utf8'));
|
|
7
|
-
if (manifest.engine !== 'workerd') throw new Error('demo-template-requires-workerd');
|
|
8
|
-
const path = join(image, 'Dockerfile'), dockerfile = await readFile(path, 'utf8');
|
|
9
|
-
const entrypoint = 'ENTRYPOINT ["sh", "/runtime/modules/container/entrypoint.sh"]';
|
|
10
|
-
if (!dockerfile.endsWith(entrypoint + '\n')) throw new Error('demo-image-entrypoint-changed');
|
|
11
|
-
const runtime = join(image, 'runtime/modules/demo-host');
|
|
12
|
-
await mkdir(runtime, { recursive: true });
|
|
13
|
-
for (const file of ['prepare.mjs', 'template.mjs', 'entrypoint.sh']) await cp(new URL(file, import.meta.url), join(runtime, file));
|
|
14
|
-
await writeFile(path, dockerfile.slice(0, -entrypoint.length - 1)
|
|
15
|
-
+ 'RUN --network=none node /runtime/modules/demo-host/prepare.mjs\n'
|
|
16
|
-
+ 'ENTRYPOINT ["sh", "/runtime/modules/demo-host/entrypoint.sh"]\n');
|
|
17
|
-
return { output: image };
|
|
18
|
-
}
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import { bounded } from './diagnostics.mjs';
|
|
2
|
-
|
|
3
|
-
// Cloudflare keeps a small prepared pool per application (7 instances measured
|
|
4
|
-
// on fresh hosts) and prepares more only on demand: a start beyond the pool
|
|
5
|
-
// waits while Cloudflare places a new instance (16-37 s measured), then boots
|
|
6
|
-
// normally. Keep this visitor's reservation through that wait. Only the
|
|
7
|
-
// provider's explicit no-instance response permits another placement attempt,
|
|
8
|
-
// and it renews the boot budget up to placementTimeout from the start; boot,
|
|
9
|
-
// health and claim failures still terminate the start. Returns the deadline the
|
|
10
|
-
// placed container must become healthy and claimed by.
|
|
11
|
-
export async function placeContainer(demo, options, deadline) {
|
|
12
|
-
const limit = demo.started + demo.placementTimeout, capacity = demo.env.CAPACITY.get(demo.env.CAPACITY.idFromName('capacity'));
|
|
13
|
-
let attempt = 0;
|
|
14
|
-
while (Date.now() < deadline && !demo.cancelled) {
|
|
15
|
-
demo.stopped = false;
|
|
16
|
-
demo.stopReason = undefined;
|
|
17
|
-
demo.container.start(options);
|
|
18
|
-
demo.watch();
|
|
19
|
-
await demo.ctx.storage.setAlarm(deadline);
|
|
20
|
-
try {
|
|
21
|
-
await demo.healthy(deadline);
|
|
22
|
-
return deadline;
|
|
23
|
-
} catch (error) {
|
|
24
|
-
if (demo.cancelled || demo.stopReason !== 'placement-unavailable') throw error;
|
|
25
|
-
demo.record('placement', { attempt: ++attempt, outcome: 'waiting' });
|
|
26
|
-
const renewed = Math.min(limit, Date.now() + demo.startTimeout);
|
|
27
|
-
if (renewed > deadline) {
|
|
28
|
-
// The reservation outlives the renewed budget, or the place is no longer this visitor's.
|
|
29
|
-
if (!await bounded(capacity.extend(demo.ctx.id.toString(), renewed + 15_000), 2000)) throw new Error('start-reservation-expired');
|
|
30
|
-
deadline = renewed;
|
|
31
|
-
await demo.ctx.storage.put('startDeadline', deadline);
|
|
32
|
-
}
|
|
33
|
-
await new Promise(resolve => setTimeout(resolve, Math.min(1000, Math.max(0, deadline - Date.now()))));
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
throw new Error(demo.cancelled ? 'container-stopped' : 'placement-unavailable');
|
|
37
|
-
}
|