garaje 0.1.0 → 0.1.1
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 +0 -0
- package/package.json +1 -1
- package/dist/host/compose.js +0 -65
package/dist/cli.js
CHANGED
|
File without changes
|
package/package.json
CHANGED
package/dist/host/compose.js
DELETED
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
import { spawnSync } from "node:child_process";
|
|
2
|
-
import { existsSync, readFileSync } from "node:fs";
|
|
3
|
-
import { join } from "node:path";
|
|
4
|
-
/**
|
|
5
|
-
* The argv to pass after `docker compose`. Mirrors bin/_lib.sh `compose`:
|
|
6
|
-
* always `-f docker-compose.yml`, layer `-f compose.bays.yaml` when present,
|
|
7
|
-
* and prepend `-p <name>` when the garaje declares one.
|
|
8
|
-
*/
|
|
9
|
-
export function composeArgs(ctx, extra) {
|
|
10
|
-
const files = ["-f", "docker-compose.yml"];
|
|
11
|
-
if (ctx.hasBaysCompose)
|
|
12
|
-
files.push("-f", "compose.bays.yaml");
|
|
13
|
-
const project = ctx.name ? ["-p", ctx.name] : [];
|
|
14
|
-
return [...project, ...files, ...extra];
|
|
15
|
-
}
|
|
16
|
-
/** The committed compose project name — the first top-level `name:` line. */
|
|
17
|
-
export function readProjectName(root) {
|
|
18
|
-
const path = join(root, "garaje.yaml");
|
|
19
|
-
if (!existsSync(path))
|
|
20
|
-
return undefined;
|
|
21
|
-
for (const line of readFileSync(path, "utf8").split(/\r?\n/)) {
|
|
22
|
-
const m = /^name:\s*(.+?)\s*$/.exec(line);
|
|
23
|
-
if (m)
|
|
24
|
-
return m[1].replace(/^["']|["']$/g, "");
|
|
25
|
-
}
|
|
26
|
-
return undefined;
|
|
27
|
-
}
|
|
28
|
-
export function composeContext(root) {
|
|
29
|
-
return {
|
|
30
|
-
name: readProjectName(root),
|
|
31
|
-
hasBaysCompose: existsSync(join(root, "compose.bays.yaml")),
|
|
32
|
-
};
|
|
33
|
-
}
|
|
34
|
-
/** Run `docker compose` from the repo root, inheriting stdio; returns exit code. */
|
|
35
|
-
export function compose(root, extra) {
|
|
36
|
-
const args = composeArgs(composeContext(root), extra);
|
|
37
|
-
return spawnSync("docker", ["compose", ...args], { cwd: root, stdio: "inherit" }).status ?? 1;
|
|
38
|
-
}
|
|
39
|
-
/** Run `docker compose` and capture stdout/stderr instead of inheriting. */
|
|
40
|
-
export function composeCapture(root, extra) {
|
|
41
|
-
const args = composeArgs(composeContext(root), extra);
|
|
42
|
-
const r = spawnSync("docker", ["compose", ...args], { cwd: root, encoding: "utf8" });
|
|
43
|
-
return { status: r.status ?? 1, stdout: r.stdout ?? "", stderr: r.stderr ?? "" };
|
|
44
|
-
}
|
|
45
|
-
/** Like composeCapture, but feeds `input` to the process's stdin. */
|
|
46
|
-
export function composeCaptureInput(root, extra, input) {
|
|
47
|
-
const args = composeArgs(composeContext(root), extra);
|
|
48
|
-
const r = spawnSync("docker", ["compose", ...args], { cwd: root, encoding: "utf8", input });
|
|
49
|
-
return { status: r.status ?? 1, stdout: r.stdout ?? "", stderr: r.stderr ?? "" };
|
|
50
|
-
}
|
|
51
|
-
/**
|
|
52
|
-
* Start the stack if the `pi` service isn't already running. Returns 0 when pi
|
|
53
|
-
* is (or becomes) running, else the non-zero `up -d` exit code so callers can
|
|
54
|
-
* bail cleanly instead of exec-ing against a stack that failed to start. The
|
|
55
|
-
* running-check is inlined (rather than importing pi.ts's parseRunningServices)
|
|
56
|
-
* to avoid a compose ↔ pi import cycle — pi.ts already imports from compose.ts.
|
|
57
|
-
*/
|
|
58
|
-
export function ensurePiRunning(root) {
|
|
59
|
-
const ps = composeCapture(root, ["ps", "--status", "running", "--services"]);
|
|
60
|
-
const running = ps.stdout.split(/\r?\n/).map((l) => l.trim()).filter(Boolean);
|
|
61
|
-
if (running.includes("pi"))
|
|
62
|
-
return 0;
|
|
63
|
-
process.stderr.write("(pi container not running; starting the stack)\n");
|
|
64
|
-
return compose(root, ["up", "-d"]);
|
|
65
|
-
}
|