@fabrika/cli 0.0.13 → 0.0.15
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 -10
- package/src/control.ts +105 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fabrika/cli",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.15",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -29,14 +29,14 @@
|
|
|
29
29
|
"test": "bun test"
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@fabrika/app": "^0.0.
|
|
33
|
-
"@fabrika/auth-core": "^0.0.
|
|
34
|
-
"@fabrika/control-contract": "^0.0.
|
|
35
|
-
"@fabrika/installation-cloudflare": "^0.0.
|
|
36
|
-
"@fabrika/installation-contract": "^0.0.
|
|
37
|
-
"@fabrika/installation-zerops": "^0.0.
|
|
38
|
-
"@fabrika/provider-cloudflare": "^0.0.
|
|
39
|
-
"@fabrika/provider-contract": "^0.0.
|
|
40
|
-
"@fabrika/provider-zerops": "^0.0.
|
|
32
|
+
"@fabrika/app": "^0.0.15",
|
|
33
|
+
"@fabrika/auth-core": "^0.0.15",
|
|
34
|
+
"@fabrika/control-contract": "^0.0.15",
|
|
35
|
+
"@fabrika/installation-cloudflare": "^0.0.15",
|
|
36
|
+
"@fabrika/installation-contract": "^0.0.15",
|
|
37
|
+
"@fabrika/installation-zerops": "^0.0.15",
|
|
38
|
+
"@fabrika/provider-cloudflare": "^0.0.15",
|
|
39
|
+
"@fabrika/provider-contract": "^0.0.15",
|
|
40
|
+
"@fabrika/provider-zerops": "^0.0.15"
|
|
41
41
|
}
|
|
42
42
|
}
|
package/src/control.ts
CHANGED
|
@@ -17,6 +17,8 @@ import type {
|
|
|
17
17
|
DeploymentNamespaceDto,
|
|
18
18
|
JsonValue,
|
|
19
19
|
PlanDeploymentNamespaceRequest,
|
|
20
|
+
PutAppEnvRequest,
|
|
21
|
+
PutAppVarRequest,
|
|
20
22
|
RegisterAppRequest,
|
|
21
23
|
RunDto,
|
|
22
24
|
} from '@fabrika/control-contract'
|
|
@@ -27,6 +29,12 @@ Usage:
|
|
|
27
29
|
fabrika control key issue --label=<name> --permissions=<a,b,c> [--expires-in=<seconds>]
|
|
28
30
|
fabrika control apps list
|
|
29
31
|
fabrika control apps get --app=<id>
|
|
32
|
+
fabrika control apps environments list --app=<id>
|
|
33
|
+
fabrika control apps environments put --provider=<name> --app=<id> --env=<name> --manifest=<path>
|
|
34
|
+
[--domain=<host>] [--public-origin=<url>] [--trigger-ref=<ref>] [--namespace=<id>]
|
|
35
|
+
fabrika control apps variables list --app=<id>
|
|
36
|
+
fabrika control apps variables put --app=<id> --name=<name> --value=<text> [--env=<name>]
|
|
37
|
+
fabrika control apps variables delete --app=<id> --name=<name> [--env=<name>]
|
|
30
38
|
fabrika control register --provider=<name> --app=<id> --repo=<url> --env=<name> --manifest=<path>
|
|
31
39
|
[--domain=<host>] [--public-origin=<url>] [--trigger-ref=<ref>]
|
|
32
40
|
[--namespace=<id>] [--installation-id=<n|none>]
|
|
@@ -39,6 +47,10 @@ Usage:
|
|
|
39
47
|
fabrika control runs get --run=<id>
|
|
40
48
|
fabrika control runs log --run=<id>
|
|
41
49
|
|
|
50
|
+
\`register\` CREATES an app and refuses a second one with the same id. Re-registering a changed
|
|
51
|
+
manifest — a new \`zerops.yaml\`, a new import document — is \`apps environments put\`, which replaces
|
|
52
|
+
one environment's envelopes and leaves the app row alone.
|
|
53
|
+
|
|
42
54
|
\`--installation-id\` has three states: omitted resolves the installation from the organization's
|
|
43
55
|
connected GitHub App, \`none\` registers an anonymous PUBLIC repository source, and a number names one
|
|
44
56
|
installation outright.
|
|
@@ -306,7 +318,98 @@ const runRegister = async (flags: Flags, provider: string | undefined, env: Read
|
|
|
306
318
|
emit(flags, result, () => `${result.app.id}\t${result.env.env}\t${result.env.provider}`)
|
|
307
319
|
}
|
|
308
320
|
|
|
309
|
-
|
|
321
|
+
/**
|
|
322
|
+
* `apps environments put` is how a REGISTERED app takes a changed manifest — `register` creates and
|
|
323
|
+
* refuses a second app with the same id, so it cannot serve a redeploy of a moved descriptor.
|
|
324
|
+
*
|
|
325
|
+
* It replaces the whole environment record, so every optional placement flag left out is cleared. That
|
|
326
|
+
* is the procedure's own semantics, shared with the console, not a choice made here.
|
|
327
|
+
*/
|
|
328
|
+
const runEnvironments = async (
|
|
329
|
+
verb: string | undefined,
|
|
330
|
+
flags: Flags,
|
|
331
|
+
provider: string | undefined,
|
|
332
|
+
env: Readonly<Record<string, string | undefined>>,
|
|
333
|
+
): Promise<void> => {
|
|
334
|
+
const client = controlClient(flags, env)
|
|
335
|
+
if (verb === 'list') {
|
|
336
|
+
const result = await client.apps.environments.list({ appId: required(flags, 'app') })
|
|
337
|
+
emit(flags, result, () => result.items.map((item) => `${item.appId}\t${item.env}\t${item.provider}\t${item.domain ?? '-'}`).join('\n'))
|
|
338
|
+
return
|
|
339
|
+
}
|
|
340
|
+
if (verb === 'put') {
|
|
341
|
+
if (provider === undefined || provider === '') {
|
|
342
|
+
throw new Error('--provider=<name> is required: it labels the envelope this environment carries.')
|
|
343
|
+
}
|
|
344
|
+
const manifestPath = required(flags, 'manifest')
|
|
345
|
+
const manifest = await readJsonFile(manifestPath)
|
|
346
|
+
const version = manifestVersion(manifest, manifestPath)
|
|
347
|
+
const domain = optional(flags, 'domain')
|
|
348
|
+
const publicOrigin = optional(flags, 'public-origin')
|
|
349
|
+
const triggerRef = optional(flags, 'trigger-ref')
|
|
350
|
+
const namespaceId = optional(flags, 'namespace')
|
|
351
|
+
const environment: PutAppEnvRequest = {
|
|
352
|
+
// The same empty placeholder `register` sends: the target is DISCOVERED from the manifest.
|
|
353
|
+
target: { provider, version, payload: {} },
|
|
354
|
+
artifact: { provider, version, payload: manifest },
|
|
355
|
+
...(domain === undefined ? {} : { domain }),
|
|
356
|
+
...(publicOrigin === undefined ? {} : { publicOrigin }),
|
|
357
|
+
...(triggerRef === undefined ? {} : { triggerRef }),
|
|
358
|
+
...(namespaceId === undefined ? {} : { namespaceId }),
|
|
359
|
+
}
|
|
360
|
+
const result = await client.apps.environments.put({ appId: required(flags, 'app'), env: required(flags, 'env'), environment })
|
|
361
|
+
emit(flags, result, () => `${result.appId}\t${result.env}\t${result.provider}`)
|
|
362
|
+
return
|
|
363
|
+
}
|
|
364
|
+
throw new Error(`Unknown \`control apps environments\` verb: ${verb ?? '(missing)'}`)
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
/**
|
|
368
|
+
* A variable is NOT a secret: its value is stored and read back in clear, so it takes a flag. The one
|
|
369
|
+
* thing an app cannot commit and fabrika cannot infer — an installation's IAM issuer, say — is written
|
|
370
|
+
* here, and the deploy carries it to the service's environment.
|
|
371
|
+
*/
|
|
372
|
+
const runVariables = async (verb: string | undefined, flags: Flags, env: Readonly<Record<string, string | undefined>>): Promise<void> => {
|
|
373
|
+
const client = controlClient(flags, env)
|
|
374
|
+
const appId = required(flags, 'app')
|
|
375
|
+
const scope = optional(flags, 'env')
|
|
376
|
+
if (verb === 'list') {
|
|
377
|
+
const result = await client.apps.variables.list({ appId })
|
|
378
|
+
emit(flags, result, () => result.items.map((item) => `${item.env ?? '*'}\t${item.name}\t${item.value}`).join('\n'))
|
|
379
|
+
return
|
|
380
|
+
}
|
|
381
|
+
if (verb === 'put') {
|
|
382
|
+
const variable: PutAppVarRequest = {
|
|
383
|
+
name: required(flags, 'name'),
|
|
384
|
+
value: required(flags, 'value'),
|
|
385
|
+
...(scope === undefined ? {} : { env: scope }),
|
|
386
|
+
}
|
|
387
|
+
const result = await client.apps.variables.put({ appId, variable })
|
|
388
|
+
emit(flags, result, () => `${result.env ?? '*'}\t${result.name}\t${result.value}`)
|
|
389
|
+
return
|
|
390
|
+
}
|
|
391
|
+
if (verb === 'delete') {
|
|
392
|
+
const result = await client.apps.variables.delete({ appId, name: required(flags, 'name'), ...(scope === undefined ? {} : { env: scope }) })
|
|
393
|
+
emit(flags, result, () => (result.ok ? 'deleted' : 'not deleted'))
|
|
394
|
+
return
|
|
395
|
+
}
|
|
396
|
+
throw new Error(`Unknown \`control apps variables\` verb: ${verb ?? '(missing)'}`)
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
const runApps = async (
|
|
400
|
+
verb: string | undefined,
|
|
401
|
+
flags: Flags,
|
|
402
|
+
provider: string | undefined,
|
|
403
|
+
env: Readonly<Record<string, string | undefined>>,
|
|
404
|
+
): Promise<void> => {
|
|
405
|
+
if (verb === 'variables') {
|
|
406
|
+
await runVariables(flags.positional[1], flags, env)
|
|
407
|
+
return
|
|
408
|
+
}
|
|
409
|
+
if (verb === 'environments') {
|
|
410
|
+
await runEnvironments(flags.positional[1], flags, provider, env)
|
|
411
|
+
return
|
|
412
|
+
}
|
|
310
413
|
const client = controlClient(flags, env)
|
|
311
414
|
if (verb === 'list') {
|
|
312
415
|
const result = await client.apps.list()
|
|
@@ -438,7 +541,7 @@ export const runControlCli = async (
|
|
|
438
541
|
await runKeyIssue(flags, env)
|
|
439
542
|
return
|
|
440
543
|
case 'apps':
|
|
441
|
-
await runApps(verb, flags, env)
|
|
544
|
+
await runApps(verb, flags, provider, env)
|
|
442
545
|
return
|
|
443
546
|
case 'runs':
|
|
444
547
|
await runRuns(verb, flags, env)
|