Ops-dashboard/lib/parse-docker.ts
Scrum4Me Agent 90eacc963d feat(docker): agent-client helper, Docker container list page
- lib/agent-client.ts: server-side execAgent() that calls the ops-agent
  directly via OPS_AGENT_URL/OPS_AGENT_SECRET and streams SSE output
- lib/parse-docker.ts: pure parser for fixed-width docker ps table output
- app/docker/page.tsx: server component that fetches initial container list
  and passes it to the client component
- app/docker/_components/docker-table.tsx: client component with 5s
  auto-refresh via useEffect, status badge, and Link to /docker/[name]
- app/docker/[name]/page.tsx: placeholder detail page (logs in Story 3)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-13 17:27:35 +02:00

40 lines
1.1 KiB
TypeScript

export type Container = {
id: string
image: string
command: string
created: string
status: string
ports: string
name: string
}
// Parse the fixed-width table output of `docker ps --format table`
export function parseDockerPs(output: string): Container[] {
const lines = output.trim().split('\n').filter(Boolean)
if (lines.length < 2) return []
const header = lines[0]
const COLS = ['CONTAINER ID', 'IMAGE', 'COMMAND', 'CREATED', 'STATUS', 'PORTS', 'NAMES'] as const
const positions = COLS.map((col) => header.indexOf(col))
// Must find at least NAMES (last) to produce useful output
if (positions[6] === -1) return []
const extract = (line: string, i: number): string => {
const start = positions[i]
if (start === -1) return ''
const nextIdx = positions.slice(i + 1).find((p) => p !== -1)
return line.slice(start, nextIdx).trim()
}
return lines.slice(1).map((line) => ({
id: extract(line, 0),
image: extract(line, 1),
command: extract(line, 2),
created: extract(line, 3),
status: extract(line, 4),
ports: extract(line, 5),
name: extract(line, 6),
}))
}