@volter/world-runtime 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +202 -0
- package/dist/known-external-services.json +1108 -0
- package/dist/src/ancestry.d.ts +2 -0
- package/dist/src/ancestry.js +42 -0
- package/dist/src/app-url.d.ts +47 -0
- package/dist/src/app-url.js +239 -0
- package/dist/src/attach.d.ts +48 -0
- package/dist/src/attach.js +87 -0
- package/dist/src/branch.d.ts +20 -0
- package/dist/src/branch.js +65 -0
- package/dist/src/browser-proxy-cli.d.ts +2 -0
- package/dist/src/browser-proxy-cli.js +41 -0
- package/dist/src/ca-trust.d.ts +5 -0
- package/dist/src/ca-trust.js +64 -0
- package/dist/src/catalog.d.ts +31 -0
- package/dist/src/catalog.js +148 -0
- package/dist/src/changeset.d.ts +142 -0
- package/dist/src/changeset.js +570 -0
- package/dist/src/cli.d.ts +2 -0
- package/dist/src/cli.js +1262 -0
- package/dist/src/command-lifetime.d.ts +15 -0
- package/dist/src/command-lifetime.js +98 -0
- package/dist/src/configs.d.ts +18 -0
- package/dist/src/configs.js +119 -0
- package/dist/src/console-apart.d.ts +38 -0
- package/dist/src/console-apart.js +107 -0
- package/dist/src/consumers.d.ts +46 -0
- package/dist/src/consumers.js +200 -0
- package/dist/src/covers.d.ts +183 -0
- package/dist/src/covers.js +800 -0
- package/dist/src/fixture-env.d.ts +42 -0
- package/dist/src/fixture-env.js +221 -0
- package/dist/src/host-cli.d.ts +2 -0
- package/dist/src/host-cli.js +92 -0
- package/dist/src/host-fault-fixture.d.ts +32 -0
- package/dist/src/host-fault-fixture.js +100 -0
- package/dist/src/host-worker.d.ts +1 -0
- package/dist/src/host-worker.js +23 -0
- package/dist/src/host.d.ts +38 -0
- package/dist/src/host.js +135 -0
- package/dist/src/index.d.ts +48 -0
- package/dist/src/index.js +35 -0
- package/dist/src/infra-cli.d.ts +2 -0
- package/dist/src/infra-cli.js +136 -0
- package/dist/src/init.d.ts +227 -0
- package/dist/src/init.js +1117 -0
- package/dist/src/inject-map.d.ts +34 -0
- package/dist/src/inject-map.js +56 -0
- package/dist/src/lifecycle-record.d.ts +47 -0
- package/dist/src/lifecycle-record.js +196 -0
- package/dist/src/origin.d.ts +31 -0
- package/dist/src/origin.js +139 -0
- package/dist/src/pack-facts.d.ts +75 -0
- package/dist/src/pack-facts.js +98 -0
- package/dist/src/pglite-backing.d.ts +21 -0
- package/dist/src/pglite-backing.js +158 -0
- package/dist/src/pglite-host.mjs +147 -0
- package/dist/src/placeholder.d.ts +20 -0
- package/dist/src/placeholder.js +100 -0
- package/dist/src/prerequisites.d.ts +21 -0
- package/dist/src/prerequisites.js +49 -0
- package/dist/src/process-groups.d.ts +4 -0
- package/dist/src/process-groups.js +49 -0
- package/dist/src/project-inspect.d.ts +109 -0
- package/dist/src/project-inspect.js +827 -0
- package/dist/src/proxy-daemon.d.ts +2 -0
- package/dist/src/proxy-daemon.js +18 -0
- package/dist/src/redirect-proxy.d.ts +105 -0
- package/dist/src/redirect-proxy.js +665 -0
- package/dist/src/reflect.d.ts +74 -0
- package/dist/src/reflect.js +392 -0
- package/dist/src/resources.d.ts +26 -0
- package/dist/src/resources.js +22 -0
- package/dist/src/root.d.ts +114 -0
- package/dist/src/root.js +312 -0
- package/dist/src/run-task-worker.d.ts +1 -0
- package/dist/src/run-task-worker.js +38 -0
- package/dist/src/run-task.d.ts +18 -0
- package/dist/src/run-task.js +48 -0
- package/dist/src/runtime-test-support.d.ts +59 -0
- package/dist/src/runtime-test-support.js +205 -0
- package/dist/src/runtime.d.ts +256 -0
- package/dist/src/runtime.js +3502 -0
- package/dist/src/schema.d.ts +449 -0
- package/dist/src/schema.js +605 -0
- package/dist/src/serve.d.ts +30 -0
- package/dist/src/serve.js +82 -0
- package/dist/src/served-world.d.ts +194 -0
- package/dist/src/served-world.js +986 -0
- package/dist/src/service-exit.d.ts +46 -0
- package/dist/src/service-exit.js +195 -0
- package/dist/src/service-recorder.d.ts +1 -0
- package/dist/src/service-recorder.js +121 -0
- package/dist/src/sibling.d.ts +1 -0
- package/dist/src/sibling.js +9 -0
- package/dist/src/signals.d.ts +1 -0
- package/dist/src/signals.js +11 -0
- package/dist/src/storage-capacity.d.ts +8 -0
- package/dist/src/storage-capacity.js +61 -0
- package/dist/src/tail.d.ts +30 -0
- package/dist/src/tail.js +160 -0
- package/dist/src/tcp-port.d.ts +2 -0
- package/dist/src/tcp-port.js +36 -0
- package/dist/src/up-task-worker.d.ts +1 -0
- package/dist/src/up-task-worker.js +61 -0
- package/dist/src/up-task.d.ts +17 -0
- package/dist/src/up-task.js +49 -0
- package/dist/src/websocket-relay.d.ts +3 -0
- package/dist/src/websocket-relay.js +40 -0
- package/known-external-services.json +1108 -0
- package/package.json +83 -0
- package/src/ancestry.ts +36 -0
- package/src/app-url.ts +253 -0
- package/src/attach.ts +117 -0
- package/src/branch.ts +63 -0
- package/src/browser-proxy-cli.ts +44 -0
- package/src/ca-trust.ts +57 -0
- package/src/catalog.ts +156 -0
- package/src/changeset.ts +627 -0
- package/src/cli.ts +1111 -0
- package/src/command-lifetime.ts +79 -0
- package/src/configs.ts +110 -0
- package/src/console-apart.ts +90 -0
- package/src/consumers.ts +185 -0
- package/src/covers.ts +934 -0
- package/src/fixture-env.ts +230 -0
- package/src/host-cli.ts +90 -0
- package/src/host-worker.ts +23 -0
- package/src/host.ts +169 -0
- package/src/index.ts +171 -0
- package/src/infra-cli.ts +133 -0
- package/src/init.ts +1316 -0
- package/src/inject-map.ts +72 -0
- package/src/lifecycle-record.ts +168 -0
- package/src/origin.ts +134 -0
- package/src/pack-facts.ts +128 -0
- package/src/pglite-backing.ts +141 -0
- package/src/pglite-host.mjs +147 -0
- package/src/placeholder.ts +89 -0
- package/src/prerequisites.ts +66 -0
- package/src/process-groups.ts +33 -0
- package/src/project-inspect.ts +770 -0
- package/src/proxy-daemon.ts +21 -0
- package/src/redirect-proxy.ts +684 -0
- package/src/reflect.ts +440 -0
- package/src/resources.ts +22 -0
- package/src/root.ts +290 -0
- package/src/run-task-worker.ts +27 -0
- package/src/run-task.ts +44 -0
- package/src/runtime-test-support.ts +208 -0
- package/src/runtime.ts +3357 -0
- package/src/schema.ts +922 -0
- package/src/serve.ts +102 -0
- package/src/served-world.ts +812 -0
- package/src/service-exit.ts +175 -0
- package/src/service-recorder.ts +89 -0
- package/src/sibling.ts +10 -0
- package/src/signals.ts +10 -0
- package/src/storage-capacity.ts +60 -0
- package/src/tail.ts +205 -0
- package/src/tcp-port.ts +35 -0
- package/src/up-task-worker.ts +40 -0
- package/src/up-task.ts +45 -0
- package/src/websocket-relay.ts +32 -0
package/src/index.ts
ADDED
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
export type {
|
|
2
|
+
WorldConfig,
|
|
3
|
+
WorldInstance,
|
|
4
|
+
WorldIsolation,
|
|
5
|
+
WorldMode,
|
|
6
|
+
WorldServiceConfig,
|
|
7
|
+
WorldServiceType,
|
|
8
|
+
WorldExternalServiceConfig,
|
|
9
|
+
WorldExternalDiscover,
|
|
10
|
+
WorldExternalDiscoverSource,
|
|
11
|
+
WorldExternalReadyWhen,
|
|
12
|
+
WorldRunOutcome,
|
|
13
|
+
WorldRunRecord,
|
|
14
|
+
WorldResourceRequirements,
|
|
15
|
+
WorldManifestV2,
|
|
16
|
+
WorldSelection,
|
|
17
|
+
WorldSelectionSelector,
|
|
18
|
+
WorldUsage,
|
|
19
|
+
} from './schema.ts';
|
|
20
|
+
export { DEFAULT_WORLD_SELECTION, LEGACY_WORLD_SELECTION, WORLD_SCHEMA_VERSION, WORLD_USAGES, worldConfigDocument, worldSelectionIncludes } from './schema.ts';
|
|
21
|
+
export { loadWorldConfig, migrateWorldConfig, resolveConfigPath, writeWorldConfig } from './configs.ts';
|
|
22
|
+
export type { WorldConfigMigration } from './configs.ts';
|
|
23
|
+
export {
|
|
24
|
+
upWorld,
|
|
25
|
+
downWorld,
|
|
26
|
+
pruneWorlds,
|
|
27
|
+
listWorlds,
|
|
28
|
+
statusWorld,
|
|
29
|
+
doctorWorld,
|
|
30
|
+
runWithWorldEnv,
|
|
31
|
+
attachWorld,
|
|
32
|
+
retireWorldConsumers,
|
|
33
|
+
activateScript,
|
|
34
|
+
shellWorld,
|
|
35
|
+
worldShellEnv,
|
|
36
|
+
ensureWorldProxy,
|
|
37
|
+
runProxyDaemon,
|
|
38
|
+
runWorld,
|
|
39
|
+
shareWorld,
|
|
40
|
+
shareWorldServices,
|
|
41
|
+
unshareWorld,
|
|
42
|
+
urlsWorld,
|
|
43
|
+
urlWorld,
|
|
44
|
+
} from './runtime.ts';
|
|
45
|
+
export type { WorldCleanupEntry } from './runtime.ts';
|
|
46
|
+
export { worldResourceReport } from './resources.ts';
|
|
47
|
+
// `volter-world app-url` — the recorded, queryable app endpoint of an instance (see app-url.ts).
|
|
48
|
+
export { appUrlFile, appUrlUnsetMessage, detectAppUrl, readAppUrl, setAppUrl } from './app-url.ts';
|
|
49
|
+
export type { AppUrlRecord, AppUrlSource } from './app-url.ts';
|
|
50
|
+
export { tailWorldActions } from './tail.ts';
|
|
51
|
+
export type { TailWorldOptions } from './tail.ts';
|
|
52
|
+
// the changeset primitive + the diff verb (docs/concepts/the-model.md v0) and the operational-PR
|
|
53
|
+
// contract over it (v1: verify/approve/status). World-side glue only — markers, deltas, content
|
|
54
|
+
// hashing, replay, verifier evaluation and approval binding live in @volter/world-core's control plane.
|
|
55
|
+
export {
|
|
56
|
+
pushWorldChangeset,
|
|
57
|
+
rebaseWorldChangeset,
|
|
58
|
+
approveWorldChangeset,
|
|
59
|
+
createWorldChangeset,
|
|
60
|
+
diffWorld,
|
|
61
|
+
EPHEMERAL_VERIFY_TARGET,
|
|
62
|
+
findWorldChangeset,
|
|
63
|
+
listWorldChangesets,
|
|
64
|
+
listWorldMarks,
|
|
65
|
+
markWorld,
|
|
66
|
+
MARK_NOTE_MAX,
|
|
67
|
+
replayWorldChangeset,
|
|
68
|
+
resolveBaseMarker,
|
|
69
|
+
statusWorldChangeset,
|
|
70
|
+
verifyWorldChangeset,
|
|
71
|
+
worldChangesetsDir,
|
|
72
|
+
worldLedgers,
|
|
73
|
+
worldMarksDir,
|
|
74
|
+
} from './changeset.ts';
|
|
75
|
+
export type { NotedMarker, PushWorldOptions, PushWorldOutcome, RebaseWorldOutcome, ApproveWorldOutcome, ChangesetLocation, VerifyWorldOutcome, WorldRootOptions } from './changeset.ts';
|
|
76
|
+
export {
|
|
77
|
+
checkLocalExecution,
|
|
78
|
+
checkPrerequisites,
|
|
79
|
+
formatPrerequisiteChecks,
|
|
80
|
+
} from './prerequisites.ts';
|
|
81
|
+
export { inspectProject, formatProjectInspection, projectDependencies, projectEnvNames, SDK_TWINS, workspaceDirs } from './project-inspect.ts';
|
|
82
|
+
export type { ProjectInspection } from './project-inspect.ts';
|
|
83
|
+
// Structurally valid fake credentials for world configs (fixture env) — see fixture-env.ts
|
|
84
|
+
// for the pattern (a fake a client SDK parses/signs with must be structurally real).
|
|
85
|
+
export { fakeEnvValue, fakeGoogleOAuthClientJson, fakeGoogleServiceAccountJson, isGoogleOAuthClientEnvName, isGoogleServiceAccountEnvName } from './fixture-env.ts';
|
|
86
|
+
export type { FakeServiceAccountOptions } from './fixture-env.ts';
|
|
87
|
+
export {
|
|
88
|
+
coverWorld,
|
|
89
|
+
detectRepoVendors,
|
|
90
|
+
envNameVendor,
|
|
91
|
+
formatCoverageReport,
|
|
92
|
+
injectorVendorKeysFor,
|
|
93
|
+
isCredentialShapedEnvName,
|
|
94
|
+
worldTwinInventory,
|
|
95
|
+
} from './covers.ts';
|
|
96
|
+
export type { CoverageReport, CoverageRow, CoverageStatus, CoverageOptions, RepoVendorSignals } from './covers.ts';
|
|
97
|
+
// `volter-world init` — the deterministic front door: detect the repo's vendors (covers), emit a
|
|
98
|
+
// world config + env file OUTSIDE the repo (fixture-env), and prove the emission with `covers`.
|
|
99
|
+
export { formatInitReport, initWorld, packCatalog, planWorldInit, renderEnvFile, writeWorldInit } from './init.ts';
|
|
100
|
+
export { STATE_GITIGNORE } from './init.ts';
|
|
101
|
+
export { clockFile } from './runtime.ts';
|
|
102
|
+
export { checkoutCatalog, findInstalledPackage, installedCatalog, resolveCatalog, resolveServicePackage, twinPackageName, TWIN_PACKAGE_PREFIX, type Catalog, type CatalogKind, packCli, packEntry } from './catalog.ts';
|
|
103
|
+
export { MINT_ENV } from './schema.ts';
|
|
104
|
+
export type {
|
|
105
|
+
EnvDisposition,
|
|
106
|
+
InitEnvRow,
|
|
107
|
+
InitInfraStub,
|
|
108
|
+
InitOptions,
|
|
109
|
+
InitPlan,
|
|
110
|
+
InitResult,
|
|
111
|
+
InitVendorPlan,
|
|
112
|
+
InitWiring,
|
|
113
|
+
} from './init.ts';
|
|
114
|
+
export {
|
|
115
|
+
deriveWorldManifest,
|
|
116
|
+
findWorldRefFile,
|
|
117
|
+
isRemoteWorldRef,
|
|
118
|
+
resolveWorldRef,
|
|
119
|
+
WORLD_REF_FILE,
|
|
120
|
+
worldManifest,
|
|
121
|
+
} from './attach.ts';
|
|
122
|
+
export type { ResolvedWorldRef, WorldManifest, WorldRefSource } from './attach.ts';
|
|
123
|
+
export {
|
|
124
|
+
parseSni,
|
|
125
|
+
readReflectRoutes,
|
|
126
|
+
reflectRoutesPath,
|
|
127
|
+
reflectManifestPath,
|
|
128
|
+
readReflectManifest,
|
|
129
|
+
writeReflectManifest,
|
|
130
|
+
clearReflectManifest,
|
|
131
|
+
composeOverrideForReflect,
|
|
132
|
+
splitDockerComposeArgs,
|
|
133
|
+
dockerComposeWithOverride,
|
|
134
|
+
CA_TRUST_ENV,
|
|
135
|
+
ATTACHED_CA_PATH,
|
|
136
|
+
startReflectFront,
|
|
137
|
+
startReflectResolver,
|
|
138
|
+
writeReflectRoutes,
|
|
139
|
+
} from './reflect.ts';
|
|
140
|
+
export type { ReflectFrontHandle, ReflectFrontOptions, ReflectManifest, ReflectResolverHandle, ReflectResolverOptions } from './reflect.ts';
|
|
141
|
+
export type {
|
|
142
|
+
PrerequisiteCheck,
|
|
143
|
+
PrerequisiteId,
|
|
144
|
+
} from './prerequisites.ts';
|
|
145
|
+
export { startColocatedHost } from './host.ts';
|
|
146
|
+
export type { ColocatedTwinSpec, ColocatedHost, HostIsolation } from './host.ts';
|
|
147
|
+
export {
|
|
148
|
+
advertiseWorldManifest,
|
|
149
|
+
fetchRemoteManifest,
|
|
150
|
+
MANIFEST_PATH,
|
|
151
|
+
remoteAttachEnv,
|
|
152
|
+
startManifestServer,
|
|
153
|
+
} from './serve.ts';
|
|
154
|
+
export type { ManifestServerHandle, ManifestServerOptions } from './serve.ts';
|
|
155
|
+
|
|
156
|
+
export { resetWorld, seedEntryFor, seedWorld } from './placeholder.ts';
|
|
157
|
+
export type { SeedWorldOptions, SeedWorldOutcome } from './placeholder.ts';
|
|
158
|
+
|
|
159
|
+
export { fetchFromOrigin, worldOrigin } from './origin.ts';
|
|
160
|
+
export type { FetchOptions, FetchOutcome } from './origin.ts';
|
|
161
|
+
|
|
162
|
+
export { branchWorld, checkoutWorld } from './branch.ts';
|
|
163
|
+
export type { BranchOptions } from './branch.ts';
|
|
164
|
+
export { deployWorld, refreshTwin, adaptersFor, credentialPath, credentialPayloadFrom, deployTwin, loadWorldChecks, materializeRoots, rootForControlRoot, sealTwinCredential, sealedCredentialInfo, setTwinRoot, userKekPath } from './root.ts';
|
|
165
|
+
export type { DeployTwinOutcome, MaterializedRoot } from './root.ts';
|
|
166
|
+
export { landReceipts, mountWorld, readServeRecord, refreshSchedule, servedName, serveWorld, TOKEN_HEADER, WorldDoors } from './served-world.ts';
|
|
167
|
+
export type { DoorHost, MountedWorld, ServeRecord, WorldLayout } from './served-world.ts';
|
|
168
|
+
export type { ServedWorld } from './served-world.ts';
|
|
169
|
+
export { CONSOLE_BASE, consoleRedirect, serveConsoleApart, serveConsoleFor, type ConsoleMount } from './console-apart.ts';
|
|
170
|
+
|
|
171
|
+
export { assertWorldStateRemovable } from './ancestry.ts';
|
package/src/infra-cli.ts
ADDED
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// Private implementation for infrastructure emitted by `volter-world init`. World configs invoke
|
|
3
|
+
// this declared service; application agents never operate or diagnose its backing mechanism.
|
|
4
|
+
import { existsSync, readFileSync } from 'node:fs';
|
|
5
|
+
import { dirname, join } from 'node:path';
|
|
6
|
+
import { spawnSync } from 'node:child_process';
|
|
7
|
+
import { infraConnections, parseInfraDefinition } from './pglite-backing.ts';
|
|
8
|
+
|
|
9
|
+
const phase = process.argv[2];
|
|
10
|
+
if (phase !== 'up' && phase !== 'status' && phase !== 'down') {
|
|
11
|
+
process.stderr.write('managed infrastructure: expected up, status, or down\n');
|
|
12
|
+
process.exit(2);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const worldConfig = process.env.VOLTER_WORLD_CONFIG;
|
|
16
|
+
const worldData = process.env.VOLTER_WORLD_DATA;
|
|
17
|
+
if (!worldConfig || !worldData) {
|
|
18
|
+
process.stderr.write('managed infrastructure: missing World lifecycle context\n');
|
|
19
|
+
process.exit(2);
|
|
20
|
+
}
|
|
21
|
+
const definition = join(dirname(worldConfig), 'world.infrastructure.yml');
|
|
22
|
+
if (!existsSync(definition)) {
|
|
23
|
+
process.stderr.write('managed infrastructure: declared definition is missing\n');
|
|
24
|
+
process.exit(2);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const base = ['compose', '-f', definition];
|
|
28
|
+
const run = (args: string[]) => spawnSync('docker', [...base, ...args], {
|
|
29
|
+
encoding: 'utf8',
|
|
30
|
+
env: { ...process.env, VOLTER_WORLD_DATA: worldData },
|
|
31
|
+
timeout: 120_000,
|
|
32
|
+
});
|
|
33
|
+
const classify = (raw: string): string => /no space left on device|enospc/iu.test(raw)
|
|
34
|
+
? 'insufficient writable storage'
|
|
35
|
+
: /out of memory|cannot allocate memory|killed/iu.test(raw)
|
|
36
|
+
? 'insufficient memory'
|
|
37
|
+
: /cannot connect|not running|daemon/iu.test(raw)
|
|
38
|
+
? 'local execution capacity is unavailable'
|
|
39
|
+
: 'managed infrastructure operation failed';
|
|
40
|
+
const fail = (result: ReturnType<typeof run>): never => {
|
|
41
|
+
const raw = `${result.stdout ?? ''}\n${result.stderr ?? ''}`.trim();
|
|
42
|
+
process.stderr.write(`managed infrastructure ${phase} failed: ${classify(raw)}\n`);
|
|
43
|
+
process.exit(result.status && result.status > 0 ? result.status : 1);
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
// ---- backing selection ------------------------------------------------------
|
|
47
|
+
// The declared service contract (up/status/down) is the boundary; WHICH
|
|
48
|
+
// runtime answers it is private and chosen here, per machine, at each phase:
|
|
49
|
+
// 1. VOLTER_WORLD_INFRA_BACKING=docker|pglite — explicit, for tests/operators;
|
|
50
|
+
// 2. a working container runtime — the compose path, byte-identical to before;
|
|
51
|
+
// 3. no container runtime + a postgres-only definition — the PGlite backing
|
|
52
|
+
// (pglite-host.ts), announced loudly;
|
|
53
|
+
// 4. otherwise the honest refusal naming what this machine cannot serve.
|
|
54
|
+
function selectBacking(): 'docker' | 'pglite' {
|
|
55
|
+
const forced = process.env.VOLTER_WORLD_INFRA_BACKING;
|
|
56
|
+
if (forced === 'docker' || forced === 'pglite') return forced;
|
|
57
|
+
if (forced !== undefined) {
|
|
58
|
+
process.stderr.write(`managed infrastructure: VOLTER_WORLD_INFRA_BACKING must be docker or pglite (got ${JSON.stringify(forced)})\n`);
|
|
59
|
+
process.exit(2);
|
|
60
|
+
}
|
|
61
|
+
const probe = spawnSync('docker', ['info', '--format', '{{.ServerVersion}}'], { encoding: 'utf8', timeout: 10_000 });
|
|
62
|
+
if (probe.status === 0) return 'docker';
|
|
63
|
+
// Absence of a container runtime (no binary, no daemon) is a capability
|
|
64
|
+
// difference: swap backings. A PRESENT runtime failing on resources stays
|
|
65
|
+
// on the docker path so the real capacity problem is classified and
|
|
66
|
+
// surfaced — a full disk starves every backing equally.
|
|
67
|
+
if (probe.error !== undefined) return 'pglite';
|
|
68
|
+
const reason = classify(`${probe.stdout ?? ''}\n${probe.stderr ?? ''}`);
|
|
69
|
+
return reason === 'local execution capacity is unavailable' ? 'pglite' : 'docker';
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
async function runPglite(): Promise<never> {
|
|
73
|
+
const { unsupportedKinds, pgliteUp, pgliteStatus, pgliteDown } = await import('./pglite-backing.ts');
|
|
74
|
+
const services = parseInfraDefinition(readFileSync(definition, 'utf8'));
|
|
75
|
+
if (services.length === 0) {
|
|
76
|
+
process.stderr.write('managed infrastructure: the declared definition names no services\n');
|
|
77
|
+
process.exit(1);
|
|
78
|
+
}
|
|
79
|
+
const unsupported = unsupportedKinds(services);
|
|
80
|
+
if (unsupported.length > 0) {
|
|
81
|
+
process.stderr.write(`managed infrastructure ${phase} failed: local execution capacity is unavailable (no container runtime, and the containerless backing cannot serve: ${unsupported.join(', ')})\n`);
|
|
82
|
+
process.exit(1);
|
|
83
|
+
}
|
|
84
|
+
if (phase === 'up') {
|
|
85
|
+
process.stdout.write('managed infrastructure backing: pglite (no container runtime)\n');
|
|
86
|
+
try {
|
|
87
|
+
await pgliteUp(services, worldData!);
|
|
88
|
+
} catch (error) {
|
|
89
|
+
process.stderr.write(`managed infrastructure up failed: ${String((error as Error).message ?? error)}\n`);
|
|
90
|
+
process.exit(1);
|
|
91
|
+
}
|
|
92
|
+
process.stdout.write('managed infrastructure ready\n');
|
|
93
|
+
process.exit(0);
|
|
94
|
+
}
|
|
95
|
+
if (phase === 'status') {
|
|
96
|
+
const status = await pgliteStatus(services, worldData!);
|
|
97
|
+
if (!status.ok) {
|
|
98
|
+
process.stderr.write(`managed infrastructure status failed: ${status.ready}/${services.length} declared services are ready\n`);
|
|
99
|
+
process.exit(1);
|
|
100
|
+
}
|
|
101
|
+
process.stdout.write(`${JSON.stringify({ ok: true, services: services.length, connections: infraConnections(services, process.env) })}\n`);
|
|
102
|
+
process.exit(0);
|
|
103
|
+
}
|
|
104
|
+
await pgliteDown(services, worldData!);
|
|
105
|
+
process.stdout.write('managed infrastructure stopped\n');
|
|
106
|
+
process.exit(0);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
if (selectBacking() === 'pglite') {
|
|
110
|
+
await runPglite();
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
if (phase === 'up') {
|
|
114
|
+
const result = run(['up', '-d', '--wait']);
|
|
115
|
+
if (result.status !== 0) fail(result);
|
|
116
|
+
process.stdout.write('managed infrastructure ready\n');
|
|
117
|
+
} else if (phase === 'status') {
|
|
118
|
+
const expected = run(['config', '--services']);
|
|
119
|
+
if (expected.status !== 0) fail(expected);
|
|
120
|
+
const running = run(['ps', '--status', 'running', '--services']);
|
|
121
|
+
if (running.status !== 0) fail(running);
|
|
122
|
+
const expectedNames = expected.stdout.split(/\s+/u).filter(Boolean).sort();
|
|
123
|
+
const runningNames = running.stdout.split(/\s+/u).filter(Boolean).sort();
|
|
124
|
+
if (expectedNames.length === 0 || expectedNames.join('\0') !== runningNames.join('\0')) {
|
|
125
|
+
process.stderr.write(`managed infrastructure status failed: ${runningNames.length}/${expectedNames.length} declared services are ready\n`);
|
|
126
|
+
process.exit(1);
|
|
127
|
+
}
|
|
128
|
+
process.stdout.write(`${JSON.stringify({ ok: true, services: expectedNames.length, connections: infraConnections(parseInfraDefinition(readFileSync(definition, 'utf8')), process.env) })}\n`);
|
|
129
|
+
} else {
|
|
130
|
+
const result = run(['down', '--remove-orphans']);
|
|
131
|
+
if (result.status !== 0) fail(result);
|
|
132
|
+
process.stdout.write('managed infrastructure stopped\n');
|
|
133
|
+
}
|