@marcusrbrown/infra 0.13.1 → 0.13.3
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/cli.js +11965 -0
- package/package.json +7 -3
- package/src/__snapshots__/cli.test.ts.snap +0 -219
- package/src/__test__/mcp-ctx-fixture.test.ts +0 -108
- package/src/__test__/mcp-ctx-fixture.ts +0 -104
- package/src/cli.test.ts +0 -66
- package/src/cli.ts +0 -43
- package/src/commands/cliproxy/config.test.ts +0 -475
- package/src/commands/cliproxy/config.ts +0 -238
- package/src/commands/cliproxy/deploy.test.ts +0 -181
- package/src/commands/cliproxy/deploy.ts +0 -157
- package/src/commands/cliproxy/host.test.ts +0 -73
- package/src/commands/cliproxy/host.ts +0 -31
- package/src/commands/cliproxy/index.ts +0 -21
- package/src/commands/cliproxy/keys.test.ts +0 -326
- package/src/commands/cliproxy/keys.ts +0 -201
- package/src/commands/cliproxy/login.test.ts +0 -415
- package/src/commands/cliproxy/login.ts +0 -131
- package/src/commands/cliproxy/models.test.ts +0 -592
- package/src/commands/cliproxy/models.ts +0 -237
- package/src/commands/cliproxy/open.test.ts +0 -132
- package/src/commands/cliproxy/open.ts +0 -78
- package/src/commands/cliproxy/setup/gh.test.ts +0 -218
- package/src/commands/cliproxy/setup/gh.ts +0 -250
- package/src/commands/cliproxy/setup/preview.test.ts +0 -159
- package/src/commands/cliproxy/setup/preview.ts +0 -41
- package/src/commands/cliproxy/setup/prompts.test.ts +0 -58
- package/src/commands/cliproxy/setup/prompts.ts +0 -99
- package/src/commands/cliproxy/setup/providers.test.ts +0 -245
- package/src/commands/cliproxy/setup/providers.ts +0 -136
- package/src/commands/cliproxy/setup/smoke-test.test.ts +0 -821
- package/src/commands/cliproxy/setup/smoke-test.ts +0 -223
- package/src/commands/cliproxy/setup/templates.test.ts +0 -357
- package/src/commands/cliproxy/setup/templates.ts +0 -145
- package/src/commands/cliproxy/setup/validation.test.ts +0 -567
- package/src/commands/cliproxy/setup/validation.ts +0 -209
- package/src/commands/cliproxy/setup/workflow-analyzer.test.ts +0 -363
- package/src/commands/cliproxy/setup/workflow-analyzer.ts +0 -136
- package/src/commands/cliproxy/setup.test.ts +0 -2366
- package/src/commands/cliproxy/setup.ts +0 -809
- package/src/commands/cliproxy/shared.test.ts +0 -118
- package/src/commands/cliproxy/shared.ts +0 -84
- package/src/commands/cliproxy/status.test.ts +0 -1157
- package/src/commands/cliproxy/status.ts +0 -597
- package/src/commands/dashboard/deploy.test.ts +0 -215
- package/src/commands/dashboard/deploy.ts +0 -135
- package/src/commands/dashboard/host.test.ts +0 -79
- package/src/commands/dashboard/host.ts +0 -33
- package/src/commands/dashboard/index.ts +0 -13
- package/src/commands/dashboard/logs.test.ts +0 -317
- package/src/commands/dashboard/logs.ts +0 -180
- package/src/commands/dashboard/status.test.ts +0 -708
- package/src/commands/dashboard/status.ts +0 -293
- package/src/commands/gateway/backup.test.ts +0 -426
- package/src/commands/gateway/backup.ts +0 -205
- package/src/commands/gateway/deploy.test.ts +0 -491
- package/src/commands/gateway/deploy.ts +0 -173
- package/src/commands/gateway/host.test.ts +0 -89
- package/src/commands/gateway/host.ts +0 -33
- package/src/commands/gateway/index.ts +0 -17
- package/src/commands/gateway/logs.test.ts +0 -263
- package/src/commands/gateway/logs.ts +0 -160
- package/src/commands/gateway/restore.test.ts +0 -650
- package/src/commands/gateway/restore.ts +0 -308
- package/src/commands/gateway/status.test.ts +0 -755
- package/src/commands/gateway/status.ts +0 -255
- package/src/commands/keeweb/deploy.test.ts +0 -177
- package/src/commands/keeweb/deploy.ts +0 -191
- package/src/commands/keeweb/index.ts +0 -11
- package/src/commands/keeweb/open.test.ts +0 -54
- package/src/commands/keeweb/open.ts +0 -30
- package/src/commands/keeweb/status.test.ts +0 -509
- package/src/commands/keeweb/status.ts +0 -359
- package/src/commands/mcp.test.ts +0 -260
- package/src/commands/mcp.ts +0 -58
- package/src/commands/status.test.ts +0 -222
- package/src/commands/status.ts +0 -161
- package/src/commands/umami/deploy.test.ts +0 -202
- package/src/commands/umami/deploy.ts +0 -132
- package/src/commands/umami/host.test.ts +0 -79
- package/src/commands/umami/host.ts +0 -33
- package/src/commands/umami/index.ts +0 -13
- package/src/commands/umami/logs.test.ts +0 -191
- package/src/commands/umami/logs.ts +0 -163
- package/src/commands/umami/status.test.ts +0 -633
- package/src/commands/umami/status.ts +0 -285
- package/src/commands/vpn/client.test.ts +0 -949
- package/src/commands/vpn/client.ts +0 -467
- package/src/commands/vpn/deploy.test.ts +0 -208
- package/src/commands/vpn/deploy.ts +0 -143
- package/src/commands/vpn/host.test.ts +0 -89
- package/src/commands/vpn/host.ts +0 -36
- package/src/commands/vpn/index.ts +0 -15
- package/src/commands/vpn/logs.test.ts +0 -234
- package/src/commands/vpn/logs.ts +0 -136
- package/src/commands/vpn/peers.test.ts +0 -478
- package/src/commands/vpn/shared.test.ts +0 -454
- package/src/commands/vpn/shared.ts +0 -170
- package/src/commands/vpn/status.test.ts +0 -142
- package/src/commands/vpn/status.ts +0 -78
- package/src/conventions.test.ts +0 -1180
- package/src/lib/action-ctx.ts +0 -25
- package/src/lib/known-hosts.test.ts +0 -192
- package/src/lib/known-hosts.ts +0 -76
- package/src/lib/redact.ts +0 -21
- package/src/lib/ssh-identity.test.ts +0 -134
- package/src/lib/ssh-identity.ts +0 -76
- /package/{src/resources/known_hosts → dist/known_hosts-tk724cp0.} +0 -0
|
@@ -1,285 +0,0 @@
|
|
|
1
|
-
import type {goke} from 'goke'
|
|
2
|
-
import type {ActionCtx} from '../../lib/action-ctx'
|
|
3
|
-
import type {StatusSummary} from '../status'
|
|
4
|
-
import {z} from 'zod'
|
|
5
|
-
|
|
6
|
-
import {buildKnownHostsArgs} from '../../lib/known-hosts'
|
|
7
|
-
import {redactHost} from '../../lib/redact'
|
|
8
|
-
import {buildIdentityArgs} from '../../lib/ssh-identity'
|
|
9
|
-
import {validateUmamiHost} from './host'
|
|
10
|
-
|
|
11
|
-
declare const process: {
|
|
12
|
-
env: Record<string, string | undefined>
|
|
13
|
-
exitCode?: number
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
const COMPOSE_PROJECT_DIR = '/opt/umami'
|
|
17
|
-
|
|
18
|
-
// ─── Types ───────────────────────────────────────────────────────────────────
|
|
19
|
-
|
|
20
|
-
export interface ComposePsEntry {
|
|
21
|
-
Name: string
|
|
22
|
-
State: string
|
|
23
|
-
Health: string
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
export type HealthStatus = 'healthy' | 'unhealthy' | 'starting' | 'n-a'
|
|
27
|
-
|
|
28
|
-
export interface ServiceRow {
|
|
29
|
-
service: string
|
|
30
|
-
state: string
|
|
31
|
-
health: HealthStatus
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
export interface UmamiStatusResult {
|
|
35
|
-
ok: boolean
|
|
36
|
-
services: ServiceRow[]
|
|
37
|
-
error?: string
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
export type SpawnFn = (
|
|
41
|
-
cmd: string[],
|
|
42
|
-
opts: {env: Record<string, string>; stdout: 'pipe'; stderr: 'pipe'},
|
|
43
|
-
) => {
|
|
44
|
-
stdout: ReadableStream<Uint8Array>
|
|
45
|
-
stderr: ReadableStream<Uint8Array>
|
|
46
|
-
exited: Promise<number>
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
// ─── Pure helpers ─────────────────────────────────────────────────────────────
|
|
50
|
-
|
|
51
|
-
export function parseComposePsOutput(stdoutText: string): ComposePsEntry[] {
|
|
52
|
-
const trimmed = stdoutText.trim()
|
|
53
|
-
if (trimmed.length === 0) return []
|
|
54
|
-
|
|
55
|
-
// Legacy compose may emit a single JSON array; current versions emit NDJSON.
|
|
56
|
-
if (trimmed.startsWith('[')) {
|
|
57
|
-
const parsed: unknown = JSON.parse(trimmed)
|
|
58
|
-
return Array.isArray(parsed) ? (parsed as ComposePsEntry[]) : []
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
// NDJSON: one JSON object per non-empty line.
|
|
62
|
-
return trimmed
|
|
63
|
-
.split('\n')
|
|
64
|
-
.map(line => line.trim())
|
|
65
|
-
.filter(line => line.length > 0)
|
|
66
|
-
.map(line => JSON.parse(line) as ComposePsEntry)
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
function normalizeHealth(raw: string): HealthStatus {
|
|
70
|
-
if (raw === 'healthy' || raw === 'unhealthy' || raw === 'starting') {
|
|
71
|
-
return raw
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
return 'n-a'
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
export function parseComposePs(entries: ComposePsEntry[]): ServiceRow[] {
|
|
78
|
-
return entries.map(entry => ({
|
|
79
|
-
service: entry.Name,
|
|
80
|
-
state: entry.State,
|
|
81
|
-
health: normalizeHealth(entry.Health),
|
|
82
|
-
}))
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
export function isAllRunning(rows: ServiceRow[]): boolean {
|
|
86
|
-
return rows.every(row => row.state === 'running' && (row.health === 'healthy' || row.health === 'n-a'))
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
// ─── SSH-backed status fetch ──────────────────────────────────────────────────
|
|
90
|
-
|
|
91
|
-
function defaultSpawn(
|
|
92
|
-
cmd: string[],
|
|
93
|
-
opts: {env: Record<string, string>; stdout: 'pipe'; stderr: 'pipe'},
|
|
94
|
-
): ReturnType<SpawnFn> {
|
|
95
|
-
return Bun.spawn(cmd, opts) as ReturnType<SpawnFn>
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
export async function getUmamiComposeStatus(host: string, spawn: SpawnFn = defaultSpawn): Promise<UmamiStatusResult> {
|
|
99
|
-
validateUmamiHost(host)
|
|
100
|
-
|
|
101
|
-
const knownHostsArgs = buildKnownHostsArgs()
|
|
102
|
-
const {args: identityArgs, cleanup} = buildIdentityArgs(process.env.UMAMI_SSH_KEY)
|
|
103
|
-
|
|
104
|
-
const sshCmd = [
|
|
105
|
-
'ssh',
|
|
106
|
-
'-o',
|
|
107
|
-
'BatchMode=yes',
|
|
108
|
-
'-o',
|
|
109
|
-
'StrictHostKeyChecking=yes',
|
|
110
|
-
...knownHostsArgs,
|
|
111
|
-
...identityArgs,
|
|
112
|
-
`root@${host}`,
|
|
113
|
-
`docker compose --project-directory ${COMPOSE_PROJECT_DIR} ps --format json`,
|
|
114
|
-
]
|
|
115
|
-
|
|
116
|
-
const env: Record<string, string> = {
|
|
117
|
-
PATH: process.env.PATH ?? '/usr/bin:/bin',
|
|
118
|
-
HOME: process.env.HOME ?? '/tmp',
|
|
119
|
-
...(process.env.SSH_AUTH_SOCK ? {SSH_AUTH_SOCK: process.env.SSH_AUTH_SOCK} : {}),
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
let stdoutText: string
|
|
123
|
-
let stderrText: string
|
|
124
|
-
let exitCode: number
|
|
125
|
-
|
|
126
|
-
try {
|
|
127
|
-
const child = spawn(sshCmd, {env, stdout: 'pipe', stderr: 'pipe'})
|
|
128
|
-
;[stdoutText, stderrText, exitCode] = await Promise.all([
|
|
129
|
-
new Response(child.stdout).text(),
|
|
130
|
-
new Response(child.stderr).text(),
|
|
131
|
-
child.exited,
|
|
132
|
-
])
|
|
133
|
-
} finally {
|
|
134
|
-
cleanup()
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
if (exitCode !== 0) {
|
|
138
|
-
return {
|
|
139
|
-
ok: false,
|
|
140
|
-
services: [],
|
|
141
|
-
error: `SSH command failed (exit ${exitCode}): ${redactHost(stderrText.trim(), host) || 'unknown error'}`,
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
let entries: ComposePsEntry[]
|
|
146
|
-
|
|
147
|
-
try {
|
|
148
|
-
entries = parseComposePsOutput(stdoutText)
|
|
149
|
-
} catch {
|
|
150
|
-
return {
|
|
151
|
-
ok: false,
|
|
152
|
-
services: [],
|
|
153
|
-
error: `Failed to parse docker compose ps output: ${redactHost(stdoutText.slice(0, 200), host)}`,
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
const services = parseComposePs(entries)
|
|
158
|
-
const ok = isAllRunning(services)
|
|
159
|
-
|
|
160
|
-
return {ok, services}
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
// ─── Unified status aggregator export ────────────────────────────────────────
|
|
164
|
-
|
|
165
|
-
export async function getUmamiStatusSummary(host: string, spawn?: SpawnFn): Promise<StatusSummary> {
|
|
166
|
-
let result: UmamiStatusResult
|
|
167
|
-
|
|
168
|
-
try {
|
|
169
|
-
result = await getUmamiComposeStatus(host, spawn)
|
|
170
|
-
} catch (error) {
|
|
171
|
-
const errorMsg = error instanceof Error ? error.message : String(error)
|
|
172
|
-
return {
|
|
173
|
-
app: 'umami',
|
|
174
|
-
http: `ERROR: ${errorMsg}`,
|
|
175
|
-
lastDeploy: '—',
|
|
176
|
-
version: '—',
|
|
177
|
-
contentHash: '—',
|
|
178
|
-
usageStats: '—',
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
// Three-way split: no services → ERROR, services present but degraded → DEGRADED, all healthy → OK
|
|
183
|
-
if (result.services.length === 0) {
|
|
184
|
-
const errorMsg = result.error ?? 'No services reported'
|
|
185
|
-
return {
|
|
186
|
-
app: 'umami',
|
|
187
|
-
http: `ERROR: ${errorMsg}`,
|
|
188
|
-
lastDeploy: '—',
|
|
189
|
-
version: '—',
|
|
190
|
-
contentHash: '—',
|
|
191
|
-
usageStats: '—',
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
const rows = result.services.map(s => `${s.service}:${s.state}/${s.health}`).join(', ')
|
|
196
|
-
|
|
197
|
-
if (!result.ok) {
|
|
198
|
-
return {
|
|
199
|
-
app: 'umami',
|
|
200
|
-
http: `DEGRADED: ${rows}`,
|
|
201
|
-
lastDeploy: '—',
|
|
202
|
-
version: '—',
|
|
203
|
-
contentHash: '—',
|
|
204
|
-
usageStats: '—',
|
|
205
|
-
}
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
return {
|
|
209
|
-
app: 'umami',
|
|
210
|
-
http: `OK: ${rows}`,
|
|
211
|
-
lastDeploy: '—',
|
|
212
|
-
version: '—',
|
|
213
|
-
contentHash: '—',
|
|
214
|
-
usageStats: '—',
|
|
215
|
-
}
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
// ─── Action (exported for direct testing) ────────────────────────────────────
|
|
219
|
-
|
|
220
|
-
export async function umamiStatusAction(
|
|
221
|
-
options: {key?: string | undefined},
|
|
222
|
-
ctx: ActionCtx,
|
|
223
|
-
spawn?: SpawnFn,
|
|
224
|
-
): Promise<void> {
|
|
225
|
-
const hostEnvKey = options.key ?? 'UMAMI_DOMAIN'
|
|
226
|
-
const host = process.env[hostEnvKey]
|
|
227
|
-
|
|
228
|
-
if (!host) {
|
|
229
|
-
ctx.console.error('Umami host not set. Export UMAMI_DOMAIN or pass --key <env-name> pointing to a set variable.')
|
|
230
|
-
ctx.process.exit(1)
|
|
231
|
-
return
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
ctx.console.log('Umami status')
|
|
235
|
-
ctx.console.log('')
|
|
236
|
-
|
|
237
|
-
let result: UmamiStatusResult
|
|
238
|
-
|
|
239
|
-
try {
|
|
240
|
-
result = await getUmamiComposeStatus(host, spawn)
|
|
241
|
-
} catch (error) {
|
|
242
|
-
ctx.console.error(`Error: ${error instanceof Error ? error.message : String(error)}`)
|
|
243
|
-
ctx.process.exit(1)
|
|
244
|
-
return
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
if (result.services.length === 0) {
|
|
248
|
-
ctx.console.error(`Error: No services reported by docker compose ps`)
|
|
249
|
-
ctx.process.exit(1)
|
|
250
|
-
return
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
ctx.console.log('Service State Health')
|
|
254
|
-
ctx.console.log('─────────────────────────────────────')
|
|
255
|
-
|
|
256
|
-
for (const row of result.services) {
|
|
257
|
-
const svc = row.service.padEnd(16)
|
|
258
|
-
const state = row.state.padEnd(10)
|
|
259
|
-
ctx.console.log(`${svc} ${state} ${row.health}`)
|
|
260
|
-
}
|
|
261
|
-
|
|
262
|
-
ctx.console.log('')
|
|
263
|
-
|
|
264
|
-
if (result.ok) {
|
|
265
|
-
ctx.console.log('Status: OK')
|
|
266
|
-
} else {
|
|
267
|
-
ctx.console.log('Status: DEGRADED (one or more services not running)')
|
|
268
|
-
ctx.process.exit(1)
|
|
269
|
-
}
|
|
270
|
-
}
|
|
271
|
-
|
|
272
|
-
// ─── Command registration ─────────────────────────────────────────────────────
|
|
273
|
-
|
|
274
|
-
export function registerUmamiStatus(cli: ReturnType<typeof goke>): void {
|
|
275
|
-
cli
|
|
276
|
-
.command('umami status', 'Show operational health of the Umami analytics deployment via docker compose ps.')
|
|
277
|
-
.option(
|
|
278
|
-
'--key [key]',
|
|
279
|
-
z
|
|
280
|
-
.string()
|
|
281
|
-
.optional()
|
|
282
|
-
.describe('Environment variable name holding the SSH host. Falls back to UMAMI_DOMAIN when omitted.'),
|
|
283
|
-
)
|
|
284
|
-
.action((options, ctx) => umamiStatusAction(options, ctx))
|
|
285
|
-
}
|