UNPKG

everything-dev

Version:

A consolidated product package for building Module Federation apps with oRPC APIs.

1 lines • 3.89 kB
{"version":3,"file":"docker.cjs","names":["join","stripAnsi","existsSync","process"],"sources":["../../src/infra/docker.ts"],"sourcesContent":["import { existsSync } from \"node:fs\";\nimport { join } from \"node:path\";\nimport process from \"node:process\";\nimport { execa } from \"execa\";\nimport { stripAnsi } from \"../dev-log-pipeline\";\nimport type { PreflightFailure } from \"./preflight\";\n\nexport interface DockerAutostartGuards {\n composeFileExists: boolean;\n dockerAvailable: boolean;\n testMode: boolean;\n}\n\nexport interface DockerComposeResult {\n ok: boolean;\n tail: string;\n}\n\nconst TAIL_LINES = 15;\n\nexport function takeTail(lines: string[], count: number = TAIL_LINES): string {\n return lines.slice(-count).join(\"\\n\").trim();\n}\n\nexport function composeFilePath(configDir: string): string {\n return join(configDir, \"docker-compose.yml\");\n}\n\nexport function isDockerTestMode(env: Record<string, string | undefined>): boolean {\n return env.BOS_TEST === \"1\" || env.NODE_ENV === \"test\" || env.BOS_NO_PERSIST_PORTS === \"1\";\n}\n\nexport function shouldAutoStartDocker(\n failures: PreflightFailure[],\n guards: DockerAutostartGuards,\n): boolean {\n if (failures.length === 0) return false;\n if (guards.testMode || !guards.dockerAvailable || !guards.composeFileExists) return false;\n return failures.every((failure) => failure.tcpReachable === false);\n}\n\nexport async function isDockerAvailable(): Promise<boolean> {\n try {\n const result = await execa(\"docker\", [\"info\"], { stdio: \"pipe\", reject: false, timeout: 5000 });\n return (result.exitCode ?? 1) === 0;\n } catch {\n return false;\n }\n}\n\nexport async function runDockerComposeUp(configDir: string): Promise<DockerComposeResult> {\n try {\n const result = await execa(\"docker\", [\"compose\", \"up\", \"-d\", \"--wait\"], {\n cwd: configDir,\n stdio: \"pipe\",\n reject: false,\n timeout: 5 * 60_000,\n });\n const lines = [result.stdout ?? \"\", result.stderr ?? \"\"]\n .flatMap((output) => output.split(\"\\n\"))\n .map((line) => stripAnsi(line).trim())\n .filter((line) => line.length > 0);\n return { ok: (result.exitCode ?? 1) === 0, tail: takeTail(lines) };\n } catch (error) {\n return { ok: false, tail: error instanceof Error ? error.message : String(error) };\n }\n}\n\nexport function detectAutoStartContext(configDir: string): DockerAutostartGuards {\n return {\n composeFileExists: existsSync(composeFilePath(configDir)),\n dockerAvailable: false,\n testMode: isDockerTestMode(process.env as Record<string, string | undefined>),\n };\n}\n"],"mappings":";;;;;;;;;AAkBA,MAAM,aAAa;AAEnB,SAAgB,SAAS,OAAiB,QAAgB,YAAoB;CAC5E,OAAO,MAAM,MAAM,CAAC,KAAK,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,KAAK;AAC7C;AAEA,SAAgB,gBAAgB,WAA2B;CACzD,WAAOA,gBAAK,WAAW,oBAAoB;AAC7C;AAEA,SAAgB,iBAAiB,KAAkD;CACjF,OAAO,IAAI,aAAa,OAAO,IAAI,aAAa,UAAU,IAAI,yBAAyB;AACzF;AAEA,SAAgB,sBACd,UACA,QACS;CACT,IAAI,SAAS,WAAW,GAAG,OAAO;CAClC,IAAI,OAAO,YAAY,CAAC,OAAO,mBAAmB,CAAC,OAAO,mBAAmB,OAAO;CACpF,OAAO,SAAS,OAAO,YAAY,QAAQ,iBAAiB,KAAK;AACnE;AAEA,eAAsB,oBAAsC;CAC1D,IAAI;EAEF,SAAQ,UADa,aAAM,UAAU,CAAC,MAAM,GAAG;GAAE,OAAO;GAAQ,QAAQ;GAAO,SAAS;EAAK,CAAC,EAChF,CAAC,YAAY,OAAO;CACpC,QAAQ;EACN,OAAO;CACT;AACF;AAEA,eAAsB,mBAAmB,WAAiD;CACxF,IAAI;EACF,MAAM,SAAS,UAAM,aAAM,UAAU;GAAC;GAAW;GAAM;GAAM;EAAQ,GAAG;GACtE,KAAK;GACL,OAAO;GACP,QAAQ;GACR,SAAS;EACX,CAAC;EACD,MAAM,QAAQ,CAAC,OAAO,UAAU,IAAI,OAAO,UAAU,EAAE,CAAC,CACrD,SAAS,WAAW,OAAO,MAAM,IAAI,CAAC,CAAC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