@fabrika/provider-zerops 0.9.0-dev.4 → 0.9.0-dev.6
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 +10 -9
- package/src/api/client.ts +12 -0
- 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 +9 -57
- package/src/execution.ts +63 -185
- package/src/index.ts +2 -0
- package/src/installation/admin.ts +1 -1
- package/src/installation/deploy-options.ts +1 -2
- package/src/installation/deploy.ts +225 -80
- 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 +48 -18
- package/src/installation/hosts.ts +1 -7
- package/src/installation/index.ts +13 -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/sidecar.ts +5 -26
- package/src/installation/topology/setups.ts +15 -4
- package/src/installation/topology/topology.ts +31 -21
- package/src/installation/upgrade-options.ts +2 -2
- package/src/managed-env.ts +1 -174
- package/src/manifest.ts +2 -9
- package/src/namespace/claims.ts +56 -1
- package/src/namespace/errors.ts +1 -1
- package/src/namespace/manifest.ts +6 -19
- package/src/namespace/provisioning.ts +20 -2
- package/src/namespace/proxy-attempt.ts +14 -2
- package/src/namespace/proxy-reads.ts +12 -22
- package/src/namespace/types.ts +2 -0
- package/src/namespace-cli.ts +152 -0
- package/src/plan.ts +1 -6
- package/src/provider.ts +39 -93
- package/src/proxy-manifest-carrier.ts +18 -0
- package/src/types.ts +0 -2
- package/types/src/api/readers.d.ts +148 -10
- package/types/src/api/types.d.ts +49 -0
- package/types/src/api.d.ts +1 -1
- package/types/src/cli.d.ts +3 -0
- package/types/src/collaborators.d.ts +0 -2
- package/types/src/compile.d.ts +1 -1
- package/types/src/control.d.ts +3 -4
- package/types/src/execution.d.ts +5 -17
- package/types/src/index.d.ts +1 -1
- package/types/src/installation/deploy-options.d.ts +1 -1
- package/types/src/installation/deploy.d.ts +40 -0
- package/types/src/installation/generated/platform-proxy-manifest.d.ts +1 -1
- package/types/src/installation/hosts.d.ts +1 -5
- package/types/src/installation/index.d.ts +0 -2
- package/types/src/installation/install-environment.d.ts +11 -18
- package/types/src/installation/install-secrets.d.ts +3 -16
- package/types/src/installation/sidecar.d.ts +0 -2
- package/types/src/installation/topology/installation-schemas.d.ts +94 -94
- package/types/src/installation/topology/setups.d.ts +2 -1
- package/types/src/installation/topology/topology.d.ts +15 -10
- package/types/src/managed-env.d.ts +0 -33
- package/types/src/manifest.d.ts +0 -2
- package/types/src/namespace/claims.d.ts +14 -1
- package/types/src/namespace/codec.d.ts +4 -4
- package/types/src/namespace/errors.d.ts +1 -1
- package/types/src/namespace/proxy-attempt.d.ts +3 -0
- package/types/src/namespace/proxy-reads.d.ts +4 -15
- package/types/src/namespace/types.d.ts +2 -0
- package/types/src/namespace-cli.d.ts +2 -0
- package/types/src/plan.d.ts +2 -3
- package/types/src/provider.d.ts +0 -2
- package/types/src/proxy-manifest-carrier.d.ts +8 -0
- package/types/src/types.d.ts +0 -2
- package/src/installation/mcp.ts +0 -102
- package/src/installation/proxy-manifest.ts +0 -214
- package/src/installation/secrets.ts +0 -78
- package/types/src/installation/mcp.d.ts +0 -18
- package/types/src/installation/proxy-manifest.d.ts +0 -105
- package/types/src/installation/secrets.d.ts +0 -17
package/src/execution.ts
CHANGED
|
@@ -2,11 +2,12 @@
|
|
|
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,
|
|
8
|
+
DEV_LAUNCHER_BOOTED_FILE,
|
|
7
9
|
DEV_LAUNCHER_CONFIG_FILE,
|
|
8
10
|
DEV_LAUNCHER_MODULE,
|
|
9
|
-
DEV_LAUNCHER_STATE_FILE,
|
|
10
11
|
type DevLauncherConfig,
|
|
11
12
|
FABRIKA_CONTRACT_DIGEST,
|
|
12
13
|
FABRIKA_SOURCE_MAP_UPLOAD,
|
|
@@ -14,7 +15,7 @@ import {
|
|
|
14
15
|
type FrameworkVariableName,
|
|
15
16
|
} from '@fabrika/auth-core'
|
|
16
17
|
import type { OperationsAssetRoot, OperationsSourceMapBuildUpload } from '@fabrika/operations-contract/releases'
|
|
17
|
-
import {
|
|
18
|
+
import type { JsonValue } from '@fabrika/provider-contract'
|
|
18
19
|
import packageManifest from '../package.json'
|
|
19
20
|
import { renderYaml } from './compile'
|
|
20
21
|
import { parseZeropsDescriptor, type PreparedZeropsDescriptor, selectZeropsDescriptorSetup } from './descriptor'
|
|
@@ -33,8 +34,7 @@ export const ZEROPS_APPLICATION_RUNTIME = 'alpine/bun@1.3'
|
|
|
33
34
|
*/
|
|
34
35
|
export const FABRIKA_CHECK_VERSION: string = packageManifest.version
|
|
35
36
|
|
|
36
|
-
|
|
37
|
-
export const PLATFORM_TYPESCRIPT_VERSION = '5.9.3'
|
|
37
|
+
export { PLATFORM_TYPESCRIPT_VERSION } from '@fabrika/app/build'
|
|
38
38
|
|
|
39
39
|
/** System packages an application may add to its runtime image, installed by the generated `run.prepareCommands`. */
|
|
40
40
|
export const ZEROPS_RUNTIME_PACKAGES = ['ffmpeg', 'ghostscript', 'imagemagick', 'poppler-utils', 'vips'] as const
|
|
@@ -46,12 +46,6 @@ export interface ZeropsContractJob {
|
|
|
46
46
|
readonly schedule: string
|
|
47
47
|
}
|
|
48
48
|
|
|
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
49
|
/**
|
|
56
50
|
* The RAM in GB a container of a scanning application starts with: one `clamscan` over a batch peaks at about 1 GB
|
|
57
51
|
* resident while it loads its signatures (measured with ClamAV 1.4), beside the application's own process.
|
|
@@ -124,7 +118,7 @@ export interface ZeropsDevExecution {
|
|
|
124
118
|
}
|
|
125
119
|
|
|
126
120
|
/** The application ids the generated scripts may name: the contract's own id rule, so a script needs no quoting. */
|
|
127
|
-
export
|
|
121
|
+
export { CONTRACT_APP_ID_PATTERN as LOCKED_APP_ID_PATTERN } from '@fabrika/app/build'
|
|
128
122
|
|
|
129
123
|
export const CONTRACT_DIGEST_PATTERN = /^sha256:[0-9a-f]{64}$/
|
|
130
124
|
|
|
@@ -258,36 +252,6 @@ export function lockedAuthoredBuild(entry: { readonly [key: string]: JsonValue }
|
|
|
258
252
|
|
|
259
253
|
const SOURCE_ROOT = '/build/source'
|
|
260
254
|
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
|
-
/**
|
|
269
|
-
* The compiler options of the platform's type check; the application's own `tsconfig.json` and its `paths` are not read.
|
|
270
|
-
* It covers the SPA under `web/` too: Bun bundles the SPA without checking its types.
|
|
271
|
-
*/
|
|
272
|
-
const PLATFORM_TSCONFIG_CONTENTS = JSON.stringify({
|
|
273
|
-
compilerOptions: {
|
|
274
|
-
target: 'ES2022',
|
|
275
|
-
module: 'ESNext',
|
|
276
|
-
moduleResolution: 'bundler',
|
|
277
|
-
lib: ['ES2022', 'DOM', 'DOM.Iterable'],
|
|
278
|
-
jsx: 'react-jsx',
|
|
279
|
-
types: ['bun'],
|
|
280
|
-
strict: true,
|
|
281
|
-
noUncheckedIndexedAccess: true,
|
|
282
|
-
noImplicitOverride: true,
|
|
283
|
-
forceConsistentCasingInFileNames: true,
|
|
284
|
-
skipLibCheck: true,
|
|
285
|
-
resolveJsonModule: true,
|
|
286
|
-
isolatedModules: true,
|
|
287
|
-
noEmit: true,
|
|
288
|
-
},
|
|
289
|
-
include: ['../fabrika.contract.ts', '../src', '../web', 'entry.generated.ts'],
|
|
290
|
-
})
|
|
291
255
|
|
|
292
256
|
/** One `printf` writing `lines` to `path`. Each line is single-quoted, so it may hold neither `'` nor an expansion. */
|
|
293
257
|
const writeFileCommand = (path: string, lines: readonly string[]): string => {
|
|
@@ -297,37 +261,45 @@ const writeFileCommand = (path: string, lines: readonly string[]): string => {
|
|
|
297
261
|
return `printf '%s\\n' ${lines.map((line) => `'${line}'`).join(' ')} > ${path}`
|
|
298
262
|
}
|
|
299
263
|
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
// verified live), so a run as long as the CRM's ~3 minutes of generated cases does not race it.
|
|
311
|
-
const verifyScript = (appId: string): readonly string[] => [
|
|
312
|
-
'#!/bin/sh',
|
|
313
|
-
'set -eu',
|
|
314
|
-
`cd ${RUNTIME_ROOT}`,
|
|
315
|
-
`FABRIKA_APP_ID=${appId} ${FABRIKA_BIN} db codegen --verify`,
|
|
316
|
-
`FABRIKA_APP_ID=${appId} exec ${FABRIKA_BIN} db test-isolation`,
|
|
317
|
-
]
|
|
264
|
+
/**
|
|
265
|
+
* The upload's build variables: the destination and asset roots as a literal, and the bearer lifted from the service
|
|
266
|
+
* variable the deploy wrote sensitive, so the descriptor never holds it.
|
|
267
|
+
*/
|
|
268
|
+
const sourceMapBuildVariables = (upload: OperationsSourceMapBuildUpload): Record<string, string> => {
|
|
269
|
+
const value = JSON.stringify(upload)
|
|
270
|
+
// Zerops resolves `${…}` in a build variable, so an SPA directory carrying one would read another variable.
|
|
271
|
+
if (value.includes('${')) throw new Error('zerops: an SPA directory or prefix must not contain `${`')
|
|
272
|
+
return { [FABRIKA_SOURCE_MAP_UPLOAD]: value, [FABRIKA_SOURCE_MAP_UPLOAD_KEY]: `\${RUNTIME_${FABRIKA_SOURCE_MAP_UPLOAD_KEY}}` }
|
|
273
|
+
}
|
|
318
274
|
|
|
319
275
|
// The readiness check is retried no sooner than every 10 s (the platform's floor), and a server is rarely listening at
|
|
320
276
|
// the first attempt, one second after `run.start`. So one attempt waits for the health endpoint itself, for less than
|
|
321
|
-
// the retry period; it passes only on a 2xx, like the `httpGet` it replaces.
|
|
322
|
-
|
|
277
|
+
// the retry period; it passes only on a 2xx, like the `httpGet` it replaces. A dev container also passes once its launcher
|
|
278
|
+
// reported the boot, served or failed: the launcher keeps running and reports a failed migration with its remedy.
|
|
279
|
+
const readinessCommand = (path: string, dev: boolean): string => {
|
|
323
280
|
if (!READINESS_PATH_PATTERN.test(path)) throw new Error('zerops: a readiness path must be a literal path of unreserved characters')
|
|
324
281
|
const url = `http://127.0.0.1:${ZEROPS_APPLICATION_PORT}${path}`
|
|
325
|
-
|
|
282
|
+
const booted = dev ? `if (await Bun.file('${RUNTIME_ROOT}/${DEV_LAUNCHER_BOOTED_FILE}').exists()) process.exit(0); ` : ''
|
|
283
|
+
return `bun -e "const end = Date.now() + 9000; while (Date.now() < end) { ${booted}try { if ((await fetch('${url}', { signal: AbortSignal.timeout(2000) })).ok) process.exit(0) } catch {} await Bun.sleep(200) } process.exit(1)"`
|
|
326
284
|
}
|
|
327
285
|
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
286
|
+
/** `@fabrika/app/build`'s recipe at this installation's paths; the dev launcher checks in the runtime root. */
|
|
287
|
+
const recipeOf = (execution: ZeropsLockedExecution, sourceRoot: string = SOURCE_ROOT): ContractRecipe =>
|
|
288
|
+
contractRecipe({
|
|
289
|
+
appId: execution.appId,
|
|
290
|
+
checkRelease: execution.checkRelease,
|
|
291
|
+
sourceRoot,
|
|
292
|
+
runtimeRoot: RUNTIME_ROOT,
|
|
293
|
+
// The build has no database; a container's init commands run the migrations and schema checks, and the readiness
|
|
294
|
+
// window opens only with `run.start`, after them (both verified live), so the CRM's ~3 minutes does not race it.
|
|
295
|
+
// A dev container has none: its init would run before Control says whether a reset is pending, over the schema the
|
|
296
|
+
// previous container left, so its launcher migrates and verifies after that answer.
|
|
297
|
+
database: execution.databaseUrl !== null && execution.dev === undefined,
|
|
298
|
+
sourceMaps: execution.sourceMaps !== null,
|
|
299
|
+
jobs: execution.contract.jobs,
|
|
300
|
+
files: execution.contract.files === true,
|
|
301
|
+
scan: execution.contract.scan === true,
|
|
302
|
+
})
|
|
331
303
|
|
|
332
304
|
// A dev environment starts the launcher of the application's own framework release, which runs the serving entry as its
|
|
333
305
|
// child. Double quotes inside: a generated file line may hold no single quote.
|
|
@@ -338,136 +310,43 @@ const devStartScript: readonly string[] = [
|
|
|
338
310
|
`exec bun -e "await import(\\"${DEV_LAUNCHER_MODULE}\\").then((dev) => dev.runDevLauncher(process.env))"`,
|
|
339
311
|
]
|
|
340
312
|
|
|
341
|
-
// The init commands of a dev container migrate and verify only what the bootstrap run built. A container that restarts
|
|
342
|
-
// after a stop keeps the files the launcher synced since, and its state file: the launcher reconciles that one itself.
|
|
343
|
-
const devInitScript: readonly string[] = [
|
|
344
|
-
'#!/bin/sh',
|
|
345
|
-
'set -eu',
|
|
346
|
-
`cd ${RUNTIME_ROOT}`,
|
|
347
|
-
`if [ -f ${DEV_LAUNCHER_STATE_FILE} ]; then exit 0; fi`,
|
|
348
|
-
`sh ${RUNTIME_ROOT}/${MIGRATE_SCRIPT}`,
|
|
349
|
-
`sh ${RUNTIME_ROOT}/${VERIFY_SCRIPT}`,
|
|
350
|
-
]
|
|
351
|
-
|
|
352
313
|
/** One command writing `content` to `path` through base64: the content may hold quotes and expansions, the command none. */
|
|
353
314
|
const writeBase64Command = (path: string, content: string): string => {
|
|
354
315
|
const encoded = btoa(String.fromCharCode(...new TextEncoder().encode(content)))
|
|
355
316
|
return `printf '%s' '${encoded}' | base64 -d > ${path}`
|
|
356
317
|
}
|
|
357
318
|
|
|
358
|
-
/** The build's check chain, in its order, as the dev launcher runs it in the application root on what the container holds. */
|
|
359
|
-
const devChecks = (release: string): DevLauncherConfig['checks'] => [
|
|
360
|
-
{ name: 'tests', command: TESTS_COMMAND },
|
|
361
|
-
{ name: 'tsc', command: `cd /tmp && bun x --bun -p typescript@${PLATFORM_TYPESCRIPT_VERSION} tsc -p ${RUNTIME_ROOT}/${PLATFORM_TSCONFIG}` },
|
|
362
|
-
{ name: 'fabrika-check', command: `cd /tmp && bun x --bun -p @fabrika/check@${release} fabrika-check ${RUNTIME_ROOT}` },
|
|
363
|
-
]
|
|
364
|
-
|
|
365
319
|
/** What the dev launcher reads (`DEV_LAUNCHER_CONFIG_FILE`): the platform's, written after the checks. */
|
|
366
320
|
export function devLauncherConfig(execution: ZeropsLockedExecution, authoredSpa: readonly string[]): DevLauncherConfig {
|
|
367
321
|
const dev = execution.dev
|
|
368
322
|
if (dev === undefined) throw new Error('zerops: a dev launcher configuration needs a dev environment')
|
|
369
323
|
if (!/^[0-9a-f]{40}$/.test(dev.head)) throw new Error('zerops: a dev environment builds an exact commit')
|
|
324
|
+
const recipe = recipeOf(execution)
|
|
370
325
|
return {
|
|
371
326
|
format: 1,
|
|
372
327
|
appId: execution.appId,
|
|
373
328
|
head: dev.head,
|
|
374
329
|
port: ZEROPS_APPLICATION_PORT,
|
|
375
330
|
healthPath: execution.contract.readinessPath,
|
|
376
|
-
serve:
|
|
377
|
-
migrate:
|
|
331
|
+
serve: recipe.serve,
|
|
332
|
+
migrate: recipe.migrate,
|
|
378
333
|
spaBuild: authoredSpa,
|
|
379
|
-
|
|
334
|
+
// The build's check chain, in its order, on what the container holds.
|
|
335
|
+
checks: recipeOf(execution, RUNTIME_ROOT).checks,
|
|
380
336
|
}
|
|
381
337
|
}
|
|
382
338
|
|
|
383
|
-
|
|
384
|
-
JSON.stringify(devLauncherConfig(execution, authoredSpa))
|
|
385
|
-
|
|
386
|
-
/** The scripts the build writes, and the ones every container's init commands run, in this order. */
|
|
387
|
-
const initScripts = (execution: ZeropsLockedExecution): readonly { readonly path: string; readonly lines: readonly string[] }[] =>
|
|
388
|
-
execution.databaseUrl === null
|
|
389
|
-
? []
|
|
390
|
-
: [
|
|
391
|
-
{ path: MIGRATE_SCRIPT, lines: migrateScript(execution.appId) },
|
|
392
|
-
{ path: VERIFY_SCRIPT, lines: verifyScript(execution.appId) },
|
|
393
|
-
...(execution.dev === undefined ? [] : [{ path: DEV_INIT_SCRIPT, lines: devInitScript }]),
|
|
394
|
-
]
|
|
395
|
-
|
|
396
|
-
const initCommandScripts = (execution: ZeropsLockedExecution): readonly string[] =>
|
|
397
|
-
execution.databaseUrl === null ? [] : execution.dev === undefined ? [MIGRATE_SCRIPT, VERIFY_SCRIPT] : [DEV_INIT_SCRIPT]
|
|
398
|
-
|
|
399
|
-
const INSTALL = 'bun install --frozen-lockfile --ignore-scripts'
|
|
400
|
-
|
|
401
|
-
/**
|
|
402
|
-
* What `@fabrika/db/testing` prints after the label of a test file it skips without `FABRIKA_TEST_POSTGRES_URL`. Every
|
|
403
|
-
* framework release prints it, so the platform counts it for any application's release.
|
|
404
|
-
*/
|
|
405
|
-
const DATABASE_TEST_SKIP_MARKER = ' skipped: set FABRIKA_TEST_POSTGRES_URL to run the Postgres-backed tests'
|
|
406
|
-
|
|
407
|
-
/** The prefix of the line the tests command prints after the test run. */
|
|
408
|
-
const TESTS_REPORT_PREFIX = 'fabrika-tests:'
|
|
409
|
-
|
|
410
|
-
/** One `bun -e "…"` running `script`, which may hold none of the characters a double-quoted shell word expands. */
|
|
411
|
-
const bunEvalCommand = (script: readonly string[]): string => {
|
|
412
|
-
const source = script.join(' ')
|
|
413
|
-
if (/["$`\\!]/.test(source)) throw new Error('zerops: a generated bun -e script must not contain a quote, an expansion or a backslash')
|
|
414
|
-
return `bun -e "${source}"`
|
|
415
|
-
}
|
|
416
|
-
|
|
417
|
-
// The build has no database, so every Postgres-backed test file skips and the run still passes. This command runs the
|
|
418
|
-
// tests as before and then says how many files did not run, so a green test step does not read as a tested database.
|
|
419
|
-
const TESTS_COMMAND = bunEvalCommand([
|
|
420
|
-
"const child = Bun.spawn([process.execPath, 'test', '--isolate', '--pass-with-no-tests'], { stdout: 'inherit', stderr: 'pipe' });",
|
|
421
|
-
'const decoder = new TextDecoder();',
|
|
422
|
-
"let output = '';",
|
|
423
|
-
'for await (const chunk of child.stderr) { process.stderr.write(chunk); output += decoder.decode(chunk, { stream: true }) }',
|
|
424
|
-
'const code = await child.exited;',
|
|
425
|
-
`const marker = '${DATABASE_TEST_SKIP_MARKER}';`,
|
|
426
|
-
'const skipped = output.split(String.fromCharCode(10)).filter((line) => line.includes(marker)).map((line) => line.slice(0, line.indexOf(marker)).trim());',
|
|
427
|
-
`const prefix = '${TESTS_REPORT_PREFIX}';`,
|
|
428
|
-
"console.warn(skipped.length === 0 ? prefix + ' no Postgres-backed test file skipped' : prefix + ' ' + skipped.length + ' Postgres-backed test files did not run, because the build has no database: ' + skipped.join(', '));",
|
|
429
|
-
'process.exit(code);',
|
|
430
|
-
])
|
|
431
|
-
|
|
432
|
-
// After every check: a map is uploaded only for a build that can deploy. A failed upload never fails the build; the
|
|
433
|
-
// provider reads the state from the report line.
|
|
434
|
-
const sourceMapUpload = (release: string): string => `cd /tmp && bun x --bun -p @fabrika/check@${release} fabrika-source-maps ${SOURCE_ROOT} || true`
|
|
435
|
-
|
|
436
|
-
/**
|
|
437
|
-
* The upload's build variables: the destination and asset roots as a literal, and the bearer lifted from the service
|
|
438
|
-
* variable the deploy wrote sensitive, so the descriptor never holds it.
|
|
439
|
-
*/
|
|
440
|
-
const sourceMapBuildVariables = (upload: OperationsSourceMapBuildUpload): Record<string, string> => {
|
|
441
|
-
const value = JSON.stringify(upload)
|
|
442
|
-
// Zerops resolves `${…}` in a build variable, so an SPA directory carrying one would read another variable.
|
|
443
|
-
if (value.includes('${')) throw new Error('zerops: an SPA directory or prefix must not contain `${`')
|
|
444
|
-
return { [FABRIKA_SOURCE_MAP_UPLOAD]: value, [FABRIKA_SOURCE_MAP_UPLOAD_KEY]: `\${RUNTIME_${FABRIKA_SOURCE_MAP_UPLOAD_KEY}}` }
|
|
445
|
-
}
|
|
446
|
-
|
|
447
|
-
/**
|
|
448
|
-
* The generated build commands, in order; the authored SPA commands run before all of them. The application's tests
|
|
449
|
-
* run first: they are authored code, so everything after them is reinstalled, regenerated or checked again. They run
|
|
450
|
-
* `--isolate`, as the application skill runs them: a test file's DOM globals otherwise leak into the next file. `tsc`
|
|
451
|
-
* runs before the checker, as in the skill's loop: the usual quick fix of a type error is a cast or an `any`, which only
|
|
452
|
-
* the checker refuses, so the checker is the last word on the code.
|
|
453
|
-
*/
|
|
339
|
+
/** The generated build commands, in order; the authored SPA commands run before all of them. */
|
|
454
340
|
export function generatedBuildCommands(execution: ZeropsLockedExecution, authoredSpa: readonly string[] = []): readonly string[] {
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
`cd /tmp && bun x --bun -p @fabrika/check@${execution.checkRelease} fabrika-check ${SOURCE_ROOT}`,
|
|
465
|
-
...initScripts(execution).map((script) => writeFileCommand(script.path, script.lines)),
|
|
466
|
-
...(execution.dev === undefined
|
|
467
|
-
? [writeFileCommand(START_SCRIPT, startScript)]
|
|
468
|
-
: [writeFileCommand(START_SCRIPT, devStartScript), writeBase64Command(DEV_LAUNCHER_CONFIG_FILE, devLauncherConfigJson(execution, authoredSpa))]),
|
|
469
|
-
...(execution.sourceMaps === null ? [] : [sourceMapUpload(execution.checkRelease)]),
|
|
470
|
-
]
|
|
341
|
+
const recipe = recipeOf(execution)
|
|
342
|
+
return recipe.build.flatMap((step) => {
|
|
343
|
+
if ('run' in step) return [step.run]
|
|
344
|
+
if (execution.dev === undefined || step.write !== recipe.start) return [writeFileCommand(step.write, step.lines)]
|
|
345
|
+
return [
|
|
346
|
+
writeFileCommand(recipe.start, devStartScript),
|
|
347
|
+
writeBase64Command(DEV_LAUNCHER_CONFIG_FILE, JSON.stringify(devLauncherConfig(execution, authoredSpa))),
|
|
348
|
+
]
|
|
349
|
+
})
|
|
471
350
|
}
|
|
472
351
|
|
|
473
352
|
const sortedUnique = (values: readonly string[]): string[] => [...new Set(values)].sort()
|
|
@@ -483,16 +362,11 @@ const storageVariables = (hostname: string): Record<StorageVariable, string> =>
|
|
|
483
362
|
})
|
|
484
363
|
|
|
485
364
|
/** The crontab lines that run a job of the contract or of the framework, each on one container. */
|
|
486
|
-
const jobCrontab = (
|
|
487
|
-
|
|
488
|
-
...(contract.files === true
|
|
489
|
-
? [{ timing: FILE_SWEEP_SCHEDULE, command: `${FABRIKA_BIN} job run ${ZEROPS_FILE_SWEEP_JOB}`, allContainers: false }]
|
|
490
|
-
: []),
|
|
491
|
-
...(contract.scan === true ? [{ timing: '* * * * *', command: `${FABRIKA_BIN} job run ${ZEROPS_FILE_SCAN_JOB}`, allContainers: false }] : []),
|
|
492
|
-
]
|
|
365
|
+
const jobCrontab = (execution: ZeropsLockedExecution): { readonly timing: string; readonly command: string; readonly allContainers: boolean }[] =>
|
|
366
|
+
recipeOf(execution).jobs.map((job) => ({ timing: job.schedule, command: job.command, allContainers: false }))
|
|
493
367
|
|
|
494
368
|
/** How many job processes the crontab may run at once, each opening the application's database. */
|
|
495
|
-
export const zeropsJobProcesses = (
|
|
369
|
+
export const zeropsJobProcesses = (execution: ZeropsLockedExecution): number => jobCrontab(execution).length
|
|
496
370
|
|
|
497
371
|
/** The commands every container runs before `run.start`, in order; any failure stops the activation. */
|
|
498
372
|
export function generatedInitCommands(execution: ZeropsLockedExecution): string[] {
|
|
@@ -500,7 +374,7 @@ export function generatedInitCommands(execution: ZeropsLockedExecution): string[
|
|
|
500
374
|
// A container starts from the prepared image, whose signatures are as old as its build; a failed refresh leaves
|
|
501
375
|
// them to the daily one, and the scanner refuses signatures older than three days, so the scan fails closed.
|
|
502
376
|
...(execution.contract.scan === true ? [`${FRESHCLAM} || echo 'fabrika: freshclam did not refresh the malware signatures'`] : []),
|
|
503
|
-
...
|
|
377
|
+
...recipeOf(execution).init.map((path) => `sh ${RUNTIME_ROOT}/${path}`),
|
|
504
378
|
]
|
|
505
379
|
}
|
|
506
380
|
|
|
@@ -525,7 +399,7 @@ export function renderLockedSetup(
|
|
|
525
399
|
const scan = contract.scan === true
|
|
526
400
|
const packages = sortedUnique([...execution.runtimePackages, ...(scan ? [SCANNER_PACKAGE] : [])])
|
|
527
401
|
// Every container keeps its own signatures; one scan pass at a time holds the job's lease.
|
|
528
|
-
const crontab = [...jobCrontab(
|
|
402
|
+
const crontab = [...jobCrontab(execution), ...(scan ? [{ timing: FRESHCLAM_SCHEDULE, command: FRESHCLAM, allContainers: true }] : [])]
|
|
529
403
|
const initCommands = generatedInitCommands(execution)
|
|
530
404
|
const prepareCommands = packages.length === 0 ? [] : [`sudo apk add --no-cache ${packages.join(' ')}`, ...(scan ? [FRESHCLAM] : [])]
|
|
531
405
|
return {
|
|
@@ -539,13 +413,17 @@ export function renderLockedSetup(
|
|
|
539
413
|
cache: ['node_modules'],
|
|
540
414
|
},
|
|
541
415
|
deploy: {
|
|
542
|
-
readinessCheck: {
|
|
416
|
+
readinessCheck: {
|
|
417
|
+
exec: { command: readinessCommand(contract.readinessPath, execution.dev !== undefined) },
|
|
418
|
+
retryPeriod: '10s',
|
|
419
|
+
failureTimeout: '180s',
|
|
420
|
+
},
|
|
543
421
|
},
|
|
544
422
|
run: {
|
|
545
423
|
base: ZEROPS_APPLICATION_RUNTIME,
|
|
546
424
|
...(prepareCommands.length === 0 ? {} : { prepareCommands }),
|
|
547
425
|
...(initCommands.length === 0 ? {} : { initCommands }),
|
|
548
|
-
start: `sh ${RUNTIME_ROOT}/${
|
|
426
|
+
start: `sh ${RUNTIME_ROOT}/${recipeOf(execution).start}`,
|
|
549
427
|
ports: [{ port: ZEROPS_APPLICATION_PORT, httpSupport: true }],
|
|
550
428
|
// A dev container keeps its launcher running while the application it respawns fails: Zerops restarting it
|
|
551
429
|
// would only boot the same failing head again.
|
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,8 +12,7 @@
|
|
|
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 { type McpClient, parseMcpClientsJson } from './mcp'
|
|
15
|
+
import { describeArgument, type McpClient, parseMcpClientsJson, readEnv, requiredSetting, setting } from '@fabrika/installation-init'
|
|
17
16
|
import { parsePlatformHosts, parsePlatformScheme } from './placement-options'
|
|
18
17
|
import { readInstallationSourceDir } from './source-options'
|
|
19
18
|
|