@yunuseon/kayra 0.19.0 → 0.20.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/agent/skills/kayra-release/SKILL.md +1 -4
- package/agent/skills/kayra-rollout/SKILL.md +1 -4
- package/ansible/roles/app/tasks/main.yml +24 -0
- package/ansible/roles/platform/defaults/main.yml +3 -0
- package/ansible/roles/platform/tasks/main.yml +6 -86
- package/ansible/roles/platform/templates/platform.env.j2 +2 -0
- package/bin/kayra-app-hook.js +6 -0
- package/bin/kayra-app-init.js +6 -0
- package/bin/kayra-app-launch.js +6 -0
- package/bin/kayra-app-values.js +6 -0
- package/cli/dist/app-hook.js +75 -0
- package/cli/dist/app-init.js +65 -0
- package/cli/dist/app-launch.js +89 -0
- package/cli/dist/app-values.js +37 -0
- package/cli/dist/browser/assets/ibm-plex-sans-cyrillic-400-normal-BTotfTJu.woff +0 -0
- package/cli/dist/browser/assets/ibm-plex-sans-cyrillic-400-normal-DZqxrq2p.woff2 +0 -0
- package/cli/dist/browser/assets/ibm-plex-sans-cyrillic-600-normal-71GNu3SW.woff2 +0 -0
- package/cli/dist/browser/assets/ibm-plex-sans-cyrillic-600-normal-BGq0mW3O.woff +0 -0
- package/cli/dist/browser/assets/ibm-plex-sans-cyrillic-ext-400-normal-Dsrv2Tcn.woff +0 -0
- package/cli/dist/browser/assets/ibm-plex-sans-cyrillic-ext-400-normal-g30qAdWV.woff2 +0 -0
- package/cli/dist/browser/assets/ibm-plex-sans-cyrillic-ext-600-normal-Bz0x94Yp.woff +0 -0
- package/cli/dist/browser/assets/ibm-plex-sans-cyrillic-ext-600-normal-DUMzJB7m.woff2 +0 -0
- package/cli/dist/browser/assets/ibm-plex-sans-greek-400-normal-D9ESIMu3.woff +0 -0
- package/cli/dist/browser/assets/ibm-plex-sans-greek-400-normal-_efipK4i.woff2 +0 -0
- package/cli/dist/browser/assets/ibm-plex-sans-greek-600-normal-D-CqTdkO.woff +0 -0
- package/cli/dist/browser/assets/ibm-plex-sans-greek-600-normal-DzTrcv_p.woff2 +0 -0
- package/cli/dist/browser/assets/ibm-plex-sans-latin-400-normal-CDDApCn2.woff2 +0 -0
- package/cli/dist/browser/assets/ibm-plex-sans-latin-400-normal-CYLoc0-x.woff +0 -0
- package/cli/dist/browser/assets/ibm-plex-sans-latin-600-normal-Cu4Hd6ag.woff +0 -0
- package/cli/dist/browser/assets/ibm-plex-sans-latin-600-normal-CuJfVYMP.woff2 +0 -0
- package/cli/dist/browser/assets/ibm-plex-sans-latin-ext-400-normal-C5H60-Va.woff2 +0 -0
- package/cli/dist/browser/assets/ibm-plex-sans-latin-ext-400-normal-RBey6euL.woff +0 -0
- package/cli/dist/browser/assets/ibm-plex-sans-latin-ext-600-normal-DIrixKbi.woff +0 -0
- package/cli/dist/browser/assets/ibm-plex-sans-latin-ext-600-normal-DOrvGEcy.woff2 +0 -0
- package/cli/dist/browser/assets/ibm-plex-sans-vietnamese-400-normal-DG4YqDda.woff2 +0 -0
- package/cli/dist/browser/assets/ibm-plex-sans-vietnamese-400-normal-fK1oJ5dG.woff +0 -0
- package/cli/dist/browser/assets/ibm-plex-sans-vietnamese-600-normal-DgdngZtN.woff +0 -0
- package/cli/dist/browser/assets/ibm-plex-sans-vietnamese-600-normal-DpPYBSTl.woff2 +0 -0
- package/cli/dist/browser/assets/index-DzIVPXyL.css +1 -0
- package/cli/dist/browser/assets/index-SP8bCDrl.js +7 -0
- package/cli/dist/browser/assets/jetbrains-mono-cyrillic-400-normal-BEIGL1Tu.woff2 +0 -0
- package/cli/dist/browser/assets/jetbrains-mono-cyrillic-400-normal-ugxPyKxw.woff +0 -0
- package/cli/dist/browser/assets/jetbrains-mono-cyrillic-500-normal-DJqRU3vO.woff +0 -0
- package/cli/dist/browser/assets/jetbrains-mono-cyrillic-500-normal-DmUKJPL_.woff2 +0 -0
- package/cli/dist/browser/assets/jetbrains-mono-cyrillic-600-normal-8K4wrrwR.woff +0 -0
- package/cli/dist/browser/assets/jetbrains-mono-cyrillic-600-normal-EVf6-Yzo.woff2 +0 -0
- package/cli/dist/browser/assets/jetbrains-mono-cyrillic-700-normal-BWTpRfYl.woff2 +0 -0
- package/cli/dist/browser/assets/jetbrains-mono-cyrillic-700-normal-CEoEElIJ.woff +0 -0
- package/cli/dist/browser/assets/jetbrains-mono-greek-400-normal-B9oWc5Lo.woff +0 -0
- package/cli/dist/browser/assets/jetbrains-mono-greek-400-normal-C190GLew.woff2 +0 -0
- package/cli/dist/browser/assets/jetbrains-mono-greek-500-normal-D7SFKleX.woff +0 -0
- package/cli/dist/browser/assets/jetbrains-mono-greek-500-normal-JpySY46c.woff2 +0 -0
- package/cli/dist/browser/assets/jetbrains-mono-greek-600-normal-H7WoG9Et.woff2 +0 -0
- package/cli/dist/browser/assets/jetbrains-mono-greek-600-normal-mc2nkWzM.woff +0 -0
- package/cli/dist/browser/assets/jetbrains-mono-greek-700-normal-C6CZE3T8.woff2 +0 -0
- package/cli/dist/browser/assets/jetbrains-mono-greek-700-normal-DEigVDxa.woff +0 -0
- package/cli/dist/browser/assets/jetbrains-mono-latin-400-normal-6-qcROiO.woff +0 -0
- package/cli/dist/browser/assets/jetbrains-mono-latin-400-normal-V6pRDFza.woff2 +0 -0
- package/cli/dist/browser/assets/jetbrains-mono-latin-500-normal-BWZEU5yA.woff2 +0 -0
- package/cli/dist/browser/assets/jetbrains-mono-latin-500-normal-CJOVTJB7.woff +0 -0
- package/cli/dist/browser/assets/jetbrains-mono-latin-600-normal-BfsvjouI.woff +0 -0
- package/cli/dist/browser/assets/jetbrains-mono-latin-600-normal-C8RAYTDA.woff2 +0 -0
- package/cli/dist/browser/assets/jetbrains-mono-latin-700-normal-BYuf6tUa.woff2 +0 -0
- package/cli/dist/browser/assets/jetbrains-mono-latin-700-normal-D3wTyLJW.woff +0 -0
- package/cli/dist/browser/assets/jetbrains-mono-latin-ext-400-normal-Bc8Ftmh3.woff2 +0 -0
- package/cli/dist/browser/assets/jetbrains-mono-latin-ext-400-normal-fXTG6kC5.woff +0 -0
- package/cli/dist/browser/assets/jetbrains-mono-latin-ext-500-normal-Cut-4mMH.woff2 +0 -0
- package/cli/dist/browser/assets/jetbrains-mono-latin-ext-500-normal-ckzbgY84.woff +0 -0
- package/cli/dist/browser/assets/jetbrains-mono-latin-ext-600-normal-BfB_LPfz.woff2 +0 -0
- package/cli/dist/browser/assets/jetbrains-mono-latin-ext-600-normal-DObL3zCW.woff +0 -0
- package/cli/dist/browser/assets/jetbrains-mono-latin-ext-700-normal-CZipNAKV.woff2 +0 -0
- package/cli/dist/browser/assets/jetbrains-mono-latin-ext-700-normal-CxPITLHs.woff +0 -0
- package/cli/dist/browser/assets/jetbrains-mono-vietnamese-400-normal-CqNFfHCs.woff +0 -0
- package/cli/dist/browser/assets/jetbrains-mono-vietnamese-500-normal-DNRqzVM1.woff +0 -0
- package/cli/dist/browser/assets/jetbrains-mono-vietnamese-600-normal-OWROknRo.woff +0 -0
- package/cli/dist/browser/assets/jetbrains-mono-vietnamese-700-normal-BDLVIk2r.woff +0 -0
- package/cli/dist/browser/index.html +10 -3
- package/cli/dist/clients/api/start.js +1 -1
- package/cli/dist/clients/cli/invocation.js +25 -0
- package/cli/dist/clients/cli/parser.js +24 -7
- package/cli/dist/clients/cli/text.js +3 -3
- package/cli/dist/clients/cli/values.js +0 -1
- package/cli/dist/clients/cli/views.js +9 -2
- package/cli/dist/clients/mcp/tools.js +8 -1
- package/cli/dist/clients/ui/assets.js +1 -0
- package/cli/dist/clients/wire/contract.js +2 -2
- package/cli/dist/clients/wire/queries.js +1 -0
- package/cli/dist/clients/wire/schemas.js +4 -1
- package/cli/dist/clients/wire/words.js +14 -0
- package/cli/dist/core/adapters/opentofu.js +1 -1
- package/cli/dist/core/app-hook/hooks.js +90 -0
- package/cli/dist/core/app-hook/token.js +49 -0
- package/cli/dist/core/app-init/plan.js +208 -0
- package/cli/dist/core/app-values/model.js +45 -0
- package/cli/dist/core/app-values/store.js +124 -0
- package/cli/dist/core/ctl/answers.js +14 -9
- package/cli/dist/core/fleet/brand.js +10 -12
- package/cli/dist/core/fleet/settings.js +14 -9
- package/cli/dist/core/operations/catalog.js +46 -1
- package/cli/dist/core/operations/dispatch.js +37 -6
- package/cli/dist/core/recipes/app-check.js +14 -1
- package/cli/dist/core/recipes/app-hook.js +26 -0
- package/cli/dist/core/recipes/app-values.js +21 -0
- package/cli/dist/core/recipes/doctor.js +2 -2
- package/cli/dist/core/recipes/launch.js +51 -0
- package/cli/dist/core/validation/facts.js +1 -3
- package/cli/dist/deployer/brand.js +8 -5
- package/cli/dist/deployer/build/builder.js +10 -4
- package/cli/dist/deployer/build/client.js +44 -0
- package/cli/dist/deployer/build/routes.js +27 -6
- package/cli/dist/deployer/ctl/answers.js +6 -2
- package/cli/dist/deployer/ctl/ctl.js +66 -9
- package/cli/dist/deployer/deployer.js +113 -196
- package/cli/dist/deployer/forges/forge.js +0 -12
- package/cli/dist/deployer/forges/notify.js +3 -3
- package/cli/dist/deployer/http/http.js +0 -1
- package/cli/dist/deployer/http/page.js +4 -2
- package/cli/dist/deployer/http/webhook.js +0 -1
- package/cli/dist/deployer/runs/effects.js +70 -0
- package/cli/dist/deployer/runs/queue.js +5 -4
- package/cli/dist/deployer/runs/records.js +22 -3
- package/cli/dist/deployer/runs/restore.js +6 -0
- package/cli/dist/deployer/runs/run.js +51 -5
- package/cli/dist/deployer/runs/store.js +19 -3
- package/cli/dist/deployer/settings.js +69 -0
- package/cli/dist/lib/forge-repo.js +15 -0
- package/cli/dist/lib/names.js +13 -0
- package/cli/dist/main.js +46 -25
- package/compose/docker-compose.ci.yml +2 -0
- package/package.json +2 -2
- package/schema/app.json +5 -0
- package/schema/defaults.json +8 -0
- package/schema/vars-platform.json +8 -0
- package/scripts/local/verify.sh +9 -2
- package/terraform/modules/platform-dns/main.tf +66 -0
- package/terraform/modules/platform-dns/outputs.tf +9 -0
- package/terraform/modules/platform-dns/tests/fleet/.cache/apps/blog/site/app.yml +3 -0
- package/terraform/modules/platform-dns/tests/fleet/.cache/apps/shop/app.yml +6 -0
- package/terraform/modules/platform-dns/tests/fleet/servers/nested/server.yml +6 -0
- package/terraform/modules/platform-dns/tests/fleet/servers/shop/server.yml +7 -0
- package/terraform/modules/platform-dns/tests/fleet/servers/uncloned/server.yml +6 -0
- package/terraform/modules/platform-dns/tests/platform-dns.tftest.hcl +64 -0
- package/terraform/modules/platform-dns/variables.tf +25 -0
- package/cli/dist/browser/assets/index-C4HCL022.js +0 -7
- package/cli/dist/browser/assets/index-Ct0Eudk4.css +0 -1
- package/scripts/agent/guard.sh +0 -125
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { appManifestSchema } from "../fleet/settings.js";
|
|
3
|
+
import { err, flatMap, ok } from "../../lib/result.js";
|
|
4
|
+
import { fields } from "../../lib/yaml.js";
|
|
5
|
+
import { within } from "../fleet/brand.js";
|
|
6
|
+
export const valueKeySchema = z.string().regex(/^[A-Za-z_][A-Za-z0-9_]*$/, "expected an environment variable name");
|
|
7
|
+
export const valueStateSchema = z.enum(["set", "missing", "locked"]);
|
|
8
|
+
export const valuesReportSchema = z.object({
|
|
9
|
+
server: z.string(),
|
|
10
|
+
app: z.string(),
|
|
11
|
+
manifest: z.string(),
|
|
12
|
+
config: z.array(z.object({ key: z.string(), state: valueStateSchema })),
|
|
13
|
+
secrets: z.array(z.object({ key: z.string(), state: valueStateSchema })),
|
|
14
|
+
hint: z.string().nullable(),
|
|
15
|
+
});
|
|
16
|
+
export const editSchema = z.discriminatedUnion("kind", [
|
|
17
|
+
z.strictObject({ kind: z.literal("config"), key: valueKeySchema, value: z.string().refine((value) => !value.includes("\0"), "NUL is not an environment value") }),
|
|
18
|
+
z.strictObject({ kind: z.literal("import"), key: valueKeySchema, file: z.string().min(1) }),
|
|
19
|
+
z.strictObject({ kind: z.literal("generate"), key: valueKeySchema }),
|
|
20
|
+
]);
|
|
21
|
+
export const requirements = (root, server, name, read, dir) => {
|
|
22
|
+
if (server.kind !== "platform")
|
|
23
|
+
return err("only platform servers have app values");
|
|
24
|
+
const app = server.apps.find((each) => each.name === name);
|
|
25
|
+
if (app === undefined)
|
|
26
|
+
return err(`app '${name}' is not registered in ${server.name}'s server.yml`);
|
|
27
|
+
const manifest = dir === undefined ? within(root, ".cache", "apps", app.name, app.path, "app.yml") : within(dir, "app.yml");
|
|
28
|
+
const source = read(manifest);
|
|
29
|
+
if (source === undefined)
|
|
30
|
+
return err(`no app.yml for ${name}; provide the local app directory with --dir`);
|
|
31
|
+
const parsed = flatMap(fields(source), (value) => {
|
|
32
|
+
const checked = appManifestSchema.safeParse(value);
|
|
33
|
+
return checked.success ? ok({ name: checked.data.name, config: Object.freeze(checked.data.config ?? []), secrets: Object.freeze(checked.data.secrets ?? []) }) : err("app.yml does not match the app contract");
|
|
34
|
+
});
|
|
35
|
+
if (!parsed.ok)
|
|
36
|
+
return err(`app.yml for ${name} is invalid`);
|
|
37
|
+
if (parsed.value.name !== name)
|
|
38
|
+
return err(`app.yml names another app, not ${name}`);
|
|
39
|
+
const { config, secrets } = parsed.value;
|
|
40
|
+
if ([...config, ...secrets].some((key) => !valueKeySchema.safeParse(key).success))
|
|
41
|
+
return err("app.yml contains an invalid configuration or secret name");
|
|
42
|
+
if (config.some((key) => secrets.includes(key)))
|
|
43
|
+
return err("app.yml declares a key as both configuration and secret");
|
|
44
|
+
return ok({ manifest, config: Object.freeze(config), secrets: Object.freeze(secrets) });
|
|
45
|
+
};
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import { randomBytes, randomUUID } from "node:crypto";
|
|
2
|
+
import { existsSync, lstatSync, mkdirSync, readFileSync, renameSync, rmSync, writeFileSync } from "node:fs";
|
|
3
|
+
import { dirname, join } from "node:path";
|
|
4
|
+
import { parseDocument } from "yaml";
|
|
5
|
+
import { appValuesSchema } from "../fleet/settings.js";
|
|
6
|
+
import { isVaulted } from "../fleet/parse.js";
|
|
7
|
+
import { within } from "../fleet/brand.js";
|
|
8
|
+
import { textAt } from "../adapters/fs.js";
|
|
9
|
+
import { spawned } from "../interpreter/process.js";
|
|
10
|
+
import { vault } from "../recipes/steps.js";
|
|
11
|
+
import { attempt, err, ok } from "../../lib/result.js";
|
|
12
|
+
import { fields } from "../../lib/yaml.js";
|
|
13
|
+
import { requirements } from "./model.js";
|
|
14
|
+
const parsedValues = (text) => {
|
|
15
|
+
const parsed = fields(text);
|
|
16
|
+
if (!parsed.ok)
|
|
17
|
+
return err("values file is not a valid YAML mapping");
|
|
18
|
+
const checked = appValuesSchema.safeParse(parsed.value);
|
|
19
|
+
return checked.success ? ok(checked.data) : err("values must be strings, numbers, or booleans");
|
|
20
|
+
};
|
|
21
|
+
const present = (values, key) => Object.hasOwn(values, key) && values[key] !== "";
|
|
22
|
+
const fileOf = (server, name, secret) => within(server.dir, "apps", `${name}${secret ? ".secrets" : ""}.yml`);
|
|
23
|
+
const opened = async (server, file, source) => {
|
|
24
|
+
if (source === undefined)
|
|
25
|
+
return ok("");
|
|
26
|
+
if (!isVaulted(source)) {
|
|
27
|
+
if (server.vault.kind !== "none")
|
|
28
|
+
return err("secrets must be Ansible Vault encrypted for this server");
|
|
29
|
+
return ok(source);
|
|
30
|
+
}
|
|
31
|
+
const result = await spawned(["ansible-vault", "view", file], { stdout: "capture", stderr: "capture", stdin: { kind: "none" } }, vault(server).env);
|
|
32
|
+
return result.code === 0 ? ok(result.stdout) : err("cannot open app secrets; configure vault_password_file or provide the vault password through the client");
|
|
33
|
+
};
|
|
34
|
+
export const inspectValues = async (root, server, name, dir) => {
|
|
35
|
+
const required = requirements(root, server, name, textAt, dir);
|
|
36
|
+
if (!required.ok)
|
|
37
|
+
return required;
|
|
38
|
+
const config = parsedValues(textAt(fileOf(server, name, false)) ?? "");
|
|
39
|
+
if (!config.ok)
|
|
40
|
+
return config;
|
|
41
|
+
const file = fileOf(server, name, true);
|
|
42
|
+
const source = textAt(file);
|
|
43
|
+
const secret = source !== undefined && isVaulted(source) && server.vault.kind === "ask"
|
|
44
|
+
? err("configure vault_password_file to inspect encrypted secret presence without prompting")
|
|
45
|
+
: await opened(server, file, source);
|
|
46
|
+
const values = secret.ok ? parsedValues(secret.value) : secret;
|
|
47
|
+
if (secret.ok && !values.ok)
|
|
48
|
+
return values;
|
|
49
|
+
return ok({
|
|
50
|
+
server: server.name, app: name, manifest: required.value.manifest,
|
|
51
|
+
config: required.value.config.map((key) => ({ key, state: present(config.value, key) ? "set" : "missing" })),
|
|
52
|
+
secrets: required.value.secrets.map((key) => ({ key, state: values.ok ? (present(values.value, key) ? "set" : "missing") : "locked" })),
|
|
53
|
+
hint: values.ok ? null : values.error,
|
|
54
|
+
});
|
|
55
|
+
};
|
|
56
|
+
const store = (file, original, content) => {
|
|
57
|
+
const temporary = `${file}.${randomUUID()}.tmp`;
|
|
58
|
+
try {
|
|
59
|
+
if (textAt(file) !== original)
|
|
60
|
+
return err("values changed during this operation; retry with the latest file");
|
|
61
|
+
writeFileSync(temporary, content, { mode: 0o600, flag: "wx" });
|
|
62
|
+
renameSync(temporary, file);
|
|
63
|
+
return ok("saved");
|
|
64
|
+
}
|
|
65
|
+
finally {
|
|
66
|
+
rmSync(temporary, { force: true });
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
const editFile = async (server, name, edit) => {
|
|
70
|
+
const file = fileOf(server, name, edit.kind !== "config");
|
|
71
|
+
if (existsSync(file) && lstatSync(file).isSymbolicLink())
|
|
72
|
+
return err("refusing to replace a symlinked values file");
|
|
73
|
+
const original = textAt(file);
|
|
74
|
+
if (edit.kind === "config" && original !== undefined && isVaulted(original))
|
|
75
|
+
return err("configuration belongs in plaintext, not a vault");
|
|
76
|
+
const source = edit.kind === "config" ? ok(original ?? "") : await opened(server, file, original);
|
|
77
|
+
if (!source.ok)
|
|
78
|
+
return source;
|
|
79
|
+
const existing = parsedValues(source.value);
|
|
80
|
+
if (!existing.ok)
|
|
81
|
+
return existing;
|
|
82
|
+
if (edit.kind === "generate" && present(existing.value, edit.key))
|
|
83
|
+
return ok(`${edit.key} already exists; kept it`);
|
|
84
|
+
const value = edit.kind === "config" ? edit.value : edit.kind === "generate" ? randomBytes(32).toString("hex") : readFileSync(edit.file, "utf8").replace(/\r?\n$/, "");
|
|
85
|
+
if (value.includes("\0") || (edit.kind !== "config" && value === ""))
|
|
86
|
+
return err("secret input must be nonempty text without NUL bytes");
|
|
87
|
+
if (existing.value[edit.key] === value)
|
|
88
|
+
return ok(`${edit.key} is unchanged`);
|
|
89
|
+
const document = parseDocument(source.value || "{}\n");
|
|
90
|
+
document.set(edit.key, value);
|
|
91
|
+
const plaintext = document.toString();
|
|
92
|
+
if (edit.kind === "config" || (server.vault.kind === "none" && (original === undefined || !isVaulted(original)))) {
|
|
93
|
+
const saved = store(file, original, plaintext);
|
|
94
|
+
return saved.ok ? ok(`${edit.key} saved in the fleet; apply with kayra apps ${server.name} after reviewing the change`) : saved;
|
|
95
|
+
}
|
|
96
|
+
// Vault receives plaintext over stdin; only ciphertext reaches a temporary file.
|
|
97
|
+
const encrypted = await spawned(["ansible-vault", "encrypt", "--output", "-"], { stdout: "capture", stderr: "capture", stdin: { kind: "given", text: plaintext } }, vault(server).env);
|
|
98
|
+
if (encrypted.code !== 0 || !isVaulted(encrypted.stdout))
|
|
99
|
+
return err("could not encrypt app secrets; the existing file was not changed");
|
|
100
|
+
const saved = store(file, original, encrypted.stdout);
|
|
101
|
+
return saved.ok ? ok(`${edit.key} saved in the fleet; apply with kayra apps ${server.name} after reviewing the change`) : saved;
|
|
102
|
+
};
|
|
103
|
+
export const editValues = async (root, server, name, edit, dir) => {
|
|
104
|
+
const required = requirements(root, server, name, textAt, dir);
|
|
105
|
+
if (!required.ok)
|
|
106
|
+
return required;
|
|
107
|
+
const keys = edit.kind === "config" ? required.value.config : required.value.secrets;
|
|
108
|
+
if (!keys.includes(edit.key))
|
|
109
|
+
return err(`${edit.key} is not a declared ${edit.kind === "config" ? "configuration" : "secret"} key`);
|
|
110
|
+
const directory = dirname(fileOf(server, name, edit.kind !== "config"));
|
|
111
|
+
mkdirSync(directory, { recursive: true, mode: 0o700 });
|
|
112
|
+
if (lstatSync(directory).isSymbolicLink())
|
|
113
|
+
return err("refusing a symlinked apps directory");
|
|
114
|
+
const lock = join(directory, ".kayra-values.lock");
|
|
115
|
+
const acquired = attempt(() => { mkdirSync(lock, { mode: 0o700 }); return ok(true); }, () => "app values are being edited; retry, or remove apps/.kayra-values.lock if its writer was interrupted");
|
|
116
|
+
if (!acquired.ok)
|
|
117
|
+
return acquired;
|
|
118
|
+
try {
|
|
119
|
+
return await editFile(server, name, edit);
|
|
120
|
+
}
|
|
121
|
+
finally {
|
|
122
|
+
rmSync(lock, { recursive: true, force: true });
|
|
123
|
+
}
|
|
124
|
+
};
|
|
@@ -1,18 +1,23 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
2
|
const deployed = z.object({ sha: z.string(), time: z.iso.datetime() });
|
|
3
|
+
/** One run, as `ctl runs --json` lists it and `ctl deploy --json` ends with it. */
|
|
4
|
+
export const runSchema = z.object({
|
|
5
|
+
id: z.string(),
|
|
6
|
+
state: z.enum(["queued", "running", "success", "failure", "superseded"]),
|
|
7
|
+
why: z.string(),
|
|
8
|
+
what: z.string(),
|
|
9
|
+
sha: z.string().exactOptional(),
|
|
10
|
+
started: z.iso.datetime(),
|
|
11
|
+
finished: z.iso.datetime().exactOptional(),
|
|
12
|
+
error: z.string().exactOptional(),
|
|
13
|
+
urls: z.array(z.string()).exactOptional(),
|
|
14
|
+
checks: z.array(z.object({ url: z.string(), status: z.number().int(), ok: z.boolean() })).exactOptional(),
|
|
15
|
+
});
|
|
3
16
|
/** `ctl runs <app> --json`, as this kayra reads it. */
|
|
4
17
|
export const runsSchema = z.object({
|
|
5
18
|
app: z.string(),
|
|
6
19
|
live: deployed.exactOptional(),
|
|
7
|
-
runs: z.array(
|
|
8
|
-
id: z.string(),
|
|
9
|
-
state: z.enum(["running", "success", "failure"]),
|
|
10
|
-
why: z.string(),
|
|
11
|
-
what: z.string(),
|
|
12
|
-
sha: z.string().exactOptional(),
|
|
13
|
-
started: z.iso.datetime(),
|
|
14
|
-
finished: z.iso.datetime().exactOptional(),
|
|
15
|
-
})),
|
|
20
|
+
runs: z.array(runSchema),
|
|
16
21
|
});
|
|
17
22
|
/** `ctl rollback <app> --json`, as this kayra reads it. */
|
|
18
23
|
export const releasesSchema = z.object({
|
|
@@ -4,18 +4,17 @@ import { z } from "zod";
|
|
|
4
4
|
import { branded } from "../../lib/brand.js";
|
|
5
5
|
import { err, ok } from "../../lib/result.js";
|
|
6
6
|
import { minting } from "../../lib/schema.js";
|
|
7
|
-
|
|
7
|
+
import { names } from "../../lib/names.js";
|
|
8
|
+
/** A string matching a name's pattern: brand it, and it is the schema the fleet's files are parsed with and the constructor everything else mints with. */
|
|
8
9
|
// eslint-disable-next-line functional/prefer-immutable-types -- a RegExp, and a Zod schema: immutable once built, but classes the rule cannot see into
|
|
9
|
-
const pattern = (regex, what) => z.string().regex(regex, { error: (issue) => `'${String(issue.input)}' is not ${what}` });
|
|
10
|
-
export const serverNameSchema = pattern(/^[a-z0-9][a-z0-9-]*$/, "a server name (lowercase letters, digits, dashes)").transform(branded());
|
|
11
|
-
export const appNameSchema = pattern(
|
|
12
|
-
export const subdomainSchema = pattern(
|
|
13
|
-
|
|
14
|
-
export const
|
|
15
|
-
export const
|
|
16
|
-
|
|
17
|
-
export const periodSchema = pattern(/^[1-9][0-9]*(ms|s|m|h)$/, "a period such as 10s, 10m or 1h").transform(branded());
|
|
18
|
-
export const domainSchema = pattern(/^([a-z0-9]([a-z0-9-]*[a-z0-9])?\.)+[a-z][a-z0-9-]*$/, "a domain").transform(branded());
|
|
10
|
+
const pattern = ({ pattern: regex, what }) => z.string().regex(regex, { error: (issue) => `'${String(issue.input)}' is not ${what}` });
|
|
11
|
+
export const serverNameSchema = pattern({ pattern: /^[a-z0-9][a-z0-9-]*$/, what: "a server name (lowercase letters, digits, dashes)" }).transform(branded());
|
|
12
|
+
export const appNameSchema = pattern(names.app).transform(branded());
|
|
13
|
+
export const subdomainSchema = pattern(names.subdomain).transform(branded());
|
|
14
|
+
export const routePathSchema = pattern(names.routePath).transform(branded());
|
|
15
|
+
export const serviceNameSchema = pattern(names.serviceName).transform(branded());
|
|
16
|
+
export const periodSchema = pattern(names.period).transform(branded());
|
|
17
|
+
export const domainSchema = pattern({ pattern: /^([a-z0-9]([a-z0-9-]*[a-z0-9])?\.)+[a-z][a-z0-9-]*$/, what: "a domain" }).transform(branded());
|
|
19
18
|
/** A path inside a repository, never above it. */
|
|
20
19
|
export const repoPathSchema = z
|
|
21
20
|
.string()
|
|
@@ -27,7 +26,6 @@ export const serverName = minting(serverNameSchema);
|
|
|
27
26
|
export const appName = minting(appNameSchema);
|
|
28
27
|
export const subdomain = minting(subdomainSchema);
|
|
29
28
|
export const domain = minting(domainSchema);
|
|
30
|
-
export const repoPath = minting(repoPathSchema);
|
|
31
29
|
/** `~/…` is the operator's home, as Ansible reads it in vault_password_file. */
|
|
32
30
|
export const absolutePath = (value) => {
|
|
33
31
|
const expanded = value === "~" || value.startsWith("~/") ? join(homedir(), value.slice(1)) : value;
|
|
@@ -4,9 +4,7 @@ import { appNameSchema, domainSchema, periodSchema, repoPathSchema, repoUrlSchem
|
|
|
4
4
|
import { serverTargets } from "./model.js";
|
|
5
5
|
/** The server kinds, each with its playbook; settings say which kinds read them. */
|
|
6
6
|
export const serverKinds = ["platform", "edge", "nas"];
|
|
7
|
-
// eslint-disable-next-line functional/prefer-immutable-types -- holds a Zod schema: immutable once built, but a class the rule cannot see into
|
|
8
7
|
const setting = (name, kinds, schema, description) => typed({ name, kinds, secret: false, schema: schema.describe(description), description });
|
|
9
|
-
// eslint-disable-next-line functional/prefer-immutable-types -- holds a Zod schema: immutable once built, but a class the rule cannot see into
|
|
10
8
|
const secret = (name, kinds, schema, description) => typed({ name, kinds, secret: true, schema: schema.describe(description), description });
|
|
11
9
|
const text = z.string();
|
|
12
10
|
const texts = z.array(z.string());
|
|
@@ -26,6 +24,8 @@ export const settings = [
|
|
|
26
24
|
setting("authelia_smtp_username", platform, text, "SMTP user for Authelia."),
|
|
27
25
|
setting("authelia_smtp_sender", platform, text, "Sender address of Authelia's mails."),
|
|
28
26
|
setting("acme_dns", platform, z.enum(["", "hetzner"]), "Certificates by DNS-01 instead of HTTP-01, for a server the internet never reaches: the DNS provider (hetzner)."),
|
|
27
|
+
setting("webhooks", platform, z.boolean(), "Whether a push webhook may start a deploy at once: true (default) serves deploy.<domain>/hook/<app>; false serves no such endpoint, and pushes deploy by deploy_poll."),
|
|
28
|
+
setting("deploy_poll", platform, text, "When the deployer looks for pushes no webhook brought, as a five-field cron spec in the server's time (default hourly: 17 * * * *)."),
|
|
29
29
|
setting("renovate_repositories", platform, texts, "owner/repo of the repos this server's Renovate job keeps up to date; the job runs only where the list is not empty."),
|
|
30
30
|
setting("renovate_schedule", platform, text, "When the Renovate job runs, as a five-field cron spec in the server's time (default weekly: 0 4 * * 1)."),
|
|
31
31
|
setting("renovate_platform", platform, z.enum(["github", "forgejo", "gitlab"]), "Where the repos live: github (default), forgejo or gitlab."),
|
|
@@ -106,7 +106,7 @@ export const settings = [
|
|
|
106
106
|
];
|
|
107
107
|
/** Ansible's own variables (connection, privilege escalation) are always allowed. */
|
|
108
108
|
export const isAnsibleVariable = (key) => key.startsWith("ansible_");
|
|
109
|
-
|
|
109
|
+
const settingsFor = (kind, secrets) => Object.freeze(settings.filter((each) => each.secret === secrets && each.kinds.includes(kind)));
|
|
110
110
|
// eslint-disable-next-line functional/prefer-immutable-types -- Zod schemas: immutable once built, but classes the rule cannot see into
|
|
111
111
|
const shape = (chosen) => Object.fromEntries(chosen.map((each) => [each.name, each.schema.optional()]));
|
|
112
112
|
/** vars.yml for a kind: its settings and nothing else (Ansible's own variables apart). */
|
|
@@ -123,6 +123,13 @@ export const secretsSchema = (kind) => z.looseObject(shape(settingsFor(kind, tru
|
|
|
123
123
|
*/
|
|
124
124
|
const schemes = (target) => typed(target === "multipass" ? ["https://", "http://"] : ["https://"]);
|
|
125
125
|
/** server.yml: topology only. What it says is checked here, once: the parser, the editors' schema and the docs read it. */
|
|
126
|
+
/** One app in server.yml: where its code is and which branch deploys. */
|
|
127
|
+
export const appEntrySchema = z.strictObject({
|
|
128
|
+
name: appNameSchema,
|
|
129
|
+
repo: repoUrlSchema.describe("The app's repository, https://."),
|
|
130
|
+
ref: z.string().optional().describe("The branch to build and deploy (default main)."),
|
|
131
|
+
path: repoPathSchema.prefault(".").describe("The app's root inside the repository (default .)."),
|
|
132
|
+
});
|
|
126
133
|
export const serverSchema = z
|
|
127
134
|
.strictObject({
|
|
128
135
|
kind: z
|
|
@@ -136,12 +143,7 @@ export const serverSchema = z
|
|
|
136
143
|
vault: z.boolean().default(false).describe("secrets.yml is vault-encrypted (required outside multipass)."),
|
|
137
144
|
vault_password_file: z.string().optional().describe("The vault password file; without it, Ansible asks."),
|
|
138
145
|
apps: z
|
|
139
|
-
.array(
|
|
140
|
-
name: appNameSchema,
|
|
141
|
-
repo: repoUrlSchema.describe("The app's repository, https://."),
|
|
142
|
-
ref: z.string().optional().describe("The branch to build and deploy (default main)."),
|
|
143
|
-
path: repoPathSchema.prefault(".").describe("The app's root inside the repository (default .)."),
|
|
144
|
-
}))
|
|
146
|
+
.array(appEntrySchema)
|
|
145
147
|
.default([])
|
|
146
148
|
.describe("The apps this server runs (platform only)."),
|
|
147
149
|
})
|
|
@@ -171,6 +173,9 @@ const routeSchema = z.strictObject({
|
|
|
171
173
|
})
|
|
172
174
|
.optional()
|
|
173
175
|
.describe("A rate limit on this route, per client address (Traefik's rateLimit)."),
|
|
176
|
+
check: routePathSchema
|
|
177
|
+
.optional()
|
|
178
|
+
.describe("A path that answers 2xx or 3xx once the app is ready; a deploy waits for it. Without one, the route's own path must answer below 500."),
|
|
174
179
|
});
|
|
175
180
|
/** app.yml, at the root of an app's repository: the app contract. */
|
|
176
181
|
export const appManifestSchema = z.strictObject({
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
|
+
import { valueKeySchema } from "../app-values/model.js";
|
|
2
3
|
/**
|
|
3
4
|
* Every kayra operation, once: what each client (the command line, the API,
|
|
4
5
|
* the web interface) offers, and what it may ask for. A client names an
|
|
@@ -19,6 +20,7 @@ const server = z.string().min(1).describe("A server of the fleet (servers/<name>
|
|
|
19
20
|
const app = z.string().min(1).describe("An app name, including a removed app whose records or data remain");
|
|
20
21
|
const serverInput = z.strictObject({ server });
|
|
21
22
|
const appInput = z.strictObject({ server, app });
|
|
23
|
+
const dir = z.string().min(1).optional().describe("Local app directory containing app.yml; otherwise use the fleet cache");
|
|
22
24
|
export const operations = {
|
|
23
25
|
up: {
|
|
24
26
|
summary: "Provision, set up everything, point /etc/hosts at it.",
|
|
@@ -78,6 +80,16 @@ export const operations = {
|
|
|
78
80
|
kind: "plan",
|
|
79
81
|
input: serverInput,
|
|
80
82
|
},
|
|
83
|
+
"app.init": {
|
|
84
|
+
summary: "Make an existing project with a compose file or Dockerfile deployable: write app.yml and the platform's overlay, then check it.",
|
|
85
|
+
scope: "repo",
|
|
86
|
+
effect: "changes",
|
|
87
|
+
kind: "plan",
|
|
88
|
+
input: z.strictObject({
|
|
89
|
+
dir: z.string().min(1).default(".").describe("The project's repository"),
|
|
90
|
+
name: z.string().min(1).optional().describe("The app's name; the directory's by default"),
|
|
91
|
+
}),
|
|
92
|
+
},
|
|
81
93
|
"app.check": {
|
|
82
94
|
summary: "What the platform checks at deploy (app.yml, images, compose policy), in an app's repository. No fleet needed.",
|
|
83
95
|
scope: "repo",
|
|
@@ -85,6 +97,39 @@ export const operations = {
|
|
|
85
97
|
kind: "plan",
|
|
86
98
|
input: z.strictObject({ dir: z.string().min(1).default(".").describe("The app's repository") }),
|
|
87
99
|
},
|
|
100
|
+
"app.values": {
|
|
101
|
+
summary: "Which configuration and secrets app.yml declares, and whether each has a value; never the values.",
|
|
102
|
+
scope: "app", effect: "reads", kind: "query", input: z.strictObject({ server, app, dir }),
|
|
103
|
+
},
|
|
104
|
+
"app.config.set": {
|
|
105
|
+
summary: "Prepare a declared configuration value in the local fleet; apply separately with apps.",
|
|
106
|
+
scope: "app", effect: "changes", kind: "plan", local: true,
|
|
107
|
+
input: z.strictObject({ server, app, dir, key: valueKeySchema, value: z.string().min(1).refine((value) => !value.includes("\0"), "NUL is not an environment value") }),
|
|
108
|
+
},
|
|
109
|
+
"app.secret.import": {
|
|
110
|
+
summary: "Import a declared secret from a local file into the fleet vault; never print its value.",
|
|
111
|
+
scope: "app", effect: "changes", kind: "plan", local: true,
|
|
112
|
+
input: z.strictObject({ server, app, dir, key: valueKeySchema, file: z.string().min(1).describe("Local file containing the secret, not YAML; one trailing newline is removed") }),
|
|
113
|
+
},
|
|
114
|
+
"app.secret.generate": {
|
|
115
|
+
summary: "Generate a 32-byte random secret in the fleet only if missing; preserve existing values.",
|
|
116
|
+
scope: "app", effect: "changes", kind: "plan", local: true,
|
|
117
|
+
input: z.strictObject({ server, app, dir, key: valueKeySchema }),
|
|
118
|
+
},
|
|
119
|
+
"app.launch": {
|
|
120
|
+
summary: "From a repository to a URL that answers: register the app, check its values, apply the apps, deploy and follow it. Run it again after a stop.",
|
|
121
|
+
scope: "app", effect: "changes", kind: "plan",
|
|
122
|
+
input: z.strictObject({
|
|
123
|
+
server, app, dir,
|
|
124
|
+
repo: z.string().min(1).optional().describe("The app's repository, https://; needed until server.yml registers it"),
|
|
125
|
+
ref: z.string().min(1).optional().describe("The branch that deploys (default main)"),
|
|
126
|
+
path: z.string().min(1).optional().describe("The app's root inside the repository (default .)"),
|
|
127
|
+
}),
|
|
128
|
+
},
|
|
129
|
+
"app.hook": {
|
|
130
|
+
summary: "Wire an app's repository (GitHub, GitLab, Forgejo, Gitea) to a server that takes webhooks: check the platform's token reads it, create or update its push hook.",
|
|
131
|
+
scope: "app", effect: "changes", kind: "plan", input: appInput,
|
|
132
|
+
},
|
|
88
133
|
"app.purge": { summary: "Delete a removed app's volumes: its data, irreversibly.", scope: "app", effect: "destroys", kind: "plan", input: appInput },
|
|
89
134
|
"app.runs": {
|
|
90
135
|
summary: "What runs now, and the app's latest runs: state, commit, why, when, how long.",
|
|
@@ -166,4 +211,4 @@ export const operationNames = Object.keys(operations).filter((name) => Object.ha
|
|
|
166
211
|
export const isOperation = (name) => Object.hasOwn(operations, name);
|
|
167
212
|
/** An operation as every client reads it, whatever its own entry spells out. */
|
|
168
213
|
const described = operations;
|
|
169
|
-
export const operation = (name) =>
|
|
214
|
+
export const operation = (name) => described[name];
|
|
@@ -1,7 +1,11 @@
|
|
|
1
|
+
import { inspectValues } from "../app-values/store.js";
|
|
2
|
+
import { appValues } from "../recipes/app-values.js";
|
|
1
3
|
import { resolve } from "node:path";
|
|
2
4
|
import { z } from "zod";
|
|
3
5
|
import { absolutePath, appName, domain, subdomain, within } from "../fleet/brand.js";
|
|
4
|
-
import { appCheck } from "../recipes/app-check.js";
|
|
6
|
+
import { appCheck, appInit } from "../recipes/app-check.js";
|
|
7
|
+
import { launch } from "../recipes/launch.js";
|
|
8
|
+
import { appHook } from "../recipes/app-hook.js";
|
|
5
9
|
import { doctor } from "../recipes/doctor.js";
|
|
6
10
|
import { appPurge, apps, deployer } from "../recipes/apps.js";
|
|
7
11
|
import { adopt, deploy, down, hosts, preview, provision, setup, up, verify } from "../recipes/host.js";
|
|
@@ -36,7 +40,14 @@ const invocations = z.discriminatedUnion("name", [
|
|
|
36
40
|
z.strictObject({ name: z.literal("down"), input: operations.down.input }),
|
|
37
41
|
z.strictObject({ name: z.literal("adopt"), input: operations.adopt.input }),
|
|
38
42
|
z.strictObject({ name: z.literal("backup.test"), input: operations["backup.test"].input }),
|
|
43
|
+
z.strictObject({ name: z.literal("app.init"), input: operations["app.init"].input }),
|
|
39
44
|
z.strictObject({ name: z.literal("app.check"), input: operations["app.check"].input }),
|
|
45
|
+
z.strictObject({ name: z.literal("app.values"), input: operations["app.values"].input }),
|
|
46
|
+
z.strictObject({ name: z.literal("app.launch"), input: operations["app.launch"].input }),
|
|
47
|
+
z.strictObject({ name: z.literal("app.hook"), input: operations["app.hook"].input }),
|
|
48
|
+
z.strictObject({ name: z.literal("app.config.set"), input: operations["app.config.set"].input }),
|
|
49
|
+
z.strictObject({ name: z.literal("app.secret.import"), input: operations["app.secret.import"].input }),
|
|
50
|
+
z.strictObject({ name: z.literal("app.secret.generate"), input: operations["app.secret.generate"].input }),
|
|
40
51
|
z.strictObject({ name: z.literal("app.purge"), input: operations["app.purge"].input }),
|
|
41
52
|
z.strictObject({ name: z.literal("app.runs"), input: operations["app.runs"].input }),
|
|
42
53
|
z.strictObject({ name: z.literal("app.log"), input: operations["app.log"].input }),
|
|
@@ -68,9 +79,9 @@ const onServer = (ctx, name) => {
|
|
|
68
79
|
* app's runs, logs and volumes stay the deployer's to answer for and purge.
|
|
69
80
|
*/
|
|
70
81
|
const onApp = (ctx, input) => flatMap(onServer(ctx, input.server), (target) => map(appName(input.app), (app) => [target, app]));
|
|
82
|
+
const appDir = (ctx, dir) => dir === undefined ? ok(undefined) : absolutePath(resolve(ctx.here, dir));
|
|
71
83
|
const withServer = (make) => (ctx, input) => flatMap(onServer(ctx, input.server), (target) => make(ctx.engine, target));
|
|
72
84
|
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
85
|
/** Each plan operation, as the plan that does it: the compiler refuses one that has none. */
|
|
75
86
|
const plans = {
|
|
76
87
|
up: withServer(up),
|
|
@@ -86,13 +97,19 @@ const plans = {
|
|
|
86
97
|
"backup.test": withServer(backupTest),
|
|
87
98
|
ssh: (ctx, input) => flatMap(onServer(ctx, input.server), (target) => ssh(target, [])),
|
|
88
99
|
"ssh.exec": (ctx, input) => flatMap(onServer(ctx, input.server), (target) => ssh(target, input.command)),
|
|
100
|
+
"app.init": (ctx, input) => map(absolutePath(resolve(ctx.here, input.dir)), (dir) => appInit(ctx.engine.kayra, dir, input.name)),
|
|
89
101
|
"app.check": (ctx, input) => flatMap(absolutePath(resolve(ctx.here, input.dir)), (dir) => appCheck(ctx.engine.kayra, dir, ctx.read(within(dir, "app.yml")))),
|
|
102
|
+
"app.config.set": (ctx, input) => flatMap(onApp(ctx, input), ([server, app]) => flatMap(appDir(ctx, input.dir), (dir) => appValues(ctx.engine, server, app, { kind: "config", key: input.key, value: input.value }, ctx.here, ctx.read, dir))),
|
|
103
|
+
"app.secret.import": (ctx, input) => flatMap(onApp(ctx, input), ([server, app]) => flatMap(appDir(ctx, input.dir), (dir) => appValues(ctx.engine, server, app, { kind: "import", key: input.key, file: input.file }, ctx.here, ctx.read, dir))),
|
|
104
|
+
"app.secret.generate": (ctx, input) => flatMap(onApp(ctx, input), ([server, app]) => flatMap(appDir(ctx, input.dir), (dir) => appValues(ctx.engine, server, app, { kind: "generate", key: input.key }, ctx.here, ctx.read, dir))),
|
|
105
|
+
"app.launch": (ctx, input) => flatMap(onApp(ctx, input), ([server, app]) => flatMap(appDir(ctx, input.dir), (dir) => launch(ctx.engine, ctx.fleet.root, server, { app, repo: input.repo, ref: input.ref, path: input.path, dir }))),
|
|
106
|
+
"app.hook": (ctx, input) => flatMap(onApp(ctx, input), ([server, app]) => appHook(ctx.engine, ctx.fleet.root, server, app)),
|
|
90
107
|
"app.purge": (ctx, input) => flatMap(onApp(ctx, input), ([target, app]) => appPurge(ctx.engine, target, app)),
|
|
91
108
|
"app.runs": onDeployer((app) => ({ kind: "runs", app, more: undefined })),
|
|
92
|
-
"app.log": onDeployer((app, input) => ({ kind: "logs", app, more:
|
|
93
|
-
"app.deploy": onDeployer((app, input) => ({ kind: "deploy", app, more:
|
|
109
|
+
"app.log": onDeployer((app, input) => ({ kind: "logs", app, more: input.run })),
|
|
110
|
+
"app.deploy": onDeployer((app, input) => ({ kind: "deploy", app, more: input.ref })),
|
|
94
111
|
"app.releases": onDeployer((app) => ({ kind: "rollback", app, more: undefined })),
|
|
95
|
-
"app.rollback": onDeployer((app, input) => ({ kind: "rollback", app, more:
|
|
112
|
+
"app.rollback": onDeployer((app, input) => ({ kind: "rollback", app, more: input.sha })),
|
|
96
113
|
job: (ctx, input) => flatMap(onServer(ctx, input.server), (target) => deployer(target, { kind: "job", job: input.job, noPrs: input.noPrs })),
|
|
97
114
|
doctor: (ctx) => ok(doctor(ctx.fleet, ctx.engine)),
|
|
98
115
|
certs: (ctx, input) => flatMap(domain(input.domain), (named) => flatMap(all(input.subdomains.map(subdomain)), (subdomains) => certsFor(ctx.engine, named, subdomains))),
|
|
@@ -116,6 +133,20 @@ const deployerAnswer = async (ctx, name, input) => {
|
|
|
116
133
|
return exit.code === 0 ? ok(exit.stdout) : err(exit.stderr.trim() || "the deployer query failed");
|
|
117
134
|
};
|
|
118
135
|
const queries = {
|
|
136
|
+
"app.values": async (ctx, input) => {
|
|
137
|
+
const target = onApp(ctx, input);
|
|
138
|
+
if (!target.ok)
|
|
139
|
+
return target;
|
|
140
|
+
const dir = appDir(ctx, input.dir);
|
|
141
|
+
if (!dir.ok)
|
|
142
|
+
return dir;
|
|
143
|
+
try {
|
|
144
|
+
return await inspectValues(ctx.fleet.root, target.value[0], target.value[1], dir.value);
|
|
145
|
+
}
|
|
146
|
+
catch {
|
|
147
|
+
return err("app values could not be inspected; check file access and vault configuration");
|
|
148
|
+
}
|
|
149
|
+
},
|
|
119
150
|
"app.runs": (ctx, input) => deployerAnswer(ctx, "app.runs", input),
|
|
120
151
|
"app.releases": (ctx, input) => deployerAnswer(ctx, "app.releases", input),
|
|
121
152
|
"app.log": (ctx, input) => deployerAnswer(ctx, "app.log", input),
|
|
@@ -123,7 +154,7 @@ const queries = {
|
|
|
123
154
|
const chosen = input.server === undefined ? ok(ctx.fleet.servers) : map(onServer(ctx, input.server), (one) => Object.freeze([one]));
|
|
124
155
|
if (!chosen.ok)
|
|
125
156
|
return chosen;
|
|
126
|
-
return ok(await Promise.all(chosen.value.map(async (each) => ({ server: each, findings: findings(await gather(ctx.fleet.root, each)) }))));
|
|
157
|
+
return ok(Object.freeze(await Promise.all(chosen.value.map(async (each) => typed({ server: each, findings: findings(await gather(ctx.fleet.root, each)) })))));
|
|
127
158
|
},
|
|
128
159
|
version: (ctx) => Promise.resolve(ok(ctx.version)),
|
|
129
160
|
};
|
|
@@ -13,10 +13,23 @@ const tool = (program, hint) => onPath(`${program} is installed`, program, hint,
|
|
|
13
13
|
* image plan and the compose policy, the same scripts the builder and the
|
|
14
14
|
* deployer run). Needs no fleet and no server.
|
|
15
15
|
*/
|
|
16
|
+
/**
|
|
17
|
+
* In an existing project without app.yml: what app init writes (app.yml, an
|
|
18
|
+
* overlay of the project's compose file, an image manifest per built service),
|
|
19
|
+
* then the same check as app check, which names what is left to do.
|
|
20
|
+
*/
|
|
21
|
+
export const appInit = (kayra, root, name) => typed([
|
|
22
|
+
tool("git", "brew install git"),
|
|
23
|
+
tool("jq", "brew install jq"),
|
|
24
|
+
tool("yq", "brew install yq"),
|
|
25
|
+
tool("docker", "the docker CLI with Compose; no daemon is needed"),
|
|
26
|
+
run("Write app.yml and the platform's overlay", [process.execPath, within(kayra, "bin", "kayra-app-init.js"), JSON.stringify({ root, ...(name === undefined ? {} : { name }) })]),
|
|
27
|
+
run("Image plan and compose policy", ["bash", within(kayra, "scripts", "local", "app-check.sh"), root]),
|
|
28
|
+
]);
|
|
16
29
|
export const appCheck = (kayra, root, manifest) => {
|
|
17
30
|
if (manifest === undefined)
|
|
18
31
|
return err(`no app.yml in ${root}`);
|
|
19
|
-
const shaped = flatMap(mapError(yamlOf(manifest), (problem) => `app.yml ${problem}`), (values) => checkShape("app.yml", values, appManifestSchema));
|
|
32
|
+
const shaped = flatMap(mapError(yamlOf(manifest), (problem) => `app.yml ${problem}`), (values) => map(checkShape("app.yml", values, appManifestSchema), () => manifest));
|
|
20
33
|
return map(shaped, () => typed([
|
|
21
34
|
tool("git", "brew install git"),
|
|
22
35
|
tool("jq", "brew install jq"),
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { within } from "../fleet/brand.js";
|
|
2
|
+
import { run } from "../plan/model.js";
|
|
3
|
+
import { err, flatMap, ok } from "../../lib/result.js";
|
|
4
|
+
import { vaulted } from "./steps.js";
|
|
5
|
+
/** Whether a server takes push webhooks: its vars.yml's `webhooks` (default true), and a forge able to reach it. */
|
|
6
|
+
export const takesWebhooks = (server) => {
|
|
7
|
+
if (server.kind !== "platform")
|
|
8
|
+
return err(`'${server.name}' is a ${server.kind} server: only platform servers run apps.`);
|
|
9
|
+
if (server.vars["webhooks"] === false)
|
|
10
|
+
return err(`${server.name} takes no webhooks (webhooks: false in its vars.yml): pushes deploy by deploy_poll`);
|
|
11
|
+
if (server.target === "multipass")
|
|
12
|
+
return err(`no forge can reach ${server.name}, a multipass VM: deploy there with kayra app deploy`);
|
|
13
|
+
return ok(true);
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* The app's repository wired to its deployer: the platform's token can read
|
|
17
|
+
* it, and one push hook posts to deploy.<domain>/hook/<app> with the platform's
|
|
18
|
+
* secret (kayra-app-hook.js, over the forge's REST API as the operator).
|
|
19
|
+
*/
|
|
20
|
+
export const appHook = (engine, root, server, app) => flatMap(takesWebhooks(server), () => {
|
|
21
|
+
if (!server.apps.some((each) => each.name === app))
|
|
22
|
+
return err(`${app} is not in ${server.name}'s server.yml`);
|
|
23
|
+
return ok([
|
|
24
|
+
vaulted(run(`Hook ${app}'s repository to ${server.name}`, [process.execPath, within(engine.kayra, "bin", "kayra-app-hook.js"), JSON.stringify({ root, server: server.name, app })]), server),
|
|
25
|
+
]);
|
|
26
|
+
});
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { resolve } from "node:path";
|
|
2
|
+
import { editSchema, requirements } from "../app-values/model.js";
|
|
3
|
+
import { within } from "../fleet/brand.js";
|
|
4
|
+
import { run } from "../plan/model.js";
|
|
5
|
+
import { vaulted } from "./steps.js";
|
|
6
|
+
import { err, ok } from "../../lib/result.js";
|
|
7
|
+
export const appValues = (engine, server, app, edit, here, read, dir) => {
|
|
8
|
+
if (!editSchema.safeParse(edit).success)
|
|
9
|
+
return err("invalid app value input");
|
|
10
|
+
const required = requirements(engine.fleet, server, app, read, dir);
|
|
11
|
+
if (!required.ok)
|
|
12
|
+
return required;
|
|
13
|
+
const keys = edit.kind === "config" ? required.value.config : required.value.secrets;
|
|
14
|
+
if (!keys.includes(edit.key))
|
|
15
|
+
return err(`${edit.key} is not a declared ${edit.kind === "config" ? "configuration" : "secret"} key`);
|
|
16
|
+
const input = { ...(dir === undefined ? {} : { dir }), root: engine.fleet, server: server.name, app, edit: edit.kind === "import" ? { ...edit, file: resolve(here, edit.file) } : edit };
|
|
17
|
+
const step = run(`Prepare ${app}'s ${edit.kind === "config" ? "configuration" : "secret"} ${edit.key} in the fleet`, [
|
|
18
|
+
process.execPath, within(engine.kayra, "bin", "kayra-app-values.js"), JSON.stringify(input),
|
|
19
|
+
]);
|
|
20
|
+
return ok([edit.kind === "config" ? step : vaulted(step, server)]);
|
|
21
|
+
};
|
|
@@ -34,7 +34,7 @@ const toolChecks = (fleet) => Object.freeze(tools.flatMap((tool) => {
|
|
|
34
34
|
// ansible-vault opens whole-file vaults only; values vaulted inline are opened by setup.
|
|
35
35
|
const vaultChecks = (fleet) => Object.freeze(fleet.servers.flatMap((server) => server.vault.kind === "file" && server.hasVaultedSecrets
|
|
36
36
|
? Object.freeze([
|
|
37
|
-
{
|
|
37
|
+
typed({
|
|
38
38
|
kind: "check",
|
|
39
39
|
label: `vault password opens ${server.name}'s secrets.yml`,
|
|
40
40
|
probe: {
|
|
@@ -43,7 +43,7 @@ const vaultChecks = (fleet) => Object.freeze(fleet.servers.flatMap((server) => s
|
|
|
43
43
|
},
|
|
44
44
|
hint: `the password file is ${server.vault.file}`,
|
|
45
45
|
onFailure: "continue",
|
|
46
|
-
},
|
|
46
|
+
}),
|
|
47
47
|
])
|
|
48
48
|
: Object.freeze([])));
|
|
49
49
|
/** The apps' repositories are cloned on this Mac with the operator's own git credentials. */
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { within } from "../fleet/brand.js";
|
|
2
|
+
import { appEntrySchema } from "../fleet/settings.js";
|
|
3
|
+
import { run } from "../plan/model.js";
|
|
4
|
+
import { err, flatMap, map, ok } from "../../lib/result.js";
|
|
5
|
+
import { apps, deployer } from "./apps.js";
|
|
6
|
+
import { appHook, takesWebhooks } from "./app-hook.js";
|
|
7
|
+
import { forgeRepo } from "../../lib/forge-repo.js";
|
|
8
|
+
import { vaulted } from "./steps.js";
|
|
9
|
+
import { typed } from "../../lib/typed.js";
|
|
10
|
+
/** The server.yml entry the launch registers, or the one already there; a different one given is refused, never overwritten. */
|
|
11
|
+
const entryOf = (server, launch) => {
|
|
12
|
+
const registered = server.apps.find((app) => app.name === launch.app);
|
|
13
|
+
if (registered === undefined) {
|
|
14
|
+
if (launch.repo === undefined)
|
|
15
|
+
return err(`${launch.app} is not in ${server.name}'s server.yml yet: give its repository with --repo https://…`);
|
|
16
|
+
return ok({ name: launch.app, repo: launch.repo, ...(launch.ref === undefined ? {} : { ref: launch.ref }), ...(launch.path === undefined ? {} : { path: launch.path }) });
|
|
17
|
+
}
|
|
18
|
+
const differs = ["repo", "ref", "path"].filter((key) => launch[key] !== undefined && launch[key] !== (registered.entry[key] ?? (key === "path" ? "." : key === "ref" ? "main" : undefined)));
|
|
19
|
+
return differs.length === 0
|
|
20
|
+
? ok(registered.entry)
|
|
21
|
+
: err(`${server.name}'s server.yml registers ${launch.app} with another ${differs.join(", ")}: change it there, not through launch`);
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* An app from its repository to a URL that answers, in one plan that may be
|
|
25
|
+
* run again until it ends: register it in server.yml and check that every value
|
|
26
|
+
* it declares is set (kayra-app-launch.js), apply the apps (kayra apps, the new
|
|
27
|
+
* entry included), deploy it and follow the run (its readiness included), then,
|
|
28
|
+
* where the server takes webhooks and the repository is on a forge kayra knows,
|
|
29
|
+
* its push hook.
|
|
30
|
+
* On a server changed only from main, the server.yml change stops the apply
|
|
31
|
+
* at its guard until it is merged: the launch says so, and a rerun goes on.
|
|
32
|
+
*/
|
|
33
|
+
export const launch = (engine, root, server, wanted) => {
|
|
34
|
+
if (server.kind !== "platform")
|
|
35
|
+
return err(`'${server.name}' is a ${server.kind} server: only platform servers run apps.`);
|
|
36
|
+
return flatMap(entryOf(server, wanted), (raw) => {
|
|
37
|
+
const parsed = appEntrySchema.safeParse(raw);
|
|
38
|
+
if (!parsed.success)
|
|
39
|
+
return err(`not an app entry: ${parsed.error.issues.map((issue) => `${issue.path.join(".")} ${issue.message}`).join("; ")}`);
|
|
40
|
+
const app = typed({ name: parsed.data.name, repo: parsed.data.repo, path: parsed.data.path, entry: raw });
|
|
41
|
+
const registered = server.apps.some((each) => each.name === app.name);
|
|
42
|
+
const withApp = registered ? server : { ...server, apps: [...server.apps, app] };
|
|
43
|
+
const prepare = vaulted(run(`Register ${app.name} and check its values`, [
|
|
44
|
+
process.execPath,
|
|
45
|
+
within(engine.kayra, "bin", "kayra-app-launch.js"),
|
|
46
|
+
JSON.stringify({ root, server: server.name, entry: raw, ...(wanted.dir === undefined ? {} : { dir: wanted.dir }) }),
|
|
47
|
+
]), server);
|
|
48
|
+
const hook = takesWebhooks(server).ok && forgeRepo(app.repo) !== undefined ? appHook(engine, root, withApp, app.name) : ok([]);
|
|
49
|
+
return flatMap(apps(engine, withApp), (applied) => flatMap(deployer(server, { kind: "deploy", app: app.name, more: undefined }), (deploy) => map(hook, (hooked) => typed([prepare, ...applied, ...deploy, ...hooked]))));
|
|
50
|
+
});
|
|
51
|
+
};
|