@fabrika/provider-zerops 0.9.0-dev.1 → 0.9.0-dev.11
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/package.json +17 -14
- package/sandbox/Dockerfile +16 -0
- package/sandbox/bin/postgres-auth.sh +38 -0
- package/sandbox/bin/reset.sh +12 -0
- package/sandbox/bin/run-build.sh +35 -0
- package/sandbox/bin/run-launcher.sh +18 -0
- package/sandbox/bin/start-launcher.sh +25 -0
- package/sandbox/bin/stop.sh +47 -0
- package/sandbox/init.sh +61 -0
- package/src/api/client.ts +15 -1
- package/src/api/errors.ts +7 -3
- package/src/api/readers.ts +29 -0
- package/src/api/types.ts +52 -0
- package/src/api.ts +2 -0
- package/src/cli.ts +11 -0
- package/src/collaborators.ts +0 -14
- package/src/compile.ts +1 -1
- package/src/control.ts +159 -92
- package/src/execution.ts +45 -195
- package/src/index.ts +2 -0
- package/src/installation/admin.ts +1 -1
- package/src/installation/deploy-options.ts +10 -2
- package/src/installation/deploy.ts +241 -81
- package/src/installation/generated/platform-console-schema.ts +3 -0
- package/src/installation/generated/platform-proxy-manifest.ts +1 -1
- package/src/installation/guide.md +53 -19
- package/src/installation/hosts.ts +1 -7
- package/src/installation/index.ts +20 -16
- package/src/installation/init-options.ts +2 -1
- package/src/installation/install-environment.ts +47 -108
- package/src/installation/install-options.ts +3 -1
- package/src/installation/install-secrets.ts +24 -68
- package/src/installation/install.ts +9 -4
- package/src/installation/plain-credentials.ts +91 -0
- package/src/installation/sidecar.ts +5 -26
- package/src/installation/templates/README.md +13 -12
- package/src/installation/templates/platform.yml +3 -0
- package/src/installation/topology/setups.ts +17 -4
- package/src/installation/topology/topology.ts +33 -23
- package/src/installation/upgrade-options.ts +2 -2
- package/src/managed-env.ts +1 -174
- package/src/manifest.ts +14 -17
- package/src/namespace/claims.ts +60 -1
- package/src/namespace/codec.ts +17 -0
- package/src/namespace/errors.ts +22 -1
- package/src/namespace/manifest.ts +36 -23
- package/src/namespace/provisioning.ts +88 -114
- package/src/namespace/proxy-attempt.ts +14 -2
- package/src/namespace/proxy-reads.ts +28 -23
- package/src/namespace/proxy-secrets.ts +18 -5
- package/src/namespace/sandbox-host.ts +212 -0
- package/src/namespace/subdomain.ts +113 -0
- package/src/namespace/topology.ts +1 -1
- package/src/namespace/types.ts +13 -0
- package/src/namespace/update.ts +1 -0
- package/src/namespace-cli.ts +152 -0
- package/src/plain-credentials.ts +90 -0
- package/src/plan.ts +1 -6
- package/src/provider.ts +88 -166
- package/src/proxy-manifest-carrier.ts +39 -0
- package/src/sandbox/base-image.ts +100 -0
- package/src/sandbox/constants.ts +44 -0
- package/src/sandbox/deploy.ts +471 -0
- package/src/sandbox/dev-artifact.ts +206 -0
- package/src/sandbox/lifecycle.ts +204 -0
- package/src/sandbox/scripts.ts +26 -0
- package/src/sandbox-host.ts +28 -0
- package/src/source/port.ts +5 -0
- package/src/types.ts +6 -2
- package/src/zbox/client.ts +259 -0
- package/src/zbox/errors.ts +45 -0
- package/src/zbox/index.ts +22 -0
- package/src/zbox/types.ts +165 -0
- package/types/src/api/client.d.ts +5 -0
- package/types/src/api/errors.d.ts +26 -0
- package/types/src/api/polling.d.ts +41 -0
- package/types/src/api/readers.d.ts +1115 -0
- package/types/src/api/service-env-limit.d.ts +17 -0
- package/types/src/api/service-env-response.d.ts +23 -0
- package/types/src/api/types.d.ts +687 -0
- package/types/src/api.d.ts +6 -0
- package/types/src/authoring.d.ts +9 -0
- package/types/src/cli-args.d.ts +19 -0
- package/types/src/cli.d.ts +13 -0
- package/types/src/collaborators.d.ts +16 -0
- package/types/src/compile.d.ts +91 -0
- package/types/src/control.d.ts +51 -0
- package/types/src/database-budget.d.ts +38 -0
- package/types/src/descriptor.d.ts +28 -0
- package/types/src/execution.d.ts +114 -0
- package/types/src/exposure.d.ts +47 -0
- package/types/src/index.d.ts +31 -0
- package/types/src/installation/admin-options.d.ts +24 -0
- package/types/src/installation/admin.d.ts +35 -0
- package/types/src/installation/checker-release.d.ts +12 -0
- package/types/src/installation/deploy-options.d.ts +42 -0
- package/types/src/installation/deploy.d.ts +136 -0
- package/types/src/installation/generated/platform-console-schema.d.ts +2 -0
- package/types/src/installation/generated/platform-proxy-manifest.d.ts +2 -0
- package/types/src/installation/hosts.d.ts +34 -0
- package/types/src/installation/index.d.ts +7 -0
- package/types/src/installation/init-options.d.ts +38 -0
- package/types/src/installation/init.d.ts +60 -0
- package/types/src/installation/install-collaborators.d.ts +24 -0
- package/types/src/installation/install-environment.d.ts +63 -0
- package/types/src/installation/install-options.d.ts +49 -0
- package/types/src/installation/install-project.d.ts +13 -0
- package/types/src/installation/install-provisioning.d.ts +58 -0
- package/types/src/installation/install-secrets.d.ts +17 -0
- package/types/src/installation/install-token.d.ts +10 -0
- package/types/src/installation/install.d.ts +23 -0
- package/types/src/installation/installation-source.d.ts +8 -0
- package/types/src/installation/log.d.ts +44 -0
- package/types/src/installation/machine-key.d.ts +19 -0
- package/types/src/installation/placement-options.d.ts +11 -0
- package/types/src/installation/plain-credentials.d.ts +20 -0
- package/types/src/installation/platform-archive.d.ts +7 -0
- package/types/src/installation/platform-source.d.ts +8 -0
- package/types/src/installation/platform-upload.d.ts +3 -0
- package/types/src/installation/sidecar.d.ts +49 -0
- package/types/src/installation/source-options.d.ts +1 -0
- package/types/src/installation/topology/artifacts.d.ts +8 -0
- package/types/src/installation/topology/index.d.ts +5 -0
- package/types/src/installation/topology/installation-schemas.d.ts +2242 -0
- package/types/src/installation/topology/invariants.d.ts +23 -0
- package/types/src/installation/topology/setups.d.ts +59 -0
- package/types/src/installation/topology/topology.d.ts +153 -0
- package/types/src/installation/topology/validate.d.ts +11 -0
- package/types/src/installation/upgrade-options.d.ts +26 -0
- package/types/src/installation/upgrade-output.d.ts +6 -0
- package/types/src/installation/upgrade.d.ts +88 -0
- package/types/src/managed-env.d.ts +24 -0
- package/types/src/manifest.d.ts +199 -0
- package/types/src/namespace/claims.d.ts +16 -0
- package/types/src/namespace/codec.d.ts +352 -0
- package/types/src/namespace/constants.d.ts +25 -0
- package/types/src/namespace/errors.d.ts +25 -0
- package/types/src/namespace/manifest.d.ts +4 -0
- package/types/src/namespace/operator.d.ts +12 -0
- package/types/src/namespace/provisioning.d.ts +4 -0
- package/types/src/namespace/proxy-attempt.d.ts +39 -0
- package/types/src/namespace/proxy-reads.d.ts +27 -0
- package/types/src/namespace/proxy-secrets.d.ts +8 -0
- package/types/src/namespace/proxy-source.d.ts +74 -0
- package/types/src/namespace/sandbox-host.d.ts +23 -0
- package/types/src/namespace/subdomain.d.ts +43 -0
- package/types/src/namespace/topology.d.ts +9 -0
- package/types/src/namespace/types.d.ts +111 -0
- package/types/src/namespace/update.d.ts +6 -0
- package/types/src/namespace/validation.d.ts +12 -0
- package/types/src/namespace-cli.d.ts +2 -0
- package/types/src/namespace.d.ts +9 -0
- package/types/src/plain-credentials.d.ts +7 -0
- package/types/src/plan.d.ts +11 -0
- package/types/src/provider.d.ts +60 -0
- package/types/src/proxy-manifest-carrier.d.ts +37 -0
- package/types/src/sandbox/base-image.d.ts +28 -0
- package/types/src/sandbox/constants.d.ts +30 -0
- package/types/src/sandbox/deploy.d.ts +75 -0
- package/types/src/sandbox/dev-artifact.d.ts +51 -0
- package/types/src/sandbox/lifecycle.d.ts +27 -0
- package/types/src/sandbox/scripts.d.ts +11 -0
- package/types/src/sandbox-host.d.ts +16 -0
- package/types/src/schema.generated.d.ts +376 -0
- package/types/src/service-names.d.ts +4 -0
- package/types/src/service-references.d.ts +13 -0
- package/types/src/source/constants.d.ts +6 -0
- package/types/src/source/port.d.ts +65 -0
- package/types/src/source/types.d.ts +4 -0
- package/types/src/source/validation.d.ts +19 -0
- package/types/src/source.d.ts +2 -0
- package/types/src/types.d.ts +125 -0
- package/types/src/version-attempt.d.ts +8 -0
- package/types/src/zbox/client.d.ts +2 -0
- package/types/src/zbox/errors.d.ts +25 -0
- package/types/src/zbox/index.d.ts +3 -0
- package/types/src/zbox/types.d.ts +433 -0
- package/src/installation/mcp.ts +0 -102
- package/src/installation/proxy-manifest.ts +0 -214
- package/src/installation/secrets.ts +0 -78
package/src/execution.ts
CHANGED
|
@@ -2,19 +2,16 @@
|
|
|
2
2
|
// runs. Of the authored setup only `build.base`, `build.os` and the SPA's `build.buildCommands` survive; the rest of
|
|
3
3
|
// the build, the deploy gate and the whole `run` section are generated here. PURE — no network, no filesystem.
|
|
4
4
|
|
|
5
|
+
import { type ContractRecipe, contractRecipe } from '@fabrika/app/build'
|
|
5
6
|
import {
|
|
6
7
|
type ContractArtifact,
|
|
7
|
-
DEV_LAUNCHER_CONFIG_FILE,
|
|
8
|
-
DEV_LAUNCHER_MODULE,
|
|
9
|
-
DEV_LAUNCHER_STATE_FILE,
|
|
10
|
-
type DevLauncherConfig,
|
|
11
8
|
FABRIKA_CONTRACT_DIGEST,
|
|
12
9
|
FABRIKA_SOURCE_MAP_UPLOAD,
|
|
13
10
|
FABRIKA_SOURCE_MAP_UPLOAD_KEY,
|
|
14
11
|
type FrameworkVariableName,
|
|
15
12
|
} from '@fabrika/auth-core'
|
|
16
13
|
import type { OperationsAssetRoot, OperationsSourceMapBuildUpload } from '@fabrika/operations-contract/releases'
|
|
17
|
-
import {
|
|
14
|
+
import type { JsonValue } from '@fabrika/provider-contract'
|
|
18
15
|
import packageManifest from '../package.json'
|
|
19
16
|
import { renderYaml } from './compile'
|
|
20
17
|
import { parseZeropsDescriptor, type PreparedZeropsDescriptor, selectZeropsDescriptorSetup } from './descriptor'
|
|
@@ -33,8 +30,7 @@ export const ZEROPS_APPLICATION_RUNTIME = 'alpine/bun@1.3'
|
|
|
33
30
|
*/
|
|
34
31
|
export const FABRIKA_CHECK_VERSION: string = packageManifest.version
|
|
35
32
|
|
|
36
|
-
|
|
37
|
-
export const PLATFORM_TYPESCRIPT_VERSION = '5.9.3'
|
|
33
|
+
export { PLATFORM_TYPESCRIPT_VERSION } from '@fabrika/app/build'
|
|
38
34
|
|
|
39
35
|
/** System packages an application may add to its runtime image, installed by the generated `run.prepareCommands`. */
|
|
40
36
|
export const ZEROPS_RUNTIME_PACKAGES = ['ffmpeg', 'ghostscript', 'imagemagick', 'poppler-utils', 'vips'] as const
|
|
@@ -46,12 +42,6 @@ export interface ZeropsContractJob {
|
|
|
46
42
|
readonly schedule: string
|
|
47
43
|
}
|
|
48
44
|
|
|
49
|
-
/** The framework's file scan job (`@fabrika/app`'s `FILE_SCAN_JOB`), run every minute when a collection scans. */
|
|
50
|
-
export const ZEROPS_FILE_SCAN_JOB = 'fabrika-file-scan'
|
|
51
|
-
/** The framework's file sweep job (`@fabrika/app`'s `FILE_SWEEP_JOB` and its schedule), run when the contract has files. */
|
|
52
|
-
export const ZEROPS_FILE_SWEEP_JOB = 'fabrika-file-sweep'
|
|
53
|
-
const FILE_SWEEP_SCHEDULE = '41 * * * *'
|
|
54
|
-
|
|
55
45
|
/**
|
|
56
46
|
* The RAM in GB a container of a scanning application starts with: one `clamscan` over a batch peaks at about 1 GB
|
|
57
47
|
* resident while it loads its signatures (measured with ClamAV 1.4), beside the application's own process.
|
|
@@ -111,20 +101,10 @@ export interface ZeropsLockedExecution {
|
|
|
111
101
|
readonly runtimePackages: readonly ZeropsRuntimePackage[]
|
|
112
102
|
/** Where the build uploads its source maps, without the bearer; null when Control minted no upload for the run. */
|
|
113
103
|
readonly sourceMaps: OperationsSourceMapBuildUpload | null
|
|
114
|
-
/**
|
|
115
|
-
* Present for an environment of kind `dev` (ADR-0049): `run.start` runs the dev launcher instead of the serving
|
|
116
|
-
* entry. The environment's kind selects it; an application never authors it.
|
|
117
|
-
*/
|
|
118
|
-
readonly dev?: ZeropsDevExecution
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
export interface ZeropsDevExecution {
|
|
122
|
-
/** The commit the bootstrap run builds: what a new container holds before the launcher's first sync. */
|
|
123
|
-
readonly head: string
|
|
124
104
|
}
|
|
125
105
|
|
|
126
106
|
/** The application ids the generated scripts may name: the contract's own id rule, so a script needs no quoting. */
|
|
127
|
-
export
|
|
107
|
+
export { CONTRACT_APP_ID_PATTERN as LOCKED_APP_ID_PATTERN } from '@fabrika/app/build'
|
|
128
108
|
|
|
129
109
|
export const CONTRACT_DIGEST_PATTERN = /^sha256:[0-9a-f]{64}$/
|
|
130
110
|
|
|
@@ -258,32 +238,6 @@ export function lockedAuthoredBuild(entry: { readonly [key: string]: JsonValue }
|
|
|
258
238
|
|
|
259
239
|
const SOURCE_ROOT = '/build/source'
|
|
260
240
|
const RUNTIME_ROOT = '/var/www'
|
|
261
|
-
const FABRIKA_BIN = './node_modules/.bin/fabrika'
|
|
262
|
-
const MIGRATE_SCRIPT = 'fabrika/migrate.generated.sh'
|
|
263
|
-
const VERIFY_SCRIPT = 'fabrika/verify.generated.sh'
|
|
264
|
-
const START_SCRIPT = 'fabrika/start.generated.sh'
|
|
265
|
-
const DEV_INIT_SCRIPT = 'fabrika/dev-init.generated.sh'
|
|
266
|
-
const PLATFORM_TSCONFIG = 'fabrika/tsconfig.platform.json'
|
|
267
|
-
|
|
268
|
-
/** The compiler options of the platform's type check; the application's own `tsconfig.json` and its `paths` are not read. */
|
|
269
|
-
const PLATFORM_TSCONFIG_CONTENTS = JSON.stringify({
|
|
270
|
-
compilerOptions: {
|
|
271
|
-
target: 'ES2022',
|
|
272
|
-
module: 'ESNext',
|
|
273
|
-
moduleResolution: 'bundler',
|
|
274
|
-
lib: ['ES2022', 'DOM', 'DOM.Iterable'],
|
|
275
|
-
types: ['bun'],
|
|
276
|
-
strict: true,
|
|
277
|
-
noUncheckedIndexedAccess: true,
|
|
278
|
-
noImplicitOverride: true,
|
|
279
|
-
forceConsistentCasingInFileNames: true,
|
|
280
|
-
skipLibCheck: true,
|
|
281
|
-
resolveJsonModule: true,
|
|
282
|
-
isolatedModules: true,
|
|
283
|
-
noEmit: true,
|
|
284
|
-
},
|
|
285
|
-
include: ['../fabrika.contract.ts', '../src', 'entry.generated.ts'],
|
|
286
|
-
})
|
|
287
241
|
|
|
288
242
|
/** One `printf` writing `lines` to `path`. Each line is single-quoted, so it may hold neither `'` nor an expansion. */
|
|
289
243
|
const writeFileCommand = (path: string, lines: readonly string[]): string => {
|
|
@@ -293,111 +247,6 @@ const writeFileCommand = (path: string, lines: readonly string[]): string => {
|
|
|
293
247
|
return `printf '%s\\n' ${lines.map((line) => `'${line}'`).join(' ')} > ${path}`
|
|
294
248
|
}
|
|
295
249
|
|
|
296
|
-
const migrateScript = (appId: string): readonly string[] => [
|
|
297
|
-
'#!/bin/sh',
|
|
298
|
-
'set -eu',
|
|
299
|
-
`cd ${RUNTIME_ROOT}`,
|
|
300
|
-
`FABRIKA_APP_ID=${appId} exec ${FABRIKA_BIN} db migrate`,
|
|
301
|
-
]
|
|
302
|
-
|
|
303
|
-
// The committed schema types must match the migrated schema and every generated isolation test must pass on a throwaway
|
|
304
|
-
// schema. The build has no database, so they run at container start, after the migrations, as init commands: a failed
|
|
305
|
-
// init command stops the activation, and the readiness window opens only with `run.start`, after the init commands (both
|
|
306
|
-
// verified live), so a run as long as the CRM's ~3 minutes of generated cases does not race it.
|
|
307
|
-
const verifyScript = (appId: string): readonly string[] => [
|
|
308
|
-
'#!/bin/sh',
|
|
309
|
-
'set -eu',
|
|
310
|
-
`cd ${RUNTIME_ROOT}`,
|
|
311
|
-
`FABRIKA_APP_ID=${appId} ${FABRIKA_BIN} db codegen --verify`,
|
|
312
|
-
`FABRIKA_APP_ID=${appId} exec ${FABRIKA_BIN} db test-isolation`,
|
|
313
|
-
]
|
|
314
|
-
|
|
315
|
-
// The readiness check is retried no sooner than every 10 s (the platform's floor), and a server is rarely listening at
|
|
316
|
-
// the first attempt, one second after `run.start`. So one attempt waits for the health endpoint itself, for less than
|
|
317
|
-
// the retry period; it passes only on a 2xx, like the `httpGet` it replaces.
|
|
318
|
-
const readinessCommand = (path: string): string => {
|
|
319
|
-
if (!READINESS_PATH_PATTERN.test(path)) throw new Error('zerops: a readiness path must be a literal path of unreserved characters')
|
|
320
|
-
const url = `http://127.0.0.1:${ZEROPS_APPLICATION_PORT}${path}`
|
|
321
|
-
return `bun -e "const end = Date.now() + 9000; while (Date.now() < end) { try { if ((await fetch('${url}', { signal: AbortSignal.timeout(2000) })).ok) process.exit(0) } catch {} await Bun.sleep(200) } process.exit(1)"`
|
|
322
|
-
}
|
|
323
|
-
|
|
324
|
-
const SERVE_ENTRY = 'fabrika/entry.generated.ts'
|
|
325
|
-
|
|
326
|
-
const startScript: readonly string[] = ['#!/bin/sh', 'set -eu', `cd ${RUNTIME_ROOT}`, `exec bun ${SERVE_ENTRY}`]
|
|
327
|
-
|
|
328
|
-
// A dev environment starts the launcher of the application's own framework release, which runs the serving entry as its
|
|
329
|
-
// child. Double quotes inside: a generated file line may hold no single quote.
|
|
330
|
-
const devStartScript: readonly string[] = [
|
|
331
|
-
'#!/bin/sh',
|
|
332
|
-
'set -eu',
|
|
333
|
-
`cd ${RUNTIME_ROOT}`,
|
|
334
|
-
`exec bun -e "await import(\\"${DEV_LAUNCHER_MODULE}\\").then((dev) => dev.runDevLauncher(process.env))"`,
|
|
335
|
-
]
|
|
336
|
-
|
|
337
|
-
// The init commands of a dev container migrate and verify only what the bootstrap run built. A container that restarts
|
|
338
|
-
// after a stop keeps the files the launcher synced since, and its state file: the launcher reconciles that one itself.
|
|
339
|
-
const devInitScript: readonly string[] = [
|
|
340
|
-
'#!/bin/sh',
|
|
341
|
-
'set -eu',
|
|
342
|
-
`cd ${RUNTIME_ROOT}`,
|
|
343
|
-
`if [ -f ${DEV_LAUNCHER_STATE_FILE} ]; then exit 0; fi`,
|
|
344
|
-
`sh ${RUNTIME_ROOT}/${MIGRATE_SCRIPT}`,
|
|
345
|
-
`sh ${RUNTIME_ROOT}/${VERIFY_SCRIPT}`,
|
|
346
|
-
]
|
|
347
|
-
|
|
348
|
-
/** One command writing `content` to `path` through base64: the content may hold quotes and expansions, the command none. */
|
|
349
|
-
const writeBase64Command = (path: string, content: string): string => {
|
|
350
|
-
const encoded = btoa(String.fromCharCode(...new TextEncoder().encode(content)))
|
|
351
|
-
return `printf '%s' '${encoded}' | base64 -d > ${path}`
|
|
352
|
-
}
|
|
353
|
-
|
|
354
|
-
/** The build's check chain as the dev launcher runs it in the application root, on what the container holds. */
|
|
355
|
-
const devChecks = (release: string): DevLauncherConfig['checks'] => [
|
|
356
|
-
{ name: 'tests', command: 'bun test --isolate --pass-with-no-tests' },
|
|
357
|
-
{ name: 'fabrika-check', command: `cd /tmp && bun x --bun -p @fabrika/check@${release} fabrika-check ${RUNTIME_ROOT}` },
|
|
358
|
-
{ name: 'tsc', command: `cd /tmp && bun x --bun -p typescript@${PLATFORM_TYPESCRIPT_VERSION} tsc -p ${RUNTIME_ROOT}/${PLATFORM_TSCONFIG}` },
|
|
359
|
-
]
|
|
360
|
-
|
|
361
|
-
/** What the dev launcher reads (`DEV_LAUNCHER_CONFIG_FILE`): the platform's, written after the checks. */
|
|
362
|
-
export function devLauncherConfig(execution: ZeropsLockedExecution, authoredSpa: readonly string[]): DevLauncherConfig {
|
|
363
|
-
const dev = execution.dev
|
|
364
|
-
if (dev === undefined) throw new Error('zerops: a dev launcher configuration needs a dev environment')
|
|
365
|
-
if (!/^[0-9a-f]{40}$/.test(dev.head)) throw new Error('zerops: a dev environment builds an exact commit')
|
|
366
|
-
return {
|
|
367
|
-
format: 1,
|
|
368
|
-
appId: execution.appId,
|
|
369
|
-
head: dev.head,
|
|
370
|
-
port: ZEROPS_APPLICATION_PORT,
|
|
371
|
-
healthPath: execution.contract.readinessPath,
|
|
372
|
-
serve: ['bun', SERVE_ENTRY],
|
|
373
|
-
migrate: [FABRIKA_BIN, 'db', 'migrate'],
|
|
374
|
-
spaBuild: authoredSpa,
|
|
375
|
-
checks: devChecks(execution.checkRelease),
|
|
376
|
-
}
|
|
377
|
-
}
|
|
378
|
-
|
|
379
|
-
const devLauncherConfigJson = (execution: ZeropsLockedExecution, authoredSpa: readonly string[]): string =>
|
|
380
|
-
JSON.stringify(devLauncherConfig(execution, authoredSpa))
|
|
381
|
-
|
|
382
|
-
/** The scripts the build writes, and the ones every container's init commands run, in this order. */
|
|
383
|
-
const initScripts = (execution: ZeropsLockedExecution): readonly { readonly path: string; readonly lines: readonly string[] }[] =>
|
|
384
|
-
execution.databaseUrl === null
|
|
385
|
-
? []
|
|
386
|
-
: [
|
|
387
|
-
{ path: MIGRATE_SCRIPT, lines: migrateScript(execution.appId) },
|
|
388
|
-
{ path: VERIFY_SCRIPT, lines: verifyScript(execution.appId) },
|
|
389
|
-
...(execution.dev === undefined ? [] : [{ path: DEV_INIT_SCRIPT, lines: devInitScript }]),
|
|
390
|
-
]
|
|
391
|
-
|
|
392
|
-
const initCommandScripts = (execution: ZeropsLockedExecution): readonly string[] =>
|
|
393
|
-
execution.databaseUrl === null ? [] : execution.dev === undefined ? [MIGRATE_SCRIPT, VERIFY_SCRIPT] : [DEV_INIT_SCRIPT]
|
|
394
|
-
|
|
395
|
-
const INSTALL = 'bun install --frozen-lockfile --ignore-scripts'
|
|
396
|
-
|
|
397
|
-
// After every check: a map is uploaded only for a build that can deploy. A failed upload never fails the build; the
|
|
398
|
-
// provider reads the state from the report line.
|
|
399
|
-
const sourceMapUpload = (release: string): string => `cd /tmp && bun x --bun -p @fabrika/check@${release} fabrika-source-maps ${SOURCE_ROOT} || true`
|
|
400
|
-
|
|
401
250
|
/**
|
|
402
251
|
* The upload's build variables: the destination and asset roots as a literal, and the bearer lifted from the service
|
|
403
252
|
* variable the deploy wrote sensitive, so the descriptor never holds it.
|
|
@@ -409,28 +258,34 @@ const sourceMapBuildVariables = (upload: OperationsSourceMapBuildUpload): Record
|
|
|
409
258
|
return { [FABRIKA_SOURCE_MAP_UPLOAD]: value, [FABRIKA_SOURCE_MAP_UPLOAD_KEY]: `\${RUNTIME_${FABRIKA_SOURCE_MAP_UPLOAD_KEY}}` }
|
|
410
259
|
}
|
|
411
260
|
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
261
|
+
// The readiness check is retried no sooner than every 10 s (the platform's floor), and a server is rarely listening at
|
|
262
|
+
// the first attempt, one second after `run.start`. So one attempt waits for the health endpoint itself, for less than
|
|
263
|
+
// the retry period; it passes only on a 2xx, like the `httpGet` it replaces.
|
|
264
|
+
const readinessCommand = (path: string): string => {
|
|
265
|
+
if (!READINESS_PATH_PATTERN.test(path)) throw new Error('zerops: a readiness path must be a literal path of unreserved characters')
|
|
266
|
+
const url = `http://127.0.0.1:${ZEROPS_APPLICATION_PORT}${path}`
|
|
267
|
+
return `bun -e "const end = Date.now() + 9000; while (Date.now() < end) { try { if ((await fetch('${url}', { signal: AbortSignal.timeout(2000) })).ok) process.exit(0) } catch {} await Bun.sleep(200) } process.exit(1)"`
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
/** `@fabrika/app/build`'s recipe at this installation's paths. */
|
|
271
|
+
const recipeOf = (execution: ZeropsLockedExecution): ContractRecipe =>
|
|
272
|
+
contractRecipe({
|
|
273
|
+
appId: execution.appId,
|
|
274
|
+
checkRelease: execution.checkRelease,
|
|
275
|
+
sourceRoot: SOURCE_ROOT,
|
|
276
|
+
runtimeRoot: RUNTIME_ROOT,
|
|
277
|
+
// The build has no database; a container's init commands run the migrations and schema checks, and the readiness
|
|
278
|
+
// window opens only with `run.start`, after them (both verified live), so the CRM's ~3 minutes does not race it.
|
|
279
|
+
database: execution.databaseUrl !== null,
|
|
280
|
+
sourceMaps: execution.sourceMaps !== null,
|
|
281
|
+
jobs: execution.contract.jobs,
|
|
282
|
+
files: execution.contract.files === true,
|
|
283
|
+
scan: execution.contract.scan === true,
|
|
284
|
+
})
|
|
285
|
+
|
|
286
|
+
/** The generated build commands, in order; the authored SPA commands run before all of them. */
|
|
287
|
+
export function generatedBuildCommands(execution: ZeropsLockedExecution): readonly string[] {
|
|
288
|
+
return recipeOf(execution).build.map((step) => 'run' in step ? step.run : writeFileCommand(step.write, step.lines))
|
|
434
289
|
}
|
|
435
290
|
|
|
436
291
|
const sortedUnique = (values: readonly string[]): string[] => [...new Set(values)].sort()
|
|
@@ -446,16 +301,11 @@ const storageVariables = (hostname: string): Record<StorageVariable, string> =>
|
|
|
446
301
|
})
|
|
447
302
|
|
|
448
303
|
/** The crontab lines that run a job of the contract or of the framework, each on one container. */
|
|
449
|
-
const jobCrontab = (
|
|
450
|
-
|
|
451
|
-
...(contract.files === true
|
|
452
|
-
? [{ timing: FILE_SWEEP_SCHEDULE, command: `${FABRIKA_BIN} job run ${ZEROPS_FILE_SWEEP_JOB}`, allContainers: false }]
|
|
453
|
-
: []),
|
|
454
|
-
...(contract.scan === true ? [{ timing: '* * * * *', command: `${FABRIKA_BIN} job run ${ZEROPS_FILE_SCAN_JOB}`, allContainers: false }] : []),
|
|
455
|
-
]
|
|
304
|
+
const jobCrontab = (execution: ZeropsLockedExecution): { readonly timing: string; readonly command: string; readonly allContainers: boolean }[] =>
|
|
305
|
+
recipeOf(execution).jobs.map((job) => ({ timing: job.schedule, command: job.command, allContainers: false }))
|
|
456
306
|
|
|
457
307
|
/** How many job processes the crontab may run at once, each opening the application's database. */
|
|
458
|
-
export const zeropsJobProcesses = (
|
|
308
|
+
export const zeropsJobProcesses = (execution: ZeropsLockedExecution): number => jobCrontab(execution).length
|
|
459
309
|
|
|
460
310
|
/** The commands every container runs before `run.start`, in order; any failure stops the activation. */
|
|
461
311
|
export function generatedInitCommands(execution: ZeropsLockedExecution): string[] {
|
|
@@ -463,7 +313,7 @@ export function generatedInitCommands(execution: ZeropsLockedExecution): string[
|
|
|
463
313
|
// A container starts from the prepared image, whose signatures are as old as its build; a failed refresh leaves
|
|
464
314
|
// them to the daily one, and the scanner refuses signatures older than three days, so the scan fails closed.
|
|
465
315
|
...(execution.contract.scan === true ? [`${FRESHCLAM} || echo 'fabrika: freshclam did not refresh the malware signatures'`] : []),
|
|
466
|
-
...
|
|
316
|
+
...recipeOf(execution).init.map((path) => `sh ${RUNTIME_ROOT}/${path}`),
|
|
467
317
|
]
|
|
468
318
|
}
|
|
469
319
|
|
|
@@ -488,7 +338,7 @@ export function renderLockedSetup(
|
|
|
488
338
|
const scan = contract.scan === true
|
|
489
339
|
const packages = sortedUnique([...execution.runtimePackages, ...(scan ? [SCANNER_PACKAGE] : [])])
|
|
490
340
|
// Every container keeps its own signatures; one scan pass at a time holds the job's lease.
|
|
491
|
-
const crontab = [...jobCrontab(
|
|
341
|
+
const crontab = [...jobCrontab(execution), ...(scan ? [{ timing: FRESHCLAM_SCHEDULE, command: FRESHCLAM, allContainers: true }] : [])]
|
|
492
342
|
const initCommands = generatedInitCommands(execution)
|
|
493
343
|
const prepareCommands = packages.length === 0 ? [] : [`sudo apk add --no-cache ${packages.join(' ')}`, ...(scan ? [FRESHCLAM] : [])]
|
|
494
344
|
return {
|
|
@@ -496,25 +346,25 @@ export function renderLockedSetup(
|
|
|
496
346
|
build: {
|
|
497
347
|
base: authored.base ?? [ZEROPS_APPLICATION_RUNTIME],
|
|
498
348
|
...(authored.os === null ? {} : { os: authored.os }),
|
|
499
|
-
buildCommands: [...authored.commands, ...generatedBuildCommands(execution
|
|
349
|
+
buildCommands: [...authored.commands, ...generatedBuildCommands(execution)],
|
|
500
350
|
...(execution.sourceMaps === null ? {} : { envVariables: sourceMapBuildVariables(execution.sourceMaps) }),
|
|
501
351
|
deployFiles: ['./'],
|
|
502
352
|
cache: ['node_modules'],
|
|
503
353
|
},
|
|
504
354
|
deploy: {
|
|
505
|
-
readinessCheck: {
|
|
355
|
+
readinessCheck: {
|
|
356
|
+
exec: { command: readinessCommand(contract.readinessPath) },
|
|
357
|
+
retryPeriod: '10s',
|
|
358
|
+
failureTimeout: '180s',
|
|
359
|
+
},
|
|
506
360
|
},
|
|
507
361
|
run: {
|
|
508
362
|
base: ZEROPS_APPLICATION_RUNTIME,
|
|
509
363
|
...(prepareCommands.length === 0 ? {} : { prepareCommands }),
|
|
510
364
|
...(initCommands.length === 0 ? {} : { initCommands }),
|
|
511
|
-
start: `sh ${RUNTIME_ROOT}/${
|
|
365
|
+
start: `sh ${RUNTIME_ROOT}/${recipeOf(execution).start}`,
|
|
512
366
|
ports: [{ port: ZEROPS_APPLICATION_PORT, httpSupport: true }],
|
|
513
|
-
|
|
514
|
-
// would only boot the same failing head again.
|
|
515
|
-
...(execution.dev === undefined
|
|
516
|
-
? { healthCheck: { httpGet: probe, execPeriod: '10s', disconnectTimeout: '30s', recoveryTimeout: '10s', failureTimeout: '120s' } }
|
|
517
|
-
: {}),
|
|
367
|
+
healthCheck: { httpGet: probe, execPeriod: '10s', disconnectTimeout: '30s', recoveryTimeout: '10s', failureTimeout: '120s' },
|
|
518
368
|
...(crontab.length === 0 ? {} : { crontab }),
|
|
519
369
|
envVariables,
|
|
520
370
|
},
|
package/src/index.ts
CHANGED
|
@@ -15,10 +15,10 @@ import {
|
|
|
15
15
|
ensureFirstAdministrator,
|
|
16
16
|
type FirstAdministratorApi,
|
|
17
17
|
type FirstAdministratorResult,
|
|
18
|
+
platformOrigin,
|
|
18
19
|
} from '@fabrika/installation-init'
|
|
19
20
|
import type { PlatformAdminInput } from './admin-options'
|
|
20
21
|
import { REISSUE_FLAG } from './admin-options'
|
|
21
|
-
import { platformOrigin } from './hosts'
|
|
22
22
|
import { MACHINE_KEY_NEXT_STEP_TITLE, machineKeyNextStepLines } from './machine-key'
|
|
23
23
|
|
|
24
24
|
/**
|
|
@@ -12,9 +12,10 @@
|
|
|
12
12
|
// The command is unattended by construction: nothing here prompts, and a missing required value is an
|
|
13
13
|
// error naming both the flag and the variable that would supply it.
|
|
14
14
|
|
|
15
|
-
import { describeArgument, readEnv, requiredSetting, setting } from '@fabrika/installation-init'
|
|
16
|
-
import {
|
|
15
|
+
import { describeArgument, type McpClient, parseMcpClientsJson, readEnv, requiredSetting, setting } from '@fabrika/installation-init'
|
|
16
|
+
import { PLATFORM_DEPLOY_ORDER } from './deploy'
|
|
17
17
|
import { parsePlatformHosts, parsePlatformScheme } from './placement-options'
|
|
18
|
+
import { parsePlainVariables } from './plain-credentials'
|
|
18
19
|
import { readInstallationSourceDir } from './source-options'
|
|
19
20
|
|
|
20
21
|
/** How the project this installation lives in is named. */
|
|
@@ -40,6 +41,11 @@ export interface PlatformDeployInput {
|
|
|
40
41
|
readonly mcpClients?: readonly McpClient[]
|
|
41
42
|
/** IAM-issued `px_` admin key, used only to reconcile the console's schema. Environment only. */
|
|
42
43
|
readonly iamAdminKey: string
|
|
44
|
+
/**
|
|
45
|
+
* Readable service variables, as `<service>/<KEY>`, the operator has checked are not credentials. The deploy refuses
|
|
46
|
+
* every other readable variable that looks like one (`plain-credentials.ts`).
|
|
47
|
+
*/
|
|
48
|
+
readonly plainVariables?: ReadonlySet<string>
|
|
43
49
|
/** Read everything, write nothing, trigger nothing. */
|
|
44
50
|
readonly dryRun: boolean
|
|
45
51
|
}
|
|
@@ -55,6 +61,7 @@ const FLAGS = [
|
|
|
55
61
|
'--scheme',
|
|
56
62
|
'--source-dir',
|
|
57
63
|
'--mcp-clients',
|
|
64
|
+
'--plain-variables',
|
|
58
65
|
] as const
|
|
59
66
|
|
|
60
67
|
const assertKnownArguments = (argv: readonly string[]): void => {
|
|
@@ -129,6 +136,7 @@ export const parsePlatformDeployArgs = (
|
|
|
129
136
|
? readEnv(env, 'FABRIKA_IAM_PROVISIONING_KEY') ?? ''
|
|
130
137
|
: requiredSetting(readEnv(env, 'FABRIKA_IAM_PROVISIONING_KEY'), '(no flag)', 'FABRIKA_IAM_PROVISIONING_KEY'),
|
|
131
138
|
scheme,
|
|
139
|
+
plainVariables: parsePlainVariables(setting(argv, env, '--plain-variables', 'FABRIKA_PLATFORM_PLAIN_VARIABLES'), PLATFORM_DEPLOY_ORDER),
|
|
132
140
|
dryRun,
|
|
133
141
|
...(hosts === undefined ? {} : { hosts }),
|
|
134
142
|
sourceDir,
|