@sixb/cli 0.2.5 → 0.2.7
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/dist/commands/api.d.ts.map +1 -1
- package/dist/commands/app.d.ts.map +1 -1
- package/dist/commands/check.d.ts +4 -0
- package/dist/commands/check.d.ts.map +1 -1
- package/dist/commands/db-migrate.d.ts +2 -0
- package/dist/commands/db-migrate.d.ts.map +1 -1
- package/dist/commands/deploy.d.ts +0 -20
- package/dist/commands/deploy.d.ts.map +1 -1
- package/dist/commands/env.d.ts.map +1 -1
- package/dist/commands/worker-group.d.ts.map +1 -1
- package/dist/commands/worker.d.ts.map +1 -1
- package/dist/lib/command-line.d.ts +16 -16
- package/dist/lib/command-line.d.ts.map +1 -1
- package/dist/lib/deploy-release.d.ts.map +1 -1
- package/dist/lib/deploy-source.d.ts +2 -0
- package/dist/lib/deploy-source.d.ts.map +1 -1
- package/dist/lib/env-config.d.ts.map +1 -1
- package/dist/lib/role-lifecycle.d.ts +8 -1
- package/dist/lib/role-lifecycle.d.ts.map +1 -1
- package/dist/lib/storage-migration.d.ts +7 -0
- package/dist/lib/storage-migration.d.ts.map +1 -1
- package/dist/lib/worker-registry.d.ts +1 -0
- package/dist/lib/worker-registry.d.ts.map +1 -1
- package/dist/runner/computer-connection.d.ts.map +1 -1
- package/dist/tui/app.d.ts +2 -0
- package/dist/tui/app.d.ts.map +1 -1
- package/dist/tui/moves.d.ts +62 -0
- package/dist/tui/moves.d.ts.map +1 -0
- package/dist/tui/parts.d.ts.map +1 -1
- package/dist/tui/settings.d.ts +2 -0
- package/dist/tui/settings.d.ts.map +1 -1
- package/dist/tui/transcript.d.ts +13 -6
- package/dist/tui/transcript.d.ts.map +1 -1
- package/dist/ui/deploy-screens.d.ts +1 -26
- package/dist/ui/deploy-screens.d.ts.map +1 -1
- package/dist/ui/screens.d.ts +8 -0
- package/dist/ui/screens.d.ts.map +1 -1
- package/package.json +21 -21
- package/src/commands/agent.ts +1 -1
- package/src/commands/api.ts +20 -10
- package/src/commands/app.ts +15 -7
- package/src/commands/check.ts +87 -49
- package/src/commands/db-migrate.ts +25 -1
- package/src/commands/deploy.ts +16 -186
- package/src/commands/dev-runner.ts +1 -1
- package/src/commands/env.ts +15 -5
- package/src/commands/worker-group.ts +36 -9
- package/src/commands/worker.ts +27 -9
- package/src/index.tsx +11 -27
- package/src/lib/command-line.ts +19 -53
- package/src/lib/deploy-release.ts +3 -4
- package/src/lib/deploy-source.ts +15 -0
- package/src/lib/env-config.ts +1 -3
- package/src/lib/role-lifecycle.ts +48 -8
- package/src/lib/storage-migration.ts +33 -1
- package/src/lib/worker-registry.ts +4 -1
- package/src/runner/computer-connection.ts +7 -1
- package/src/tui/app.tsx +183 -38
- package/src/tui/moves.ts +221 -0
- package/src/tui/parts.ts +7 -0
- package/src/tui/settings.ts +5 -0
- package/src/tui/transcript.tsx +50 -14
- package/src/ui/deploy-screens.ts +11 -112
- package/src/ui/screens.ts +23 -0
- package/dist/lib/github-ci.d.ts +0 -49
- package/dist/lib/github-ci.d.ts.map +0 -1
- package/src/lib/github-ci.ts +0 -262
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sixb/cli",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.7",
|
|
4
4
|
"description": "Command-line interface for Sixb projects",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"sixb",
|
|
@@ -31,32 +31,32 @@
|
|
|
31
31
|
"dependencies": {
|
|
32
32
|
"@opentui/core": "0.6.6",
|
|
33
33
|
"@opentui/react": "0.6.6",
|
|
34
|
-
"@sixb/agent": "0.2.
|
|
35
|
-
"@sixb/agent-worker": "0.2.
|
|
36
|
-
"@sixb/app": "^0.2.
|
|
37
|
-
"@sixb/client": "^0.2.
|
|
38
|
-
"@sixb/core": "0.2.
|
|
39
|
-
"@sixb/cli-core": "^0.2.
|
|
40
|
-
"@sixb/lake-worker": "0.2.
|
|
41
|
-
"@sixb/orchestrator": "0.2.
|
|
42
|
-
"@sixb/pipeline-worker": "0.2.
|
|
43
|
-
"@sixb/projection-worker": "0.2.
|
|
44
|
-
"@sixb/render-worker": "0.2.
|
|
45
|
-
"@sixb/rules-worker": "0.2.
|
|
46
|
-
"@sixb/sandboxes-local": "^0.2.
|
|
47
|
-
"@sixb/server": "0.2.
|
|
48
|
-
"@sixb/sync-worker": "0.2.
|
|
49
|
-
"@sixb/workflow-worker": "0.2.
|
|
50
|
-
"create-sixb": "^0.2.
|
|
34
|
+
"@sixb/agent": "0.2.7",
|
|
35
|
+
"@sixb/agent-worker": "0.2.7",
|
|
36
|
+
"@sixb/app": "^0.2.7",
|
|
37
|
+
"@sixb/client": "^0.2.7",
|
|
38
|
+
"@sixb/core": "0.2.7",
|
|
39
|
+
"@sixb/cli-core": "^0.2.5",
|
|
40
|
+
"@sixb/lake-worker": "0.2.7",
|
|
41
|
+
"@sixb/orchestrator": "0.2.7",
|
|
42
|
+
"@sixb/pipeline-worker": "0.2.7",
|
|
43
|
+
"@sixb/projection-worker": "0.2.7",
|
|
44
|
+
"@sixb/render-worker": "0.2.7",
|
|
45
|
+
"@sixb/rules-worker": "0.2.7",
|
|
46
|
+
"@sixb/sandboxes-local": "^0.2.1",
|
|
47
|
+
"@sixb/server": "0.2.7",
|
|
48
|
+
"@sixb/sync-worker": "0.2.7",
|
|
49
|
+
"@sixb/workflow-worker": "0.2.7",
|
|
50
|
+
"create-sixb": "^0.2.2",
|
|
51
51
|
"react": "^19.2.0"
|
|
52
52
|
},
|
|
53
53
|
"devDependencies": {
|
|
54
|
-
"@sixb/deploy-ssh": "0.2.
|
|
54
|
+
"@sixb/deploy-ssh": "0.2.7",
|
|
55
55
|
"@sixb/desktop": "0.2.1",
|
|
56
56
|
"@sixb/ducklake": "0.2.5",
|
|
57
|
-
"@sixb/pg": "0.2.
|
|
57
|
+
"@sixb/pg": "0.2.7",
|
|
58
58
|
"@sixb/queues-bullmq": "0.2.5",
|
|
59
|
-
"@sixb/sqlite": "0.2.
|
|
59
|
+
"@sixb/sqlite": "0.2.7",
|
|
60
60
|
"@types/bun": "latest",
|
|
61
61
|
"@types/react": "^19.0.0",
|
|
62
62
|
"typescript": "^5.7.0"
|
package/src/commands/agent.ts
CHANGED
|
@@ -92,7 +92,7 @@ export async function runAgent(options: {
|
|
|
92
92
|
const place = thread.computer
|
|
93
93
|
if (onComputer && !place) {
|
|
94
94
|
throw new Error(
|
|
95
|
-
"[SixbCLI] This conversation has no folder yet: open it with sixb in its folder, and press ctrl+
|
|
95
|
+
"[SixbCLI] This conversation has no folder yet: open it with sixb in its folder, and press ctrl+g twice."
|
|
96
96
|
)
|
|
97
97
|
}
|
|
98
98
|
const here = onComputer && place?.id === (await thisComputerId()) && place.folder === folder
|
package/src/commands/api.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { stat } from "node:fs/promises"
|
|
2
2
|
import { resolve } from "node:path"
|
|
3
|
+
import { ACTION_RUN_DRAIN_TIMEOUT_MS } from "@sixb/core/internal/actions"
|
|
3
4
|
import { createSixbServer, requestTimingOptionsFromEnv, type SixbServer } from "@sixb/server"
|
|
4
5
|
import { apiDocsUrl, apiEventsUrl, apiUrl, resolveBrowserTopology } from "../lib/browser-topology"
|
|
5
6
|
import type { LoadedSixbHost } from "../lib/loadSixb"
|
|
6
7
|
import { builtAppOutdir, loadProductionSixb } from "../lib/production"
|
|
7
|
-
import { runUntilSignal, stopQuietly } from "../lib/role-lifecycle"
|
|
8
|
+
import { resolveDrainTimeoutMs, runUntilSignal, stopQuietly } from "../lib/role-lifecycle"
|
|
8
9
|
import { stopSixbProviders } from "../lib/runtime"
|
|
9
10
|
import { migrateStorageForRole } from "../lib/storage-migration"
|
|
10
11
|
import { printStopping, renderCliError, renderStatic, roleView, startTask } from "../ui"
|
|
@@ -95,18 +96,27 @@ export async function runApi(options: ApiOptions = {}) {
|
|
|
95
96
|
})
|
|
96
97
|
)
|
|
97
98
|
|
|
98
|
-
await runUntilSignal(
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
99
|
+
await runUntilSignal(
|
|
100
|
+
async (signal) => {
|
|
101
|
+
app.stop()
|
|
102
|
+
printStopping("api")
|
|
103
|
+
const timeoutMs =
|
|
104
|
+
signal === "SIGTERM" ? resolveDrainTimeoutMs(ACTION_RUN_DRAIN_TIMEOUT_MS) : 0
|
|
105
|
+
await stopQuietly(() => server?.stop({ timeoutMs }) ?? Promise.resolve())
|
|
106
|
+
if (sixb) {
|
|
107
|
+
await stopSixbProviders(sixb)
|
|
108
|
+
}
|
|
109
|
+
sixb = null
|
|
110
|
+
},
|
|
111
|
+
{
|
|
112
|
+
onInterrupt: () => {
|
|
113
|
+
void stopQuietly(() => server?.stop({ timeoutMs: 0 }) ?? Promise.resolve())
|
|
114
|
+
},
|
|
104
115
|
}
|
|
105
|
-
|
|
106
|
-
})
|
|
116
|
+
)
|
|
107
117
|
} catch (error) {
|
|
108
118
|
app.stop()
|
|
109
|
-
await stopQuietly(() => server?.stop() ?? Promise.resolve())
|
|
119
|
+
await stopQuietly(() => server?.stop({ timeoutMs: 0 }) ?? Promise.resolve())
|
|
110
120
|
if (sixb) {
|
|
111
121
|
await stopSixbProviders(sixb)
|
|
112
122
|
}
|
package/src/commands/app.ts
CHANGED
|
@@ -7,7 +7,7 @@ import {
|
|
|
7
7
|
resolveProductionPaths,
|
|
8
8
|
resolveRuntimeEntry,
|
|
9
9
|
} from "../lib/production"
|
|
10
|
-
import { runUntilSignal, stopQuietly } from "../lib/role-lifecycle"
|
|
10
|
+
import { resolveDrainTimeoutMs, runUntilSignal, stopQuietly } from "../lib/role-lifecycle"
|
|
11
11
|
import { printStopping, renderCliError, renderStatic, roleView, startTask } from "../ui"
|
|
12
12
|
|
|
13
13
|
export interface AppOptions {
|
|
@@ -65,14 +65,22 @@ export async function runApp(options: AppOptions = {}) {
|
|
|
65
65
|
})
|
|
66
66
|
)
|
|
67
67
|
|
|
68
|
-
await runUntilSignal(
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
68
|
+
await runUntilSignal(
|
|
69
|
+
async (signal) => {
|
|
70
|
+
app.stop()
|
|
71
|
+
printStopping("app")
|
|
72
|
+
const timeoutMs = signal === "SIGTERM" ? resolveDrainTimeoutMs(5_000) : 0
|
|
73
|
+
await stopQuietly(() => customAppServer?.stop({ timeoutMs }) ?? Promise.resolve())
|
|
74
|
+
},
|
|
75
|
+
{
|
|
76
|
+
onInterrupt: () => {
|
|
77
|
+
void stopQuietly(() => customAppServer?.stop({ timeoutMs: 0 }) ?? Promise.resolve())
|
|
78
|
+
},
|
|
79
|
+
}
|
|
80
|
+
)
|
|
73
81
|
} catch (error) {
|
|
74
82
|
app.stop()
|
|
75
|
-
await stopQuietly(() => customAppServer?.stop() ?? Promise.resolve())
|
|
83
|
+
await stopQuietly(() => customAppServer?.stop({ timeoutMs: 0 }) ?? Promise.resolve())
|
|
76
84
|
await renderCliError(error)
|
|
77
85
|
process.exit(1)
|
|
78
86
|
}
|
package/src/commands/check.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { dirname, resolve } from "node:path"
|
|
2
|
+
import { migrateStorage } from "@sixb/core"
|
|
2
3
|
import { getLakeRetentionRuntime, ingestStalledSince } from "@sixb/core/internal/runtime"
|
|
3
4
|
import { countLostRuns } from "@sixb/core/internal/workers"
|
|
4
5
|
import { assertDeclaredEnv } from "../lib/env-config"
|
|
@@ -6,15 +7,20 @@ import { errorMessage } from "../lib/errors"
|
|
|
6
7
|
import { checkRuntimeHealth } from "../lib/health"
|
|
7
8
|
import { type LoadedSixbHost, loadSixbFromEntry } from "../lib/loadSixb"
|
|
8
9
|
import {
|
|
10
|
+
checkRuntimeLakeDefinitions,
|
|
9
11
|
checkRuntimePipelineMarkings,
|
|
10
12
|
readAppliedMarkingNotices,
|
|
11
13
|
stopSixbProviders,
|
|
12
14
|
} from "../lib/runtime"
|
|
13
15
|
import { generateProjectTypes } from "../lib/typegen"
|
|
14
|
-
import { checkView, renderStatic, withTask } from "../ui"
|
|
16
|
+
import { checkView, dbMigrateView, lakeCheckView, renderStatic, withTask } from "../ui"
|
|
15
17
|
|
|
16
18
|
export interface CheckOptions {
|
|
17
19
|
entry?: string
|
|
20
|
+
/** Brings the storage schema up to date first, in the same project load, as a deploy does. */
|
|
21
|
+
migrate?: boolean
|
|
22
|
+
/** Checks the lake's dataset definitions too, as `sixb lake check` does. */
|
|
23
|
+
lake?: boolean
|
|
18
24
|
}
|
|
19
25
|
|
|
20
26
|
export async function runCheck(options: CheckOptions = {}) {
|
|
@@ -29,54 +35,8 @@ export async function runCheck(options: CheckOptions = {}) {
|
|
|
29
35
|
})
|
|
30
36
|
|
|
31
37
|
try {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
const health = await checkRuntimeHealth(sixb)
|
|
35
|
-
task.step("Checking markings")
|
|
36
|
-
return { health, markings: await checkMarkings(sixb, health.storage.ok) }
|
|
37
|
-
})
|
|
38
|
-
|
|
39
|
-
const projectValidation =
|
|
40
|
-
objectTypes.length > 0
|
|
41
|
-
? {
|
|
42
|
-
ok: true,
|
|
43
|
-
message: `${objectTypes.length} object type${objectTypes.length === 1 ? "" : "s"}`,
|
|
44
|
-
}
|
|
45
|
-
: { ok: false, message: "No object types loaded" }
|
|
46
|
-
|
|
47
|
-
await renderStatic(
|
|
48
|
-
checkView({
|
|
49
|
-
projectId: sixb.id,
|
|
50
|
-
storage: health.storage,
|
|
51
|
-
timeseries: health.timeseries,
|
|
52
|
-
broker: health.broker,
|
|
53
|
-
queues: health.queues,
|
|
54
|
-
projectValidation,
|
|
55
|
-
markings,
|
|
56
|
-
ontology: {
|
|
57
|
-
enabled: true,
|
|
58
|
-
source: entry,
|
|
59
|
-
errors: objectTypes.length > 0 ? 0 : 1,
|
|
60
|
-
// Ontology warnings, which nothing produces yet. The provider warnings below
|
|
61
|
-
// are a different thing and counting them here read as ontology drift.
|
|
62
|
-
warnings: 0,
|
|
63
|
-
},
|
|
64
|
-
warnings: [
|
|
65
|
-
...health.warnings,
|
|
66
|
-
...markings.warnings,
|
|
67
|
-
...(await lakeWorkerWarnings(sixb, health.storage.ok)),
|
|
68
|
-
...(await lostRunWarnings(sixb, health.storage.ok)),
|
|
69
|
-
],
|
|
70
|
-
})
|
|
71
|
-
)
|
|
72
|
-
|
|
73
|
-
// A failing probe exits non-zero so `sixb check` can gate a deploy. `exitCode`, not
|
|
74
|
-
// `exit()`: `process.exit()` terminates immediately and the `finally` below never runs, so
|
|
75
|
-
// the providers this command opened were left unclosed on the one path where that matters.
|
|
76
|
-
const failed = [health.storage, health.timeseries, health.broker, health.queues, markings].some(
|
|
77
|
-
(check) => !check.ok
|
|
78
|
-
)
|
|
79
|
-
if (objectTypes.length === 0 || failed) process.exitCode = 1
|
|
38
|
+
if (options.migrate) await migrate(sixb)
|
|
39
|
+
await probe(sixb, entry, options.lake === true)
|
|
80
40
|
} finally {
|
|
81
41
|
// Tear down runtime providers (broker, queues, storage, connectors) so the
|
|
82
42
|
// process can exit instead of hanging on open connections. Mirrors lake-check.
|
|
@@ -92,8 +52,86 @@ export async function runCheck(options: CheckOptions = {}) {
|
|
|
92
52
|
process.exit(process.exitCode ?? 0)
|
|
93
53
|
}
|
|
94
54
|
|
|
55
|
+
/** Probes every provider and the project, and the lake's datasets when asked. */
|
|
56
|
+
async function probe(sixb: LoadedSixbHost, entry: string, lake: boolean): Promise<void> {
|
|
57
|
+
const objectTypes = sixb.definitions.ontology.listObjectTypes()
|
|
58
|
+
const { health, markings } = await withTask("check", "Probing providers", async (task) => {
|
|
59
|
+
const health = await checkRuntimeHealth(sixb)
|
|
60
|
+
task.step("Checking markings")
|
|
61
|
+
return { health, markings: await checkMarkings(sixb, health.storage.ok) }
|
|
62
|
+
})
|
|
63
|
+
|
|
64
|
+
const projectValidation =
|
|
65
|
+
objectTypes.length > 0
|
|
66
|
+
? {
|
|
67
|
+
ok: true,
|
|
68
|
+
message: `${objectTypes.length} object type${objectTypes.length === 1 ? "" : "s"}`,
|
|
69
|
+
}
|
|
70
|
+
: { ok: false, message: "No object types loaded" }
|
|
71
|
+
|
|
72
|
+
await renderStatic(
|
|
73
|
+
checkView({
|
|
74
|
+
projectId: sixb.id,
|
|
75
|
+
storage: health.storage,
|
|
76
|
+
timeseries: health.timeseries,
|
|
77
|
+
broker: health.broker,
|
|
78
|
+
queues: health.queues,
|
|
79
|
+
projectValidation,
|
|
80
|
+
markings,
|
|
81
|
+
ontology: {
|
|
82
|
+
enabled: true,
|
|
83
|
+
source: entry,
|
|
84
|
+
errors: objectTypes.length > 0 ? 0 : 1,
|
|
85
|
+
// Ontology warnings, which nothing produces yet. The provider warnings below
|
|
86
|
+
// are a different thing and counting them here read as ontology drift.
|
|
87
|
+
warnings: 0,
|
|
88
|
+
},
|
|
89
|
+
warnings: [
|
|
90
|
+
...health.warnings,
|
|
91
|
+
...markings.warnings,
|
|
92
|
+
...(await lakeWorkerWarnings(sixb, health.storage.ok)),
|
|
93
|
+
...(await lostRunWarnings(sixb, health.storage.ok)),
|
|
94
|
+
],
|
|
95
|
+
})
|
|
96
|
+
)
|
|
97
|
+
|
|
98
|
+
// A failing probe exits non-zero so `sixb check` can gate a deploy. `exitCode`, not
|
|
99
|
+
// `exit()`: `process.exit()` terminates immediately and the `finally` below never runs, so
|
|
100
|
+
// the providers this command opened were left unclosed on the one path where that matters.
|
|
101
|
+
const failed = [health.storage, health.timeseries, health.broker, health.queues, markings].some(
|
|
102
|
+
(check) => !check.ok
|
|
103
|
+
)
|
|
104
|
+
if (objectTypes.length === 0 || failed) process.exitCode = 1
|
|
105
|
+
else if (lake) {
|
|
106
|
+
await withTask("check", "Checking lake datasets", () => checkRuntimeLakeDefinitions(sixb))
|
|
107
|
+
await renderStatic(lakeCheckView({ projectId: sixb.id }))
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
95
111
|
const CLOSE_TIMEOUT_MS = 10_000
|
|
96
112
|
|
|
113
|
+
/**
|
|
114
|
+
* Migrates before anything is probed, since the probes read the schema. Always, as
|
|
115
|
+
* `sixb db migrate` does: a release with no schema change can still add a query index or make a
|
|
116
|
+
* property unique, and the services start with `--no-migrate`.
|
|
117
|
+
*/
|
|
118
|
+
async function migrate(sixb: LoadedSixbHost): Promise<void> {
|
|
119
|
+
const result = await withTask("check", "Migrating storage", () =>
|
|
120
|
+
migrateStorage(sixb.storage, {
|
|
121
|
+
projectId: sixb.id,
|
|
122
|
+
ontology: sixb.definitions.ontology,
|
|
123
|
+
security: sixb.definitions.security,
|
|
124
|
+
})
|
|
125
|
+
)
|
|
126
|
+
await renderStatic(
|
|
127
|
+
dbMigrateView({
|
|
128
|
+
projectId: sixb.id,
|
|
129
|
+
status: result.status,
|
|
130
|
+
applied: result.reports.flatMap((report) => report.applied),
|
|
131
|
+
})
|
|
132
|
+
)
|
|
133
|
+
}
|
|
134
|
+
|
|
97
135
|
/**
|
|
98
136
|
* What storage says, since no process knows what the others run. A storage that is down or behind
|
|
99
137
|
* has its own row in this report.
|
|
@@ -2,16 +2,40 @@ import { migrateStorage } from "@sixb/core"
|
|
|
2
2
|
import { loadSixbFromEntry } from "../lib/loadSixb"
|
|
3
3
|
import { resolveRuntimeEntry } from "../lib/production"
|
|
4
4
|
import { stopSixbProviders } from "../lib/runtime"
|
|
5
|
-
import {
|
|
5
|
+
import { findPendingMigrations } from "../lib/storage-migration"
|
|
6
|
+
import { dbMigrateCheckView, dbMigrateView, renderStatic, withTask } from "../ui"
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* `--check` exits with this code when `sixb db migrate` would change the schema. Not 2, which
|
|
10
|
+
* every command uses for a usage error, such as an option an older `sixb` does not know.
|
|
11
|
+
*/
|
|
12
|
+
const MIGRATIONS_PENDING_EXIT_CODE = 3
|
|
6
13
|
|
|
7
14
|
export interface DbMigrateOptions {
|
|
8
15
|
entry?: string
|
|
16
|
+
/** Only report whether migrations are pending, without running them. */
|
|
17
|
+
check?: boolean
|
|
9
18
|
}
|
|
10
19
|
|
|
11
20
|
export async function runDbMigrate(options: DbMigrateOptions = {}) {
|
|
12
21
|
const entry = await resolveRuntimeEntry({ entry: options.entry })
|
|
13
22
|
const sixb = await withTask("db migrate", "Loading project", () => loadSixbFromEntry(entry))
|
|
14
23
|
|
|
24
|
+
if (options.check) {
|
|
25
|
+
try {
|
|
26
|
+
const pending = await withTask("db migrate", "Reading the storage schema", () =>
|
|
27
|
+
findPendingMigrations(sixb.storage)
|
|
28
|
+
)
|
|
29
|
+
await renderStatic(dbMigrateCheckView({ projectId: sixb.id, pending }))
|
|
30
|
+
|
|
31
|
+
// A deploy reads the code: the release it is about to start needs the services stopped.
|
|
32
|
+
if (pending.length > 0) process.exitCode = MIGRATIONS_PENDING_EXIT_CODE
|
|
33
|
+
} finally {
|
|
34
|
+
await stopSixbProviders(sixb)
|
|
35
|
+
}
|
|
36
|
+
return
|
|
37
|
+
}
|
|
38
|
+
|
|
15
39
|
try {
|
|
16
40
|
const result = await withTask("db migrate", "Migrating storage", () =>
|
|
17
41
|
migrateStorage(sixb.storage, {
|
package/src/commands/deploy.ts
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { dirname, join, relative } from "node:path"
|
|
1
|
+
import { relative } from "node:path"
|
|
3
2
|
import { writeJson } from "@sixb/cli-core"
|
|
4
3
|
import type {
|
|
5
|
-
DeployAccessKey,
|
|
6
4
|
DeployCheck,
|
|
7
5
|
DeployConfig,
|
|
8
6
|
DeployControlAction,
|
|
@@ -16,30 +14,14 @@ import {
|
|
|
16
14
|
deployer,
|
|
17
15
|
packSource,
|
|
18
16
|
projectPathOf,
|
|
19
|
-
repoRootOf,
|
|
20
17
|
resolveBunVersion,
|
|
18
|
+
usesChromium,
|
|
21
19
|
} from "../lib/deploy-source"
|
|
22
20
|
import { ENV_CONFIG_FILE, loadEnvConfig } from "../lib/env-config"
|
|
23
21
|
import { SixbCliError } from "../lib/errors"
|
|
24
|
-
import {
|
|
25
|
-
bunVersionFile,
|
|
26
|
-
CI_ENVIRONMENT,
|
|
27
|
-
currentRepo,
|
|
28
|
-
ensureEnvironment,
|
|
29
|
-
hasSecret,
|
|
30
|
-
isPrivate,
|
|
31
|
-
readSubmodules,
|
|
32
|
-
renderWorkflow,
|
|
33
|
-
SUBMODULE_TOKEN_SECRET,
|
|
34
|
-
secretName,
|
|
35
|
-
setSecret,
|
|
36
|
-
workflowPath,
|
|
37
|
-
} from "../lib/github-ci"
|
|
38
22
|
import {
|
|
39
23
|
cliErrorView,
|
|
40
|
-
deployAccessView,
|
|
41
24
|
deployChecksView,
|
|
42
|
-
deployCiView,
|
|
43
25
|
deployCompleteView,
|
|
44
26
|
deployReleaseView,
|
|
45
27
|
deployStatusView,
|
|
@@ -60,7 +42,8 @@ export interface DeployOptions {
|
|
|
60
42
|
export async function runDeploy(options: DeployOptions = {}): Promise<void> {
|
|
61
43
|
const cwd = options.cwd ?? process.cwd()
|
|
62
44
|
const { path, config } = await loadDeployConfig(cwd)
|
|
63
|
-
const
|
|
45
|
+
const envSource = (await loadEnvConfig(cwd))?.source
|
|
46
|
+
const envFromSource = Boolean(envSource)
|
|
64
47
|
|
|
65
48
|
if (options.dryRun) {
|
|
66
49
|
const release = buildDeployRelease(config, {
|
|
@@ -91,6 +74,8 @@ export async function runDeploy(options: DeployOptions = {}): Promise<void> {
|
|
|
91
74
|
const checks = await config.target.check(release, {
|
|
92
75
|
name: config.name,
|
|
93
76
|
projectPath: source.projectPath,
|
|
77
|
+
chromium: await usesChromium(cwd),
|
|
78
|
+
envToken: envSource?.serverNeedsToken !== false,
|
|
94
79
|
})
|
|
95
80
|
return { source, release, checks }
|
|
96
81
|
})
|
|
@@ -132,13 +117,19 @@ export async function runDeploy(options: DeployOptions = {}): Promise<void> {
|
|
|
132
117
|
export async function runDeployCheck(options: { readonly json?: boolean; readonly cwd?: string }) {
|
|
133
118
|
const cwd = options.cwd ?? process.cwd()
|
|
134
119
|
const { config } = await loadDeployConfig(cwd)
|
|
120
|
+
const envSource = (await loadEnvConfig(cwd))?.source
|
|
135
121
|
const release = buildDeployRelease(config, {
|
|
136
122
|
bunVersion: await resolveBunVersion(cwd),
|
|
137
|
-
envFromSource: Boolean(
|
|
123
|
+
envFromSource: Boolean(envSource),
|
|
138
124
|
})
|
|
139
|
-
const
|
|
125
|
+
const context = {
|
|
126
|
+
name: config.name,
|
|
127
|
+
projectPath: await projectPathOf(cwd),
|
|
128
|
+
chromium: await usesChromium(cwd),
|
|
129
|
+
envToken: envSource?.serverNeedsToken !== false,
|
|
130
|
+
}
|
|
140
131
|
const targetChecks = await withTask("deploy check", `Checking ${location(config)}`, () =>
|
|
141
|
-
config.target.check(release,
|
|
132
|
+
config.target.check(release, context)
|
|
142
133
|
)
|
|
143
134
|
const checks = [...targetChecks, ...lakeWorkChecks(config)]
|
|
144
135
|
if (options.json) writeJson(checks)
|
|
@@ -147,173 +138,12 @@ export async function runDeployCheck(options: { readonly json?: boolean; readonl
|
|
|
147
138
|
if (checks.some(blocksDeploy)) process.exitCode = 1
|
|
148
139
|
}
|
|
149
140
|
|
|
150
|
-
export async function runDeploySetup(options: {
|
|
151
|
-
readonly admin?: string
|
|
152
|
-
readonly key?: string
|
|
153
|
-
readonly cwd?: string
|
|
154
|
-
}) {
|
|
155
|
-
const cwd = options.cwd ?? process.cwd()
|
|
156
|
-
const { config } = await loadDeployConfig(cwd)
|
|
157
|
-
const source = (await loadEnvConfig(cwd))?.source
|
|
158
|
-
const release = buildDeployRelease(config, {
|
|
159
|
-
bunVersion: await resolveBunVersion(cwd),
|
|
160
|
-
envFromSource: Boolean(source),
|
|
161
|
-
})
|
|
162
|
-
const context = { name: config.name, projectPath: await projectPathOf(cwd) }
|
|
163
|
-
|
|
164
|
-
if (!config.target.setup) {
|
|
165
|
-
console.log(`A ${config.target.kind} target needs no setup.`)
|
|
166
|
-
} else {
|
|
167
|
-
await config.target.setup(release, {
|
|
168
|
-
...context,
|
|
169
|
-
...(options.admin ? { admin: options.admin } : {}),
|
|
170
|
-
...(options.key ? { key: options.key } : {}),
|
|
171
|
-
...(source
|
|
172
|
-
? {
|
|
173
|
-
createEnvToken: () =>
|
|
174
|
-
source.createServerToken("prod", `sixb-${config.name}-${new Date().toISOString()}`),
|
|
175
|
-
}
|
|
176
|
-
: {}),
|
|
177
|
-
write: (line) => console.log(line),
|
|
178
|
-
})
|
|
179
|
-
}
|
|
180
|
-
const checks = await config.target.check(release, context)
|
|
181
|
-
await renderStatic(deployChecksView({ name: config.name, location: location(config), checks }))
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
export async function runDeployAccess(options: {
|
|
185
|
-
readonly action: "list" | "add" | "remove"
|
|
186
|
-
readonly value?: string
|
|
187
|
-
readonly json?: boolean
|
|
188
|
-
readonly cwd?: string
|
|
189
|
-
}) {
|
|
190
|
-
const { config } = await loadDeployConfig(options.cwd)
|
|
191
|
-
const access = config.target.access
|
|
192
|
-
if (!access) {
|
|
193
|
-
throw new SixbCliError(`[SixbDeploy] A ${config.target.kind} target has no keys to manage.`)
|
|
194
|
-
}
|
|
195
|
-
const context = { name: config.name }
|
|
196
|
-
|
|
197
|
-
if (options.action === "list") {
|
|
198
|
-
const keys = await access.list(context)
|
|
199
|
-
if (options.json) return writeJson(keys)
|
|
200
|
-
return renderStatic(deployAccessView({ title: `Keys for ${location(config)}`, keys }))
|
|
201
|
-
}
|
|
202
|
-
if (options.action === "add") {
|
|
203
|
-
const added: DeployAccessKey[] = []
|
|
204
|
-
for (const key of await publicKeys(options.value ?? ""))
|
|
205
|
-
added.push(await access.add(key, context))
|
|
206
|
-
return renderStatic(deployAccessView({ title: "Authorized", keys: added }))
|
|
207
|
-
}
|
|
208
|
-
const removed = await access.remove(options.value ?? "", context)
|
|
209
|
-
return renderStatic(deployAccessView({ title: "Revoked", keys: removed }))
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
/**
|
|
213
|
-
* Sets up deploys from GitHub Actions: a key for the job, authorized on the target and stored as
|
|
214
|
-
* secrets of the repository's `production` environment, and the workflow that uses it. Running it
|
|
215
|
-
* again rotates the key: the new one is stored before the old one is revoked.
|
|
216
|
-
*/
|
|
217
|
-
export async function runDeployCi(options: { readonly branch?: string; readonly cwd?: string }) {
|
|
218
|
-
const cwd = options.cwd ?? process.cwd()
|
|
219
|
-
const { config } = await loadDeployConfig(cwd)
|
|
220
|
-
const ci = config.target.ci
|
|
221
|
-
if (!ci) {
|
|
222
|
-
throw new SixbCliError(`[SixbDeploy] A ${config.target.kind} target cannot deploy from CI.`)
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
const repo = await currentRepo(cwd)
|
|
226
|
-
const projectPath = await projectPathOf(cwd)
|
|
227
|
-
const repoRoot = await repoRootOf(cwd)
|
|
228
|
-
const submodules = await readSubmodules(repoRoot, repo)
|
|
229
|
-
const privateSubmodules = []
|
|
230
|
-
for (const submodule of submodules) {
|
|
231
|
-
if (!submodule.repo || (await isPrivate(submodule.repo))) privateSubmodules.push(submodule)
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
const credential = await ci.create(`github:${repo.name}`, { name: config.name })
|
|
235
|
-
const secrets = Object.fromEntries(
|
|
236
|
-
Object.keys(credential.secrets).map((variable) => [variable, secretName(config.name, variable)])
|
|
237
|
-
)
|
|
238
|
-
try {
|
|
239
|
-
await ensureEnvironment(repo)
|
|
240
|
-
for (const [variable, value] of Object.entries(credential.secrets)) {
|
|
241
|
-
await setSecret(repo, secrets[variable] ?? variable, value)
|
|
242
|
-
}
|
|
243
|
-
} catch (error) {
|
|
244
|
-
// CI never got the new key, so it must not stay authorized.
|
|
245
|
-
await credential.revoke()
|
|
246
|
-
throw error
|
|
247
|
-
}
|
|
248
|
-
const retired = await credential.retireOthers()
|
|
249
|
-
|
|
250
|
-
const branch = options.branch ?? repo.defaultBranch
|
|
251
|
-
const workflow = renderWorkflow({
|
|
252
|
-
name: config.name,
|
|
253
|
-
branch,
|
|
254
|
-
projectPath,
|
|
255
|
-
bunVersionFile: await bunVersionFile(join(repoRoot, projectPath), repoRoot),
|
|
256
|
-
secrets,
|
|
257
|
-
install: credential.install,
|
|
258
|
-
submodules:
|
|
259
|
-
privateSubmodules.length > 0 ? "private" : submodules.length > 0 ? "public" : "none",
|
|
260
|
-
})
|
|
261
|
-
const path = workflowPath(config.name)
|
|
262
|
-
const file = Bun.file(join(repoRoot, path))
|
|
263
|
-
// A workflow already there may have been edited, and rotating the key must not undo that.
|
|
264
|
-
const existing = (await file.exists()) ? await file.text() : null
|
|
265
|
-
if (existing === null) {
|
|
266
|
-
await mkdir(dirname(join(repoRoot, path)), { recursive: true })
|
|
267
|
-
await Bun.write(file, workflow)
|
|
268
|
-
}
|
|
269
|
-
|
|
270
|
-
await renderStatic(
|
|
271
|
-
deployCiView({
|
|
272
|
-
name: config.name,
|
|
273
|
-
repo: repo.name,
|
|
274
|
-
environment: CI_ENVIRONMENT,
|
|
275
|
-
branch,
|
|
276
|
-
credential: credential.description,
|
|
277
|
-
secrets: Object.values(secrets),
|
|
278
|
-
retired,
|
|
279
|
-
workflow: {
|
|
280
|
-
path,
|
|
281
|
-
state: existing === null ? "written" : existing === workflow ? "unchanged" : "kept",
|
|
282
|
-
},
|
|
283
|
-
token:
|
|
284
|
-
privateSubmodules.length > 0 && !(await hasSecret(repo, SUBMODULE_TOKEN_SECRET))
|
|
285
|
-
? { name: SUBMODULE_TOKEN_SECRET, submodules: privateSubmodules }
|
|
286
|
-
: null,
|
|
287
|
-
})
|
|
288
|
-
)
|
|
289
|
-
}
|
|
290
|
-
|
|
291
|
-
/**
|
|
292
|
-
* The public keys a value names: `github:<user>` for the keys on that GitHub account, a path to a
|
|
293
|
-
* `.pub` file, or the key's own text.
|
|
294
|
-
*/
|
|
295
|
-
async function publicKeys(value: string): Promise<string[]> {
|
|
296
|
-
if (value.startsWith("github:")) {
|
|
297
|
-
const user = value.slice("github:".length)
|
|
298
|
-
const response = await fetch(`https://github.com/${encodeURIComponent(user)}.keys`)
|
|
299
|
-
if (!response.ok) {
|
|
300
|
-
throw new SixbCliError(`[SixbDeploy] GitHub has no public keys for '${user}'.`)
|
|
301
|
-
}
|
|
302
|
-
const keys = (await response.text()).split("\n").filter((line) => line.trim())
|
|
303
|
-
if (keys.length === 0) throw new SixbCliError(`[SixbDeploy] '${user}' has no keys on GitHub.`)
|
|
304
|
-
return keys.map((key) => `${key.trim()} ${user}@github`)
|
|
305
|
-
}
|
|
306
|
-
const file = Bun.file(value)
|
|
307
|
-
if (await file.exists()) return [(await file.text()).trim()]
|
|
308
|
-
return [value]
|
|
309
|
-
}
|
|
310
|
-
|
|
311
141
|
function configWarnings(config: DeployConfig): readonly string[] {
|
|
312
142
|
return lakeWorkChecks(config).map((check) => `${check.label}: ${check.detail} ${check.remedy}`)
|
|
313
143
|
}
|
|
314
144
|
|
|
315
145
|
function blocksDeploy(check: DeployCheck): boolean {
|
|
316
|
-
return check.status === "
|
|
146
|
+
return check.status === "fail"
|
|
317
147
|
}
|
|
318
148
|
|
|
319
149
|
function location(config: DeployConfig): string {
|
|
@@ -134,7 +134,7 @@ export async function runDevRuntime(options: DevOptions = {}) {
|
|
|
134
134
|
step("Starting server")
|
|
135
135
|
return server.start()
|
|
136
136
|
},
|
|
137
|
-
stop: () => server.stop(),
|
|
137
|
+
stop: () => server.stop({ timeoutMs: 0 }),
|
|
138
138
|
},
|
|
139
139
|
agentApiBaseUrl: topology.apiPublicOrigin,
|
|
140
140
|
workerConcurrency,
|