@yunuseon/kayra 0.16.1 → 0.17.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/README.md +4 -0
- package/ansible/roles/platform/tasks/main.yml +31 -0
- package/cli/dist/browser/assets/{index-3W_NFATj.css → index-Ct0Eudk4.css} +1 -1
- package/cli/dist/browser/assets/index-hcyM6f6T.js +7 -0
- package/cli/dist/browser/assets/xterm-CerOhKYV.js +16 -0
- package/cli/dist/browser/index.html +2 -2
- package/cli/dist/clients/api/api.js +189 -0
- package/cli/dist/clients/api/auth.js +37 -0
- package/cli/dist/clients/api/commands.js +63 -0
- package/cli/dist/clients/api/contract.gen.js +1 -0
- package/cli/dist/clients/api/contract.js +91 -0
- package/cli/dist/clients/api/directories.js +20 -0
- package/cli/dist/clients/api/discovery.js +43 -0
- package/cli/dist/clients/api/live.js +40 -0
- package/cli/dist/clients/api/protocol.js +68 -0
- package/cli/dist/clients/api/queries.js +20 -0
- package/cli/dist/{web → clients/api}/runs.js +14 -11
- package/cli/dist/clients/api/start.js +97 -0
- package/cli/dist/clients/api/status.js +29 -0
- package/cli/dist/clients/api/validate.js +13 -0
- package/cli/dist/{ui → clients/cli}/explain.js +10 -8
- package/cli/dist/clients/cli/framed.js +67 -0
- package/cli/dist/clients/cli/invocation.js +84 -0
- package/cli/dist/clients/cli/paint.js +23 -0
- package/cli/dist/{cli.js → clients/cli/parser.js} +38 -32
- package/cli/dist/clients/cli/questions.js +89 -0
- package/cli/dist/clients/cli/status.js +75 -0
- package/cli/dist/{ui → clients/cli}/terminal.js +5 -15
- package/cli/dist/{ui → clients/cli}/text.js +15 -24
- package/cli/dist/clients/cli/validate.js +32 -0
- package/cli/dist/clients/cli/values.js +19 -0
- package/cli/dist/{ui → clients/cli}/views.js +28 -60
- package/cli/dist/clients/ui/assets.js +36 -0
- package/cli/dist/core/adapters/fs.js +18 -0
- package/cli/dist/{net.js → core/adapters/network.js} +20 -5
- package/cli/dist/core/adapters/opentofu.js +24 -0
- package/cli/dist/core/ctl/answers.js +32 -0
- package/cli/dist/core/fleet/brand.js +45 -0
- package/cli/dist/{schemas.js → core/fleet/docs.js} +4 -3
- package/cli/dist/core/fleet/load.js +44 -0
- package/cli/dist/core/fleet/model.js +1 -0
- package/cli/dist/{fleet.js → core/fleet/parse.js} +61 -41
- package/cli/dist/{settings.js → core/fleet/settings.js} +10 -3
- package/cli/dist/{validate.js → core/fleet/shape.js} +6 -5
- package/cli/dist/core/interpreter/events.js +81 -0
- package/cli/dist/core/interpreter/io.js +18 -0
- package/cli/dist/core/interpreter/loop.js +101 -0
- package/cli/dist/core/interpreter/needs.js +47 -0
- package/cli/dist/core/interpreter/process.js +107 -0
- package/cli/dist/core/interpreter/progress.js +15 -0
- package/cli/dist/core/interpreter/pty.js +8 -0
- package/cli/dist/core/operations/catalog.js +169 -0
- package/cli/dist/core/operations/dispatch.js +142 -0
- package/cli/dist/{plan.js → core/plan/describe.js} +13 -16
- package/cli/dist/core/plan/model.js +14 -0
- package/cli/dist/{commands → core/recipes}/app-check.js +11 -16
- package/cli/dist/core/recipes/apps.js +63 -0
- package/cli/dist/core/recipes/backup.js +34 -0
- package/cli/dist/core/recipes/certs.js +4 -0
- package/cli/dist/{commands → core/recipes}/doctor.js +20 -35
- package/cli/dist/core/recipes/host.js +104 -0
- package/cli/dist/core/recipes/ssh.js +20 -0
- package/cli/dist/core/recipes/steps.js +82 -0
- package/cli/dist/core/status/look.js +55 -0
- package/cli/dist/core/status/model.js +6 -0
- package/cli/dist/core/status/ports.js +1 -0
- package/cli/dist/core/status/updates.js +13 -0
- package/cli/dist/core/text/plural.js +2 -0
- package/cli/dist/core/text/spans.js +22 -0
- package/cli/dist/core/text/time.js +12 -0
- package/cli/dist/core/validation/facts.js +49 -0
- package/cli/dist/{commands/validate.js → core/validation/findings.js} +31 -66
- package/cli/dist/deployer/app.js +2 -1
- package/cli/dist/deployer/{builder.js → build/builder.js} +14 -13
- package/cli/dist/deployer/{bundle.js → build/bundle.js} +8 -7
- package/cli/dist/deployer/{compose.js → build/compose.js} +8 -7
- package/cli/dist/deployer/cron.js +2 -2
- package/cli/dist/deployer/{answers.js → ctl/answers.js} +5 -4
- package/cli/dist/deployer/{ctl.js → ctl/ctl.js} +3 -3
- package/cli/dist/deployer/deployer.js +23 -22
- package/cli/dist/deployer/{forge.js → forges/forge.js} +2 -1
- package/cli/dist/deployer/{forgejo.js → forges/forgejo.js} +2 -2
- package/cli/dist/deployer/{github.js → forges/github.js} +2 -2
- package/cli/dist/deployer/{gitlab.js → forges/gitlab.js} +2 -2
- package/cli/dist/deployer/{github-issues.js → forges/issues.js} +5 -4
- package/cli/dist/deployer/{notify.js → forges/notify.js} +9 -8
- package/cli/dist/deployer/{http.js → http/http.js} +1 -0
- package/cli/dist/deployer/{page.js → http/page.js} +1 -1
- package/cli/dist/deployer/{webhook.js → http/webhook.js} +2 -1
- package/cli/dist/deployer/main.js +2 -2
- package/cli/dist/deployer/{queue.js → runs/queue.js} +4 -3
- package/cli/dist/deployer/{records.js → runs/records.js} +9 -8
- package/cli/dist/deployer/{run.js → runs/run.js} +10 -9
- package/cli/dist/deployer/{store.js → runs/store.js} +9 -8
- package/cli/dist/main.js +98 -99
- package/cli/dist/result.js +11 -1
- package/cli/dist/serve.js +77 -0
- package/cli/dist/typed.js +2 -0
- package/package.json +4 -2
- package/scripts/agent/guard.sh +9 -2
- package/scripts/local/packed-runs.sh +20 -5
- package/scripts/local/setup-hosts.sh +9 -2
- package/cli/dist/brand.js +0 -39
- package/cli/dist/browser/assets/index-DRFX9Q77.js +0 -2
- package/cli/dist/commands/index.js +0 -52
- package/cli/dist/commands/server.js +0 -289
- package/cli/dist/commands/status.js +0 -194
- package/cli/dist/gather.js +0 -61
- package/cli/dist/interpret.js +0 -141
- package/cli/dist/load.js +0 -64
- package/cli/dist/ui/line.js +0 -39
- package/cli/dist/ui/progress.js +0 -144
- package/cli/dist/web/auth.js +0 -36
- package/cli/dist/web/commands.js +0 -102
- package/cli/dist/web/contract.js +0 -7
- package/cli/dist/web/server.js +0 -336
- /package/cli/dist/{web → clients/ui}/opener.js +0 -0
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { chmodSync, mkdtempSync, rmSync, writeFileSync } from "node:fs";
|
|
2
|
+
import { tmpdir } from "node:os";
|
|
3
|
+
import { join } from "node:path";
|
|
4
|
+
import { active, muted, strong } from "../text/spans.js";
|
|
5
|
+
import { ask } from "./io.js";
|
|
6
|
+
import { spawned } from "./process.js";
|
|
7
|
+
import { typed } from "../../typed.js";
|
|
8
|
+
const keyOf = (need) => (need.kind === "vault" ? `vault:${need.server}` : "sudo");
|
|
9
|
+
const questionOf = (need) => typed(need.kind === "vault" ? { kind: "secret", text: [" ", active("?"), " ", strong(`${need.server}'s vault password`), muted(" (asked once, kept for this run): ")] } : { kind: "secret", text: [" ", active("?"), " ", strong("sudo's password"), muted(" (for this step only): ")] });
|
|
10
|
+
/** Whether sudo would run without a password: a cached one, or none needed. */
|
|
11
|
+
const sudoReady = async (plumbing) => (await spawned(["sudo", "-n", "true"], { stdout: "discard", stderr: "capture", stdin: { kind: "none" } }, {}, plumbing)).code === 0;
|
|
12
|
+
export const scratch = () => {
|
|
13
|
+
// eslint-disable-next-line functional/prefer-immutable-types -- made on first need, removed when the run ends
|
|
14
|
+
const made = {};
|
|
15
|
+
const dir = () => {
|
|
16
|
+
// eslint-disable-next-line functional/immutable-data -- see above
|
|
17
|
+
made.dir ??= mkdtempSync(join(tmpdir(), "kayra-"));
|
|
18
|
+
return made.dir;
|
|
19
|
+
};
|
|
20
|
+
return typed({
|
|
21
|
+
vaultScript: () => {
|
|
22
|
+
const script = join(dir(), "vault-password");
|
|
23
|
+
writeFileSync(script, '#!/bin/sh\nprintf \'%s\\n\' "$KAYRA_VAULT_PASSWORD"\n', { mode: 0o700 });
|
|
24
|
+
chmodSync(script, 0o700);
|
|
25
|
+
return script;
|
|
26
|
+
},
|
|
27
|
+
clean: () => {
|
|
28
|
+
if (made.dir !== undefined)
|
|
29
|
+
rmSync(made.dir, { recursive: true, force: true });
|
|
30
|
+
},
|
|
31
|
+
});
|
|
32
|
+
};
|
|
33
|
+
/** Asks what a step needs and has not been given yet in this run; undefined if the operator gave nothing. */
|
|
34
|
+
export const meet = async (needs, asked, io, made) => needs.reduce(async (previous, need) => {
|
|
35
|
+
const so = await previous;
|
|
36
|
+
if (so === undefined)
|
|
37
|
+
return undefined;
|
|
38
|
+
if (need.kind === "sudo" && (await sudoReady(io)))
|
|
39
|
+
return so;
|
|
40
|
+
const key = keyOf(need);
|
|
41
|
+
const given = so.asked[key] ?? (await ask(io, questionOf(need)));
|
|
42
|
+
// An empty password is none: Enter alone declines.
|
|
43
|
+
if (given === undefined || given === "")
|
|
44
|
+
return undefined;
|
|
45
|
+
const now = need.kind === "vault" ? { ...so.asked, [key]: given } : so.asked;
|
|
46
|
+
return typed(need.kind === "vault" ? { asked: now, met: { ...so.met, env: { ...so.met.env, ANSIBLE_VAULT_PASSWORD_FILE: made.vaultScript(), KAYRA_VAULT_PASSWORD: given } } } : { asked: now, met: { env: { ...so.met.env, KAYRA_SUDO_STDIN: "1" }, stdin: { kind: "given", text: `${given}\n` } } });
|
|
47
|
+
}, Promise.resolve({ met: { env: {} }, asked }));
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { spawn } from "node:child_process";
|
|
2
|
+
import { text } from "node:stream/consumers";
|
|
3
|
+
import { all, err, flatMap, ok } from "../../result.js";
|
|
4
|
+
import { isStopped } from "./io.js";
|
|
5
|
+
import { exitCode } from "../fleet/brand.js";
|
|
6
|
+
import { typed } from "../../typed.js";
|
|
7
|
+
const terminal = {};
|
|
8
|
+
/** A program that ignores SIGINT this long gets SIGTERM. */
|
|
9
|
+
const patience = 10_000;
|
|
10
|
+
export const spawned = async (argv, streams, env = {}, plumbing = terminal) => {
|
|
11
|
+
const [program, ...args] = argv;
|
|
12
|
+
const { output, signal } = plumbing;
|
|
13
|
+
if (isStopped(signal))
|
|
14
|
+
return typed({ code: exitCode(130), stdout: "", stderr: "", started: false });
|
|
15
|
+
const shown = (stream) => stream === "show" ? (typed(output === undefined ? "inherit" : "pipe")) : typed(stream === "capture" ? "pipe" : "ignore");
|
|
16
|
+
const stdin = streams.stdin ?? (output === undefined ? { kind: "inherit" } : { kind: "none" });
|
|
17
|
+
const child = spawn(program, args, {
|
|
18
|
+
env: { ...process.env, ...env },
|
|
19
|
+
detached: output !== undefined,
|
|
20
|
+
stdio: [stdin.kind === "inherit" ? "inherit" : stdin.kind === "none" ? "ignore" : "pipe", shown(streams.stdout), shown(streams.stderr)],
|
|
21
|
+
});
|
|
22
|
+
const forward = (from, sink) => {
|
|
23
|
+
child[from]?.setEncoding("utf8").on("data", (chunk) => {
|
|
24
|
+
sink(chunk, from);
|
|
25
|
+
});
|
|
26
|
+
};
|
|
27
|
+
if (output !== undefined && streams.stdout === "show")
|
|
28
|
+
forward("stdout", output);
|
|
29
|
+
if (output !== undefined && streams.stderr === "show")
|
|
30
|
+
forward("stderr", output);
|
|
31
|
+
// A program that exits before reading all it was given must not take kayra down with EPIPE.
|
|
32
|
+
child.stdin?.on("error", () => undefined);
|
|
33
|
+
if (stdin.kind === "given")
|
|
34
|
+
child.stdin?.end(stdin.text);
|
|
35
|
+
const unsubscribe = stdin.kind === "typed"
|
|
36
|
+
? stdin.input((chunk) => {
|
|
37
|
+
child.stdin?.write(chunk);
|
|
38
|
+
})
|
|
39
|
+
: () => undefined;
|
|
40
|
+
const read = (from, stream) => {
|
|
41
|
+
const piped = child[from];
|
|
42
|
+
return piped === null || stream !== "capture" ? Promise.resolve("") : text(piped);
|
|
43
|
+
};
|
|
44
|
+
const stdout = read("stdout", streams.stdout);
|
|
45
|
+
const stderr = read("stderr", streams.stderr);
|
|
46
|
+
const kill = (withSignal) => {
|
|
47
|
+
if (child.pid === undefined)
|
|
48
|
+
return;
|
|
49
|
+
try {
|
|
50
|
+
if (output === undefined)
|
|
51
|
+
child.kill(withSignal);
|
|
52
|
+
else
|
|
53
|
+
process.kill(-child.pid, withSignal);
|
|
54
|
+
}
|
|
55
|
+
catch (error) {
|
|
56
|
+
if (!(error instanceof Error && "code" in error && error.code === "ESRCH"))
|
|
57
|
+
throw error;
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
// eslint-disable-next-line functional/prefer-immutable-types -- the escalation belongs to this child, cleared when it exits
|
|
61
|
+
const stopping = {};
|
|
62
|
+
const stop = () => {
|
|
63
|
+
if (stopping.timer !== undefined)
|
|
64
|
+
return;
|
|
65
|
+
if (stdin.kind === "typed")
|
|
66
|
+
child.stdin?.write("\u0003");
|
|
67
|
+
kill("SIGINT");
|
|
68
|
+
// eslint-disable-next-line functional/immutable-data -- see above
|
|
69
|
+
stopping.timer = setTimeout(() => { kill("SIGTERM"); }, patience);
|
|
70
|
+
stopping.timer.unref();
|
|
71
|
+
};
|
|
72
|
+
// The process group exists only once Node confirms the child has spawned.
|
|
73
|
+
child.once("spawn", () => {
|
|
74
|
+
signal?.addEventListener("abort", stop, { once: true });
|
|
75
|
+
if (isStopped(signal))
|
|
76
|
+
stop();
|
|
77
|
+
});
|
|
78
|
+
const exit = await new Promise((resolve) => {
|
|
79
|
+
child.on("error", resolve);
|
|
80
|
+
child.on("close", (code) => {
|
|
81
|
+
resolve(code ?? 1);
|
|
82
|
+
});
|
|
83
|
+
});
|
|
84
|
+
signal?.removeEventListener("abort", stop);
|
|
85
|
+
clearTimeout(stopping.timer);
|
|
86
|
+
unsubscribe();
|
|
87
|
+
return typed(exit instanceof Error ? { code: exitCode(127), stdout: "", stderr: exit.message, started: false } : { code: exitCode(exit), stdout: await stdout, stderr: await stderr, started: true });
|
|
88
|
+
};
|
|
89
|
+
/** A command's stdout, for kayra to read; its stderr reaches the operator unless captured too. */
|
|
90
|
+
export const capture = (argv, stderr = "show", env = {}, plumbing = terminal) => spawned(argv, { stdout: "capture", stderr }, env, plumbing);
|
|
91
|
+
export const answer = (probe, plumbing) => spawned(probe.kind === "on-path" ? ["sh", "-c", 'command -v "$1"', "sh", probe.program] : probe.argv, { stdout: "discard", stderr: "capture", stdin: { kind: "none" } }, probe.kind === "exits-zero" ? probe.env : {}, plumbing);
|
|
92
|
+
/** Each query's answer in place of it, as `$(…)` would: one word, or split into many. */
|
|
93
|
+
export const resolve = async (argv, plumbing) => {
|
|
94
|
+
const words = await Promise.all(argv.map(async (value) => {
|
|
95
|
+
if (typeof value === "string")
|
|
96
|
+
return ok([value]);
|
|
97
|
+
const exit = await capture(value.argv, "show", value.env, plumbing);
|
|
98
|
+
if (exit.code !== 0)
|
|
99
|
+
return err(`$(${value.argv.join(" ")}) failed: exit ${String(exit.code)}`);
|
|
100
|
+
const output = exit.stdout.replace(/\n+$/, "");
|
|
101
|
+
return ok(value.words === "one" ? [output] : output.split(/\s+/).filter((word) => word !== ""));
|
|
102
|
+
}));
|
|
103
|
+
return flatMap(all(words), (lists) => {
|
|
104
|
+
const [program, ...rest] = lists.flat();
|
|
105
|
+
return program === undefined ? err("the command is empty") : ok([program, ...rest]);
|
|
106
|
+
});
|
|
107
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { typed } from "../../typed.js";
|
|
2
|
+
/** Why a plan stopped before its end. */
|
|
3
|
+
export const stopReasons = ["failed", "declined", "interrupted"];
|
|
4
|
+
/** Nothing around the steps: for commands whose output is the point (ssh, logs), and for tests. */
|
|
5
|
+
export const silent = {
|
|
6
|
+
plan: (_plan, work) => work(),
|
|
7
|
+
step: (_step, _at, work) => work(),
|
|
8
|
+
};
|
|
9
|
+
export const parts = (plan) => typed([...new Set(plan.flatMap((step) => (step.part === undefined ? Object.freeze([]) : Object.freeze([step.part]))))]);
|
|
10
|
+
/** Where the step at `index` is, for a plan that may consist of several parts. */
|
|
11
|
+
export const position = (plan, index) => {
|
|
12
|
+
const part = plan[index]?.part;
|
|
13
|
+
const opens = part !== undefined && parts(plan).length > 1 && plan[index - 1]?.part !== part;
|
|
14
|
+
return typed({ index, total: plan.length, ...(opens ? { opens: part } : {}) });
|
|
15
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { quote } from "../plan/describe.js";
|
|
2
|
+
import { typed } from "../../typed.js";
|
|
3
|
+
/** A step that talks with a person, given a pty: macOS's script, util-linux's elsewhere. */
|
|
4
|
+
export const inPty = (argv, size) => {
|
|
5
|
+
const { columns, rows } = size ?? { columns: 120, rows: 32 };
|
|
6
|
+
const sized = ["sh", "-c", `stty rows ${String(rows)} cols ${String(columns)} 2>/dev/null; exec "$@"`, "sh", ...argv];
|
|
7
|
+
return typed(process.platform === "darwin" ? ["bash", "-c", '"$@" < <(cat); code=$?; kill "$!" 2>/dev/null || :; exit "$code"', "bash", "script", "-q", "/dev/null", ...sized] : ["script", "-q", "-e", "-c", sized.map(quote).join(" "), "/dev/null"]);
|
|
8
|
+
};
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
/**
|
|
3
|
+
* Every kayra operation, once: what each client (the command line, the API,
|
|
4
|
+
* the web interface) offers, and what it may ask for. A client names an
|
|
5
|
+
* operation and gives its input as plain JSON; the core checks it here, binds
|
|
6
|
+
* it to the fleet and runs it. A new operation is added here, and each client's
|
|
7
|
+
* coverage table refuses to compile until it offers it too.
|
|
8
|
+
*/
|
|
9
|
+
/** What an operation acts on: the fleet as a whole, one server, one app on a server, or an app's own repository. */
|
|
10
|
+
export const scopes = ["fleet", "server", "app", "repo"];
|
|
11
|
+
/** What it does to the world: a client asks before a change to a real server, and twice before destroying. */
|
|
12
|
+
export const effects = ["reads", "changes", "destroys"];
|
|
13
|
+
/**
|
|
14
|
+
* How it runs: a plan of steps (shown before, followed while), a query
|
|
15
|
+
* answering at once, a stream of answers as they land (status), or an interactive session.
|
|
16
|
+
*/
|
|
17
|
+
export const kinds = ["plan", "query", "stream", "session"];
|
|
18
|
+
const server = z.string().min(1).describe("A server of the fleet (servers/<name>/)");
|
|
19
|
+
const app = z.string().min(1).describe("An app name, including a removed app whose records or data remain");
|
|
20
|
+
const serverInput = z.strictObject({ server });
|
|
21
|
+
const appInput = z.strictObject({ server, app });
|
|
22
|
+
export const operations = {
|
|
23
|
+
up: {
|
|
24
|
+
summary: "Provision, set up everything, point /etc/hosts at it.",
|
|
25
|
+
scope: "server",
|
|
26
|
+
effect: "changes",
|
|
27
|
+
kind: "plan",
|
|
28
|
+
input: serverInput,
|
|
29
|
+
},
|
|
30
|
+
provision: {
|
|
31
|
+
summary: "Create or update the machine (target home: build the image to import).",
|
|
32
|
+
scope: "server",
|
|
33
|
+
effect: "changes",
|
|
34
|
+
kind: "plan",
|
|
35
|
+
input: serverInput,
|
|
36
|
+
},
|
|
37
|
+
deploy: { summary: "Host setup and every app, no provisioning.", scope: "server", effect: "changes", kind: "plan", input: serverInput },
|
|
38
|
+
setup: { summary: "The host layer only: the playbook for the server's kind.", scope: "server", effect: "changes", kind: "plan", input: serverInput },
|
|
39
|
+
plan: {
|
|
40
|
+
summary: "What provision and setup would change, changing nothing (OpenTofu plan, Ansible check mode).",
|
|
41
|
+
scope: "server",
|
|
42
|
+
effect: "reads",
|
|
43
|
+
kind: "plan",
|
|
44
|
+
input: serverInput,
|
|
45
|
+
},
|
|
46
|
+
verify: {
|
|
47
|
+
summary: "Whether a platform server works as its users see it: logins, certificates, webhooks, apps, runs, alerts.",
|
|
48
|
+
scope: "server",
|
|
49
|
+
effect: "reads",
|
|
50
|
+
kind: "plan",
|
|
51
|
+
input: serverInput,
|
|
52
|
+
},
|
|
53
|
+
apps: {
|
|
54
|
+
summary: "Make the server's apps match server.yml: register each, remove the rest (data kept).",
|
|
55
|
+
scope: "server",
|
|
56
|
+
effect: "changes",
|
|
57
|
+
kind: "plan",
|
|
58
|
+
input: serverInput,
|
|
59
|
+
},
|
|
60
|
+
hosts: { summary: "Point the domain at a multipass VM in /etc/hosts (sudo).", scope: "server", effect: "changes", kind: "plan", input: serverInput },
|
|
61
|
+
ssh: { summary: "Open an interactive SSH session.", scope: "server", effect: "changes", kind: "session", bare: true, input: serverInput },
|
|
62
|
+
"ssh.exec": {
|
|
63
|
+
summary: "Run a command over SSH.", scope: "server", effect: "changes", kind: "plan", bare: true,
|
|
64
|
+
input: z.strictObject({ server, command: z.array(z.string()).min(1).describe("The remote command and arguments") }),
|
|
65
|
+
},
|
|
66
|
+
down: { summary: "Destroy the machine.", scope: "server", effect: "destroys", kind: "plan", input: serverInput },
|
|
67
|
+
adopt: {
|
|
68
|
+
summary: "Once, for a server we did not create: add the deploy user as root.",
|
|
69
|
+
scope: "server",
|
|
70
|
+
effect: "changes",
|
|
71
|
+
kind: "plan",
|
|
72
|
+
input: serverInput,
|
|
73
|
+
},
|
|
74
|
+
"backup.test": {
|
|
75
|
+
summary: "Restore the latest backup to a scratch dir, check it, delete it.",
|
|
76
|
+
scope: "server",
|
|
77
|
+
effect: "changes",
|
|
78
|
+
kind: "plan",
|
|
79
|
+
input: serverInput,
|
|
80
|
+
},
|
|
81
|
+
"app.check": {
|
|
82
|
+
summary: "What the platform checks at deploy (app.yml, images, compose policy), in an app's repository. No fleet needed.",
|
|
83
|
+
scope: "repo",
|
|
84
|
+
effect: "reads",
|
|
85
|
+
kind: "plan",
|
|
86
|
+
input: z.strictObject({ dir: z.string().min(1).default(".").describe("The app's repository") }),
|
|
87
|
+
},
|
|
88
|
+
"app.purge": { summary: "Delete a removed app's volumes: its data, irreversibly.", scope: "app", effect: "destroys", kind: "plan", input: appInput },
|
|
89
|
+
"app.runs": {
|
|
90
|
+
summary: "What runs now, and the app's latest runs: state, commit, why, when, how long.",
|
|
91
|
+
scope: "app",
|
|
92
|
+
effect: "reads",
|
|
93
|
+
kind: "query",
|
|
94
|
+
bare: true,
|
|
95
|
+
input: appInput,
|
|
96
|
+
},
|
|
97
|
+
"app.log": {
|
|
98
|
+
summary: "A run's log, the newest unless named; its errors and warnings marked.",
|
|
99
|
+
scope: "app",
|
|
100
|
+
effect: "reads",
|
|
101
|
+
kind: "query",
|
|
102
|
+
bare: true,
|
|
103
|
+
input: z.strictObject({ server, app, run: z.string().min(1).optional().describe("A run's id; the newest by default") }),
|
|
104
|
+
},
|
|
105
|
+
"app.deploy": {
|
|
106
|
+
summary: "Build and deploy a branch, tag or commit (default: the app's ref).",
|
|
107
|
+
scope: "app",
|
|
108
|
+
effect: "changes",
|
|
109
|
+
kind: "plan",
|
|
110
|
+
bare: true,
|
|
111
|
+
input: z.strictObject({ server, app, ref: z.string().min(1).optional().describe("A branch, tag or commit; the app's ref by default") }),
|
|
112
|
+
},
|
|
113
|
+
"app.releases": {
|
|
114
|
+
summary: "The app's releases: what runs now, and the earlier ones to roll back to.",
|
|
115
|
+
scope: "app",
|
|
116
|
+
effect: "reads",
|
|
117
|
+
kind: "query",
|
|
118
|
+
bare: true,
|
|
119
|
+
input: appInput,
|
|
120
|
+
},
|
|
121
|
+
"app.rollback": {
|
|
122
|
+
summary: "Deploy an earlier release again.",
|
|
123
|
+
scope: "app",
|
|
124
|
+
effect: "changes",
|
|
125
|
+
kind: "plan",
|
|
126
|
+
bare: true,
|
|
127
|
+
input: z.strictObject({ server, app, sha: z.string().regex(/^[0-9a-f]{7,40}$/).describe("An earlier release's commit") }),
|
|
128
|
+
},
|
|
129
|
+
job: {
|
|
130
|
+
summary: "Run a platform job now: the registry GC or Renovate.",
|
|
131
|
+
scope: "server",
|
|
132
|
+
effect: "changes",
|
|
133
|
+
kind: "plan",
|
|
134
|
+
bare: true,
|
|
135
|
+
input: z.strictObject({
|
|
136
|
+
server,
|
|
137
|
+
job: z.enum(["gc", "renovate"]),
|
|
138
|
+
noPrs: z.boolean().default(false).describe("Renovate: log what would change, open no PRs"),
|
|
139
|
+
}),
|
|
140
|
+
},
|
|
141
|
+
status: {
|
|
142
|
+
summary: "Every server: where it is, whether SSH and its login answer.",
|
|
143
|
+
scope: "fleet",
|
|
144
|
+
effect: "reads",
|
|
145
|
+
kind: "stream",
|
|
146
|
+
input: z.strictObject({ offline: z.boolean().default(false).describe("Only what the fleet and OpenTofu's state say: reach no server") }),
|
|
147
|
+
},
|
|
148
|
+
validate: {
|
|
149
|
+
summary: "Check the fleet beyond its schemas: secrets, apps against their contract, stacks, routes.",
|
|
150
|
+
scope: "fleet",
|
|
151
|
+
effect: "reads",
|
|
152
|
+
kind: "query",
|
|
153
|
+
input: z.strictObject({ server: server.optional() }),
|
|
154
|
+
},
|
|
155
|
+
doctor: { summary: "Check that this Mac can run every command on every server.", scope: "fleet", effect: "reads", kind: "plan", input: z.strictObject({}) },
|
|
156
|
+
certs: {
|
|
157
|
+
summary: "mkcert certs for a domain and its subdomains (local dev, multipass).",
|
|
158
|
+
scope: "fleet",
|
|
159
|
+
effect: "changes",
|
|
160
|
+
kind: "plan",
|
|
161
|
+
input: z.strictObject({ domain: z.string().min(1), subdomains: z.array(z.string()).default([]) }),
|
|
162
|
+
},
|
|
163
|
+
version: { summary: "Which kayra this is.", scope: "fleet", effect: "reads", kind: "query", input: z.strictObject({}) },
|
|
164
|
+
};
|
|
165
|
+
export const operationNames = Object.keys(operations).filter((name) => Object.hasOwn(operations, name));
|
|
166
|
+
export const isOperation = (name) => Object.hasOwn(operations, name);
|
|
167
|
+
/** An operation as every client reads it, whatever its own entry spells out. */
|
|
168
|
+
const described = operations;
|
|
169
|
+
export const operation = (name) => Object.freeze(described[name]);
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
import { resolve } from "node:path";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
import { absolutePath, appName, domain, subdomain, within } from "../fleet/brand.js";
|
|
4
|
+
import { appCheck } from "../recipes/app-check.js";
|
|
5
|
+
import { doctor } from "../recipes/doctor.js";
|
|
6
|
+
import { appPurge, apps, deployer } from "../recipes/apps.js";
|
|
7
|
+
import { adopt, deploy, down, hosts, preview, provision, setup, up, verify } from "../recipes/host.js";
|
|
8
|
+
import { backupTest } from "../recipes/backup.js";
|
|
9
|
+
import { certsFor } from "../recipes/certs.js";
|
|
10
|
+
import { ssh } from "../recipes/ssh.js";
|
|
11
|
+
import { look } from "../status/look.js";
|
|
12
|
+
import { findings } from "../validation/findings.js";
|
|
13
|
+
import { gather } from "../validation/facts.js";
|
|
14
|
+
import { all, err, flatMap, map, ok } from "../../result.js";
|
|
15
|
+
import { operations } from "./catalog.js";
|
|
16
|
+
import { textAt } from "../adapters/fs.js";
|
|
17
|
+
import { typed } from "../../typed.js";
|
|
18
|
+
import { resolve as substitute, spawned } from "../interpreter/process.js";
|
|
19
|
+
/** The context for a fleet, with the files read from disk: what every client runs the core with. */
|
|
20
|
+
export const contextFor = (parts) => {
|
|
21
|
+
const { kayra, ...rest } = parts;
|
|
22
|
+
return typed({ ...rest, engine: { kayra, fleet: parts.fleet.root }, read: textAt });
|
|
23
|
+
};
|
|
24
|
+
/** Every operation with its input: what a client sends, parsed in one go. */
|
|
25
|
+
const invocations = z.discriminatedUnion("name", [
|
|
26
|
+
z.strictObject({ name: z.literal("up"), input: operations.up.input }),
|
|
27
|
+
z.strictObject({ name: z.literal("provision"), input: operations.provision.input }),
|
|
28
|
+
z.strictObject({ name: z.literal("deploy"), input: operations.deploy.input }),
|
|
29
|
+
z.strictObject({ name: z.literal("setup"), input: operations.setup.input }),
|
|
30
|
+
z.strictObject({ name: z.literal("plan"), input: operations.plan.input }),
|
|
31
|
+
z.strictObject({ name: z.literal("verify"), input: operations.verify.input }),
|
|
32
|
+
z.strictObject({ name: z.literal("apps"), input: operations.apps.input }),
|
|
33
|
+
z.strictObject({ name: z.literal("hosts"), input: operations.hosts.input }),
|
|
34
|
+
z.strictObject({ name: z.literal("ssh"), input: operations.ssh.input }),
|
|
35
|
+
z.strictObject({ name: z.literal("ssh.exec"), input: operations["ssh.exec"].input }),
|
|
36
|
+
z.strictObject({ name: z.literal("down"), input: operations.down.input }),
|
|
37
|
+
z.strictObject({ name: z.literal("adopt"), input: operations.adopt.input }),
|
|
38
|
+
z.strictObject({ name: z.literal("backup.test"), input: operations["backup.test"].input }),
|
|
39
|
+
z.strictObject({ name: z.literal("app.check"), input: operations["app.check"].input }),
|
|
40
|
+
z.strictObject({ name: z.literal("app.purge"), input: operations["app.purge"].input }),
|
|
41
|
+
z.strictObject({ name: z.literal("app.runs"), input: operations["app.runs"].input }),
|
|
42
|
+
z.strictObject({ name: z.literal("app.log"), input: operations["app.log"].input }),
|
|
43
|
+
z.strictObject({ name: z.literal("app.deploy"), input: operations["app.deploy"].input }),
|
|
44
|
+
z.strictObject({ name: z.literal("app.releases"), input: operations["app.releases"].input }),
|
|
45
|
+
z.strictObject({ name: z.literal("app.rollback"), input: operations["app.rollback"].input }),
|
|
46
|
+
z.strictObject({ name: z.literal("job"), input: operations.job.input }),
|
|
47
|
+
z.strictObject({ name: z.literal("status"), input: operations.status.input }),
|
|
48
|
+
z.strictObject({ name: z.literal("validate"), input: operations.validate.input }),
|
|
49
|
+
z.strictObject({ name: z.literal("doctor"), input: operations.doctor.input }),
|
|
50
|
+
z.strictObject({ name: z.literal("certs"), input: operations.certs.input }),
|
|
51
|
+
z.strictObject({ name: z.literal("version"), input: operations.version.input }),
|
|
52
|
+
]);
|
|
53
|
+
/** An operation and input from any client, checked against its schema: the one gate into the core. */
|
|
54
|
+
export const invocation = (name, input) => {
|
|
55
|
+
const parsed = invocations.safeParse({ name, input: input ?? {} });
|
|
56
|
+
if (parsed.success)
|
|
57
|
+
return ok(parsed.data);
|
|
58
|
+
const issue = parsed.error.issues[0];
|
|
59
|
+
const where = issue?.path.slice(1).join(".") ?? "";
|
|
60
|
+
return err(Object.hasOwn(operations, name) ? `${name}: ${where === "" ? "input" : where}: ${issue?.message ?? "invalid"}` : `no operation '${name}'`);
|
|
61
|
+
};
|
|
62
|
+
const onServer = (ctx, name) => {
|
|
63
|
+
const found = ctx.fleet.servers.find((each) => each.name === name);
|
|
64
|
+
return found === undefined ? err(`no server '${name}' in this fleet`) : ok(found);
|
|
65
|
+
};
|
|
66
|
+
/**
|
|
67
|
+
* A server and an app's name. The app need not be in server.yml: a removed
|
|
68
|
+
* app's runs, logs and volumes stay the deployer's to answer for and purge.
|
|
69
|
+
*/
|
|
70
|
+
const onApp = (ctx, input) => flatMap(onServer(ctx, input.server), (target) => map(appName(input.app), (app) => [target, app]));
|
|
71
|
+
const withServer = (make) => (ctx, input) => flatMap(onServer(ctx, input.server), (target) => make(ctx.engine, target));
|
|
72
|
+
const onDeployer = (command) => (ctx, input) => flatMap(onApp(ctx, input), ([target, app]) => deployer(target, command(app, input)));
|
|
73
|
+
const optional = (value) => (typeof value === "string" ? value : undefined);
|
|
74
|
+
/** Each plan operation, as the plan that does it: the compiler refuses one that has none. */
|
|
75
|
+
const plans = {
|
|
76
|
+
up: withServer(up),
|
|
77
|
+
provision: withServer(provision),
|
|
78
|
+
deploy: withServer(deploy),
|
|
79
|
+
setup: withServer(setup),
|
|
80
|
+
plan: withServer(preview),
|
|
81
|
+
verify: withServer(verify),
|
|
82
|
+
apps: withServer(apps),
|
|
83
|
+
hosts: withServer(hosts),
|
|
84
|
+
down: withServer(down),
|
|
85
|
+
adopt: withServer(adopt),
|
|
86
|
+
"backup.test": withServer(backupTest),
|
|
87
|
+
ssh: (ctx, input) => flatMap(onServer(ctx, input.server), (target) => ssh(target, [])),
|
|
88
|
+
"ssh.exec": (ctx, input) => flatMap(onServer(ctx, input.server), (target) => ssh(target, input.command)),
|
|
89
|
+
"app.check": (ctx, input) => flatMap(absolutePath(resolve(ctx.here, input.dir)), (dir) => appCheck(ctx.engine.kayra, dir, ctx.read(within(dir, "app.yml")))),
|
|
90
|
+
"app.purge": (ctx, input) => flatMap(onApp(ctx, input), ([target, app]) => appPurge(ctx.engine, target, app)),
|
|
91
|
+
"app.runs": onDeployer((app) => ({ kind: "runs", app, more: undefined })),
|
|
92
|
+
"app.log": onDeployer((app, input) => ({ kind: "logs", app, more: optional(input["run"]) })),
|
|
93
|
+
"app.deploy": onDeployer((app, input) => ({ kind: "deploy", app, more: optional(input["ref"]) })),
|
|
94
|
+
"app.releases": onDeployer((app) => ({ kind: "rollback", app, more: undefined })),
|
|
95
|
+
"app.rollback": onDeployer((app, input) => ({ kind: "rollback", app, more: optional(input["sha"]) })),
|
|
96
|
+
job: (ctx, input) => flatMap(onServer(ctx, input.server), (target) => deployer(target, { kind: "job", job: input.job, noPrs: input.noPrs })),
|
|
97
|
+
doctor: (ctx) => ok(doctor(ctx.fleet, ctx.engine.kayra)),
|
|
98
|
+
certs: (ctx, input) => flatMap(domain(input.domain), (named) => flatMap(all(input.subdomains.map(subdomain)), (subdomains) => certsFor(ctx.engine, named, subdomains))),
|
|
99
|
+
};
|
|
100
|
+
export const planOf = (ctx, call) => plans[call.name](ctx, call.input);
|
|
101
|
+
export const hasPlan = (call) => Object.hasOwn(plans, call.name);
|
|
102
|
+
/** What a deployer's ctl answers, read whole: its stdout, or why it failed. */
|
|
103
|
+
const deployerAnswer = async (ctx, name, input) => {
|
|
104
|
+
const plan = planOf(ctx, { name, input });
|
|
105
|
+
if (!plan.ok)
|
|
106
|
+
return plan;
|
|
107
|
+
const [step] = plan.value;
|
|
108
|
+
if (step?.kind !== "run")
|
|
109
|
+
return err("the deployer's plan runs nothing");
|
|
110
|
+
// Like a step without a terminal: no stdin, and stopping reaches the whole process group.
|
|
111
|
+
const plumbing = { output: () => undefined, ...(ctx.signal === undefined ? {} : { signal: ctx.signal }) };
|
|
112
|
+
const argv = await substitute(step.argv, plumbing);
|
|
113
|
+
if (!argv.ok)
|
|
114
|
+
return argv;
|
|
115
|
+
const exit = await spawned(argv.value, { stdout: "capture", stderr: "capture" }, step.env, plumbing);
|
|
116
|
+
return exit.code === 0 ? ok(exit.stdout) : err(exit.stderr.trim() || "the deployer query failed");
|
|
117
|
+
};
|
|
118
|
+
const queries = {
|
|
119
|
+
"app.runs": (ctx, input) => deployerAnswer(ctx, "app.runs", input),
|
|
120
|
+
"app.releases": (ctx, input) => deployerAnswer(ctx, "app.releases", input),
|
|
121
|
+
"app.log": (ctx, input) => deployerAnswer(ctx, "app.log", input),
|
|
122
|
+
validate: async (ctx, input) => {
|
|
123
|
+
const chosen = input.server === undefined ? ok(ctx.fleet.servers) : map(onServer(ctx, input.server), (one) => Object.freeze([one]));
|
|
124
|
+
if (!chosen.ok)
|
|
125
|
+
return chosen;
|
|
126
|
+
return ok(await Promise.all(chosen.value.map(async (each) => ({ server: each, findings: findings(await gather(ctx.fleet.root, each)) }))));
|
|
127
|
+
},
|
|
128
|
+
version: (ctx) => Promise.resolve(ok(ctx.version)),
|
|
129
|
+
};
|
|
130
|
+
export const query = (ctx, name, input) => queries[name](ctx, input);
|
|
131
|
+
const streams = {
|
|
132
|
+
status: (ctx, input) => look(ctx.fleet, ctx.tofu, input.offline ? undefined : ctx.network),
|
|
133
|
+
};
|
|
134
|
+
/** A stream's first state and the updates still to land. */
|
|
135
|
+
export const stream = (ctx, name, input) => streams[name](ctx, input);
|
|
136
|
+
/** The server an invocation acts on, if one: what its heading names, what a real server's confirmation asks for. */
|
|
137
|
+
export const serverOf = (ctx, invocation) => {
|
|
138
|
+
const named = "server" in invocation.input ? invocation.input.server : undefined;
|
|
139
|
+
return typeof named === "string" ? ctx.fleet.servers.find((each) => each.name === named) : undefined;
|
|
140
|
+
};
|
|
141
|
+
export const isQuery = (call) => operations[call.name].kind === "query";
|
|
142
|
+
export const isStream = (call) => operations[call.name].kind === "stream";
|
|
@@ -1,12 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
argv,
|
|
5
|
-
env,
|
|
6
|
-
stdout: "show",
|
|
7
|
-
});
|
|
8
|
-
const quote = (word) => (/^[\w@%+=:,./~-]+$/.test(word) ? word : `'${word.replaceAll("'", `'\\''`)}'`);
|
|
9
|
-
export const shell = (argv) => argv.map(quote).join(" ");
|
|
1
|
+
/** A word as a shell reads it back: bare where it is safe, else single-quoted. */
|
|
2
|
+
export const quote = (word) => (/^[\w@%+=:,./~-]+$/.test(word) ? word : `'${word.replaceAll("'", `'\\''`)}'`);
|
|
3
|
+
const shell = (argv) => argv.map(quote).join(" ");
|
|
10
4
|
const assignments = (env = {}) => Object.entries(env)
|
|
11
5
|
.map(([key, value]) => `${key}=${quote(value)} `)
|
|
12
6
|
.join("");
|
|
@@ -17,13 +11,12 @@ const arg = (value) => {
|
|
|
17
11
|
return value.words === "one" ? `"${command}"` : command;
|
|
18
12
|
};
|
|
19
13
|
const describeProbe = (probe) => probe.kind === "on-path" ? `command -v ${quote(probe.program)}` : assignments(probe.env) + shell(probe.argv);
|
|
20
|
-
/** Every step of a plan as part of one kayra command. */
|
|
21
|
-
export const partOf = (part, plan) => plan.map((step) => ({ ...step, part }));
|
|
22
14
|
/** guard, check, run, confirm or note: what kind of step it is, as --dry-run says. */
|
|
23
15
|
export const kindOf = (step) => (step.kind === "check" ? (step.onFailure === "stop" ? "guard" : "check") : step.kind);
|
|
24
16
|
/** What it is called while it runs; a confirmation and a note say what they say. */
|
|
25
17
|
export const titleOf = (step) => {
|
|
26
18
|
switch (step.kind) {
|
|
19
|
+
case "session":
|
|
27
20
|
case "run":
|
|
28
21
|
return step.title;
|
|
29
22
|
case "check":
|
|
@@ -34,11 +27,16 @@ export const titleOf = (step) => {
|
|
|
34
27
|
return step.text;
|
|
35
28
|
}
|
|
36
29
|
};
|
|
30
|
+
/** What --dry-run says a step will ask for: kayra asks it when the step runs. */
|
|
31
|
+
const asks = (needs = []) => needs.length === 0
|
|
32
|
+
? ""
|
|
33
|
+
: ` # asks for ${needs.map((need) => (need.kind === "vault" ? `${need.server}'s vault password` : "sudo's password, unless cached")).join(" and ")}`;
|
|
37
34
|
/** The shell command a step runs, or undefined if it runs none. */
|
|
38
35
|
export const commandOf = (step) => {
|
|
39
36
|
switch (step.kind) {
|
|
37
|
+
case "session":
|
|
40
38
|
case "run":
|
|
41
|
-
return `${assignments(step.env)}${step.argv.map(arg).join(" ")}${step.stdout === "discard" ? " >/dev/null" : ""}`;
|
|
39
|
+
return `${assignments(step.env)}${step.argv.map(arg).join(" ")}${step.stdout === "discard" ? " >/dev/null" : ""}${asks(step.needs)}`;
|
|
42
40
|
case "check":
|
|
43
41
|
return describeProbe(step.probe);
|
|
44
42
|
case "confirm":
|
|
@@ -48,8 +46,9 @@ export const commandOf = (step) => {
|
|
|
48
46
|
};
|
|
49
47
|
const describe = (step) => {
|
|
50
48
|
switch (step.kind) {
|
|
49
|
+
case "session":
|
|
51
50
|
case "run":
|
|
52
|
-
return
|
|
51
|
+
return `${step.kind.padEnd(8)} ${commandOf(step) ?? ""}`;
|
|
53
52
|
case "check":
|
|
54
53
|
return `${kindOf(step).padEnd(8)} ${step.label}: ${commandOf(step) ?? ""}`;
|
|
55
54
|
case "confirm":
|
|
@@ -59,6 +58,4 @@ const describe = (step) => {
|
|
|
59
58
|
}
|
|
60
59
|
};
|
|
61
60
|
/** The plan as plain lines: --dry-run's output where it is read by a program. */
|
|
62
|
-
export const render = (plan) => plan.map(describe);
|
|
63
|
-
/** A plan with a step that asks on the terminal (the vault password, typed): it cannot run without one. */
|
|
64
|
-
export const needsTerminal = (plan) => plan.some((step) => step.kind === "run" && step.env["ANSIBLE_ASK_VAULT_PASS"] === "True");
|
|
61
|
+
export const render = (plan) => Object.freeze(plan.map(describe));
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { typed } from "../../typed.js";
|
|
2
|
+
/** The kayra commands a longer one is made of, each of which runs its part alone. */
|
|
3
|
+
export const parts = ["provision", "setup", "apps", "verify", "hosts"];
|
|
4
|
+
export const run = (title, argv, env = {}) => typed({
|
|
5
|
+
kind: "run",
|
|
6
|
+
title,
|
|
7
|
+
argv,
|
|
8
|
+
env,
|
|
9
|
+
stdout: "show",
|
|
10
|
+
});
|
|
11
|
+
/** Every step of a plan as part of one kayra command. */
|
|
12
|
+
export const partOf = (part, plan) => Object.freeze(plan.map((step) => ({ ...step, part })));
|
|
13
|
+
/** A plan with a step that talks with a person: a client without a terminal gives it a pty and the person's keys. */
|
|
14
|
+
export const needsTerminal = (plan) => plan.some((step) => step.kind === "session");
|
|
@@ -1,17 +1,12 @@
|
|
|
1
|
-
import { appName, within } from "../brand.js";
|
|
2
|
-
import { yamlOf } from "../fleet.js";
|
|
3
|
-
import { run } from "../plan.js";
|
|
4
|
-
import { err, flatMap, map } from "
|
|
5
|
-
import { appManifestSchema } from "../settings.js";
|
|
6
|
-
import { checkShape } from "../
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
label: `${program} is installed`,
|
|
11
|
-
probe: { kind: "on-path", program },
|
|
12
|
-
hint,
|
|
13
|
-
onFailure: "stop",
|
|
14
|
-
});
|
|
1
|
+
import { appName, within } from "../fleet/brand.js";
|
|
2
|
+
import { yamlOf } from "../fleet/parse.js";
|
|
3
|
+
import { run } from "../plan/model.js";
|
|
4
|
+
import { err, flatMap, map, mapError } from "../../result.js";
|
|
5
|
+
import { appManifestSchema } from "../fleet/settings.js";
|
|
6
|
+
import { checkShape } from "../fleet/shape.js";
|
|
7
|
+
import { onPath } from "./steps.js";
|
|
8
|
+
import { typed } from "../../typed.js";
|
|
9
|
+
const tool = (program, hint) => onPath(`${program} is installed`, program, hint, "stop");
|
|
15
10
|
/**
|
|
16
11
|
* In an app's own repository, before a push: what the platform checks when it
|
|
17
12
|
* deploys the app — app.yml against its schema here, then app-check.sh (the
|
|
@@ -25,11 +20,11 @@ export const appCheck = (kayra, root, manifest) => {
|
|
|
25
20
|
const parsed = appManifestSchema.safeParse(values);
|
|
26
21
|
return parsed.success ? appName(parsed.data.name) : err("app.yml: invalid");
|
|
27
22
|
});
|
|
28
|
-
return map(shaped, () => [
|
|
23
|
+
return map(shaped, () => typed([
|
|
29
24
|
tool("git", "brew install git"),
|
|
30
25
|
tool("jq", "brew install jq"),
|
|
31
26
|
tool("yq", "brew install yq"),
|
|
32
27
|
tool("docker", "the docker CLI with Compose; no daemon is needed"),
|
|
33
28
|
run("Image plan and compose policy", ["bash", within(kayra, "scripts", "local", "app-check.sh"), root]),
|
|
34
|
-
]);
|
|
29
|
+
]));
|
|
35
30
|
};
|