@yunuseon/kayra 0.18.0 → 0.20.0
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 +4 -6
- package/ansible/playbooks/edge.yml +5 -0
- package/ansible/playbooks/nas.yml +9 -1
- package/ansible/playbooks/platform.yml +8 -2
- package/ansible/roles/app/tasks/main.yml +33 -3
- package/ansible/roles/kayra-version/defaults/main.yml +5 -0
- package/ansible/roles/kayra-version/tasks/main.yml +18 -0
- package/ansible/roles/platform/defaults/main.yml +3 -0
- package/ansible/roles/platform/tasks/main.yml +6 -84
- 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/status.js +28 -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 +6 -2
- package/cli/dist/clients/wire/status.js +7 -1
- package/cli/dist/clients/wire/words.js +14 -0
- package/cli/dist/core/adapters/network.js +20 -1
- 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 -7
- package/cli/dist/core/fleet/parse.js +10 -1
- package/cli/dist/core/fleet/settings.js +32 -12
- package/cli/dist/core/operations/catalog.js +46 -1
- package/cli/dist/core/operations/dispatch.js +40 -9
- 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 +5 -5
- package/cli/dist/core/recipes/host.js +8 -3
- package/cli/dist/core/recipes/launch.js +51 -0
- package/cli/dist/core/status/look.js +33 -13
- package/cli/dist/core/status/model.js +2 -0
- package/cli/dist/core/validation/facts.js +1 -3
- package/cli/dist/deployer/brand.js +9 -1
- package/cli/dist/deployer/build/builder.js +15 -4
- package/cli/dist/deployer/build/bundle.js +5 -0
- package/cli/dist/deployer/build/client.js +44 -0
- package/cli/dist/deployer/build/compose.js +21 -8
- package/cli/dist/deployer/build/routes.js +149 -0
- package/cli/dist/deployer/ctl/answers.js +6 -2
- package/cli/dist/deployer/ctl/ctl.js +66 -9
- package/cli/dist/deployer/deployer.js +114 -191
- 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 +64 -11
- 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 +69 -8
- package/schema/defaults.json +8 -0
- package/schema/vars-platform.json +8 -0
- package/scripts/local/app-check.sh +12 -9
- package/scripts/local/app-manifests.sh +11 -6
- package/scripts/local/verify.sh +30 -12
- package/scripts/platform/compose-policy.sh +37 -40
- 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-Ct0Eudk4.css +0 -1
- package/cli/dist/browser/assets/index-hcyM6f6T.js +0 -7
- package/compose/traefik/dynamic/ratelimit.yml +0 -21
- package/scripts/agent/guard.sh +0 -125
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The apps to deploy again as they were: deployed once, yet no container of
|
|
3
|
+
* theirs running now — after a Docker update, a reboot, or anything else that
|
|
4
|
+
* stopped them without kayra.
|
|
5
|
+
*/
|
|
6
|
+
export const toRestore = (apps, running) => Object.freeze(apps.flatMap((each) => (each.live !== undefined && !running(each.app) ? Object.freeze([{ app: each.app, live: each.live }]) : Object.freeze([]))));
|
|
@@ -1,7 +1,45 @@
|
|
|
1
1
|
import { err, ok } from "../../lib/result.js";
|
|
2
2
|
import { imagesEnv, parseBundle } from "../build/bundle.js";
|
|
3
3
|
import { config, policy, up } from "../build/compose.js";
|
|
4
|
+
import { describeRoutes, readinessUrl, routesOverride } from "../build/routes.js";
|
|
4
5
|
import { typed } from "../../lib/typed.js";
|
|
6
|
+
/** How often, and how far apart, a URL is asked before it counts as not ready: a minute. */
|
|
7
|
+
const tries = 30;
|
|
8
|
+
const apart = 2_000;
|
|
9
|
+
/** Traefik answers 404 until it has seen the new containers; without a check path, a 404 counts only after this many tries. */
|
|
10
|
+
const routerGrace = 5;
|
|
11
|
+
/**
|
|
12
|
+
* Whether a URL is ready. With a check path: 2xx or 3xx. Without one, the
|
|
13
|
+
* app owes no particular answer, only one below 500.
|
|
14
|
+
*/
|
|
15
|
+
const passes = (status, strict, attempt) => strict ? status >= 200 && status < 400 : status > 0 && status < 500 && (status !== 404 || attempt >= routerGrace);
|
|
16
|
+
const probeUntil = async (fx, url, strict, attempt = 1) => {
|
|
17
|
+
const status = await fx.probe(url);
|
|
18
|
+
if (passes(status, strict, attempt))
|
|
19
|
+
return { url, status, ok: true };
|
|
20
|
+
if (attempt >= tries)
|
|
21
|
+
return { url, status, ok: false };
|
|
22
|
+
await fx.pause(apart);
|
|
23
|
+
return probeUntil(fx, url, strict, attempt + 1);
|
|
24
|
+
};
|
|
25
|
+
/** Each route asked through Traefik, once per URL; a URL some route gave a check path for is held to it. */
|
|
26
|
+
const readiness = async (routes, domain, fx) => {
|
|
27
|
+
const urls = [...new Set(routes.map((route) => readinessUrl(route, domain)))];
|
|
28
|
+
const strict = (url) => routes.some((route) => route.check !== undefined && readinessUrl(route, domain) === url);
|
|
29
|
+
if (urls.length > 0)
|
|
30
|
+
fx.log(`── Ready? ${urls.join(", ")}`);
|
|
31
|
+
const checks = await Promise.all(urls.map((url) => probeUntil(fx, url, strict(url))));
|
|
32
|
+
checks.forEach((check) => {
|
|
33
|
+
fx.log(`${check.ok ? "ready" : "NOT READY"} ${check.url} ${check.status === 0 ? "no answer" : String(check.status)}`);
|
|
34
|
+
});
|
|
35
|
+
return Object.freeze(checks);
|
|
36
|
+
};
|
|
37
|
+
/** Where the app answers: each routed host once. */
|
|
38
|
+
const appUrls = (routes, domain) => Object.freeze([...new Set(routes.map((route) => `https://${route.host}.${domain}/`))]);
|
|
39
|
+
const notReady = (checks) => checks
|
|
40
|
+
.filter((check) => !check.ok)
|
|
41
|
+
.map((check) => `${check.url} ${check.status === 0 ? "did not answer" : `answered ${String(check.status)}`}`)
|
|
42
|
+
.join("; ");
|
|
5
43
|
const step = async (fx, label, argv, options) => {
|
|
6
44
|
fx.log(`── ${label}`);
|
|
7
45
|
const exit = await fx.exec(argv, options);
|
|
@@ -9,21 +47,27 @@ const step = async (fx, label, argv, options) => {
|
|
|
9
47
|
};
|
|
10
48
|
/**
|
|
11
49
|
* Admission, then up: the compose config of the commit being deployed must
|
|
12
|
-
* pass the policy before anything starts, and what it checked is what runs
|
|
50
|
+
* pass the policy before anything starts, and what it checked is what runs,
|
|
51
|
+
* with the routes the platform writes from it.
|
|
13
52
|
*/
|
|
14
|
-
const deployBundle = async (app, bundle,
|
|
53
|
+
const deployBundle = async (app, bundle, site, fx) => {
|
|
15
54
|
const images = imagesEnv(bundle);
|
|
16
55
|
const secrets = fx.secrets(app);
|
|
17
56
|
if (!secrets.ok)
|
|
18
57
|
return secrets;
|
|
19
58
|
const cwd = await fx.workdir(bundle, images);
|
|
20
|
-
const resolved = await step(fx, "Admission: compose config", config(app,
|
|
59
|
+
const resolved = await step(fx, "Admission: compose config", config(app, site.appsDir, bundle), { cwd, env: secrets.value, capture: true });
|
|
21
60
|
if (!resolved.ok)
|
|
22
61
|
return resolved;
|
|
23
|
-
const admitted = await step(fx, "Admission: policy", policy(app,
|
|
62
|
+
const admitted = await step(fx, "Admission: policy", policy(app, site.policyScript, site.domain, bundle), { cwd, env: {}, stdin: resolved.value });
|
|
24
63
|
if (!admitted.ok)
|
|
25
64
|
return err("refused by the compose policy");
|
|
26
|
-
const
|
|
65
|
+
const routes = routesOverride(app.name, site.domain, bundle.routes, resolved.value);
|
|
66
|
+
if (!routes.ok)
|
|
67
|
+
return routes;
|
|
68
|
+
fx.log(`── Routes: ${describeRoutes(bundle.routes)}`);
|
|
69
|
+
await fx.writeRoutes(cwd, routes.value);
|
|
70
|
+
const started = await step(fx, "Up", up(app, site.appsDir, bundle), { cwd, env: secrets.value });
|
|
27
71
|
if (!started.ok)
|
|
28
72
|
return started;
|
|
29
73
|
await fx.record(app, bundle.sha, images);
|
|
@@ -34,12 +78,12 @@ const deployBundle = async (app, bundle, paths, fx) => {
|
|
|
34
78
|
* then admitted and started (kayra/deploy). Each phase posts its status on the
|
|
35
79
|
* commit; a failed build never reaches deploy.
|
|
36
80
|
*/
|
|
37
|
-
export const deploy = async (app, ref,
|
|
81
|
+
export const deploy = async (app, ref, site, fx) => {
|
|
38
82
|
fx.log(`Deploying ${app.name} at ${ref}`);
|
|
39
83
|
const commit = await fx.resolve(app, ref);
|
|
40
84
|
if (!commit.ok) {
|
|
41
85
|
fx.log(commit.error);
|
|
42
|
-
return typed({ ok: false });
|
|
86
|
+
return typed({ ok: false, error: commit.error });
|
|
43
87
|
}
|
|
44
88
|
const sha = commit.value;
|
|
45
89
|
fx.log(`── ${ref} is ${sha}`);
|
|
@@ -49,19 +93,28 @@ export const deploy = async (app, ref, paths, fx) => {
|
|
|
49
93
|
if (!bundle.ok) {
|
|
50
94
|
fx.log(bundle.error);
|
|
51
95
|
await fx.status(app, sha, "kayra/build", "failure", "Build failed");
|
|
52
|
-
return typed({ ok: false, sha });
|
|
96
|
+
return typed({ ok: false, sha, error: `build: ${bundle.error}` });
|
|
53
97
|
}
|
|
54
98
|
await fx.status(app, sha, "kayra/build", "success", "Images built");
|
|
55
99
|
await fx.status(app, sha, "kayra/deploy", "pending", "Deploying");
|
|
56
|
-
const deployed = await deployBundle(app, bundle.value,
|
|
100
|
+
const deployed = await deployBundle(app, bundle.value, site, fx);
|
|
57
101
|
if (!deployed.ok) {
|
|
58
102
|
fx.log(deployed.error);
|
|
59
103
|
await fx.status(app, sha, "kayra/deploy", "failure", deployed.error);
|
|
60
|
-
return typed({ ok: false, sha });
|
|
104
|
+
return typed({ ok: false, sha, error: deployed.error });
|
|
105
|
+
}
|
|
106
|
+
const urls = appUrls(bundle.value.routes, site.domain);
|
|
107
|
+
const checks = await readiness(bundle.value.routes, site.domain, fx);
|
|
108
|
+
const unready = notReady(checks);
|
|
109
|
+
if (unready !== "") {
|
|
110
|
+
const error = `running, but not ready: ${unready}`;
|
|
111
|
+
fx.log(error);
|
|
112
|
+
await fx.status(app, sha, "kayra/deploy", "failure", "Not ready");
|
|
113
|
+
return typed({ ok: false, sha, error, urls, checks });
|
|
61
114
|
}
|
|
62
115
|
fx.log(`Deployed ${sha}`);
|
|
63
116
|
await fx.status(app, sha, "kayra/deploy", "success", "Deployed");
|
|
64
|
-
return typed({ ok: true, sha });
|
|
117
|
+
return typed({ ok: true, sha, urls, checks });
|
|
65
118
|
};
|
|
66
119
|
/** Renovate's settings, as the platform's .env holds them; the optional ones only when set. */
|
|
67
120
|
export const renovate = (env, dryRun, image) => {
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { existsSync, readdirSync, readFileSync } from "node:fs";
|
|
1
|
+
import { appendFileSync, existsSync, mkdirSync, readdirSync, readFileSync, rmSync, writeFileSync } from "node:fs";
|
|
2
2
|
import { join } from "node:path";
|
|
3
3
|
import { owner as mintOwner, runId } from "../brand.js";
|
|
4
|
-
import { parseMeta } from "./records.js";
|
|
4
|
+
import { expired, parseMeta } from "./records.js";
|
|
5
5
|
import { typed } from "../../lib/typed.js";
|
|
6
|
-
/**
|
|
6
|
+
/** runs/: <owner>/<id>/{meta.json,log}. Only the deployer writes there; the builder's pages and ctl read it. */
|
|
7
7
|
const entries = (dir) => (existsSync(dir) ? readdirSync(dir).toSorted() : typed([]));
|
|
8
8
|
export const owners = (runs) => Object.freeze(entries(runs).flatMap((name) => {
|
|
9
9
|
const minted = mintOwner(name);
|
|
@@ -30,3 +30,19 @@ export const log = (runs, who, id) => {
|
|
|
30
30
|
const path = join(runs, who, id, "log");
|
|
31
31
|
return existsSync(path) ? readFileSync(path, "utf8") : undefined;
|
|
32
32
|
};
|
|
33
|
+
/** A run's meta.json, as it begins and again as it ends. */
|
|
34
|
+
export const writeMeta = (runs, who, run) => {
|
|
35
|
+
const dir = join(runs, who, run.id);
|
|
36
|
+
mkdirSync(dir, { recursive: true });
|
|
37
|
+
writeFileSync(join(dir, "meta.json"), JSON.stringify(run));
|
|
38
|
+
};
|
|
39
|
+
/** A line of a run's log, stamped with the time of day. */
|
|
40
|
+
export const appendLog = (runs, who, id, line) => {
|
|
41
|
+
appendFileSync(join(runs, who, id, "log"), `${new Date().toISOString().slice(11, 19)} ${line}\n`);
|
|
42
|
+
};
|
|
43
|
+
/** An owner's runs beyond the newest `keep`, gone. */
|
|
44
|
+
export const prune = (runs, who, keep) => {
|
|
45
|
+
expired(readdirSync(join(runs, who)), keep).forEach((old) => {
|
|
46
|
+
rmSync(join(runs, who, old), { recursive: true, force: true });
|
|
47
|
+
});
|
|
48
|
+
};
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from "node:fs";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
import { err, ok } from "../lib/result.js";
|
|
4
|
+
import { parseCron } from "./cron.js";
|
|
5
|
+
import { githubIssues } from "./forges/issues.js";
|
|
6
|
+
import { parseNotify, silent } from "./forges/notify.js";
|
|
7
|
+
import { typed } from "../lib/typed.js";
|
|
8
|
+
/** Mounted into the deployer only: the platform's tokens, each app's secrets, the notifier's key. */
|
|
9
|
+
export const mounts = { platform: "/run/platform-secrets", apps: "/run/app-secrets", deployer: "/run/deployer-secrets" };
|
|
10
|
+
/** A platform token, read on every use: a new one needs no restart. */
|
|
11
|
+
export const token = (name) => {
|
|
12
|
+
const path = join(mounts.platform, name);
|
|
13
|
+
return existsSync(path) ? readFileSync(path, "utf8").trim() : "";
|
|
14
|
+
};
|
|
15
|
+
const must = (result) => {
|
|
16
|
+
if (!result.ok)
|
|
17
|
+
throw new Error(result.error);
|
|
18
|
+
return result.value;
|
|
19
|
+
};
|
|
20
|
+
/** The configured notifier; its open alerts are kept in <platformDir>/alerts/<key>. */
|
|
21
|
+
const notifierFor = (config, platformDir) => {
|
|
22
|
+
if (config.kind === "none")
|
|
23
|
+
return silent;
|
|
24
|
+
const alerts = join(platformDir, "alerts");
|
|
25
|
+
const keyFile = join(mounts.deployer, "NOTIFIER_GITHUB_APP_KEY");
|
|
26
|
+
return githubIssues(config.repository, config.appId, {
|
|
27
|
+
fetch: async (url, init) => {
|
|
28
|
+
const response = await fetch(url, init);
|
|
29
|
+
const json = await response.json().catch(() => undefined);
|
|
30
|
+
return Object.freeze({ status: response.status, json });
|
|
31
|
+
},
|
|
32
|
+
privateKey: () => (existsSync(keyFile) ? ok(readFileSync(keyFile, "utf8")) : err(`${keyFile} is missing: notifier_github_app_key in secrets.yml`)),
|
|
33
|
+
now: () => Date.now(),
|
|
34
|
+
openIssue: (key) => {
|
|
35
|
+
const path = join(alerts, key);
|
|
36
|
+
const number = existsSync(path) ? Number(readFileSync(path, "utf8")) : Number.NaN;
|
|
37
|
+
return Number.isInteger(number) ? number : undefined;
|
|
38
|
+
},
|
|
39
|
+
remember: (key, issue) => {
|
|
40
|
+
mkdirSync(alerts, { recursive: true });
|
|
41
|
+
if (issue === undefined)
|
|
42
|
+
rmSync(join(alerts, key), { force: true });
|
|
43
|
+
else
|
|
44
|
+
writeFileSync(join(alerts, key), String(issue));
|
|
45
|
+
},
|
|
46
|
+
});
|
|
47
|
+
};
|
|
48
|
+
export const settings = (env) => {
|
|
49
|
+
const scripts = env["PLATFORM_SCRIPTS"] ?? "/opt/kayra/scripts/platform";
|
|
50
|
+
const platformDir = env["PLATFORM_DIR"] ?? "/opt/platform";
|
|
51
|
+
const strings = Object.fromEntries(Object.entries(env).flatMap(([key, value]) => typed(value === undefined ? [] : [[key, value]])));
|
|
52
|
+
return typed({
|
|
53
|
+
platformDir,
|
|
54
|
+
appsDir: env["APPS_DIR"] ?? "/opt/apps",
|
|
55
|
+
builder: env["BUILDER_URL"] ?? "http://builder:8081",
|
|
56
|
+
domain: env["DOMAIN"] ?? "localhost",
|
|
57
|
+
policyScript: join(scripts, "compose-policy.sh"),
|
|
58
|
+
gcScript: join(scripts, "registry-gc.sh"),
|
|
59
|
+
renovateImage: env["RENOVATE_IMAGE"] ?? "",
|
|
60
|
+
renovate: env["PLATFORM_RENOVATE"] === "true" ? must(parseCron(env["RENOVATE_SCHEDULE"] ?? "0 4 * * 1")) : undefined,
|
|
61
|
+
gc: must(parseCron("0 3 * * *")),
|
|
62
|
+
poll: must(parseCron(env["DEPLOY_POLL"] ?? "17 * * * *")),
|
|
63
|
+
env: strings,
|
|
64
|
+
server: env["SERVER"] ?? env["DOMAIN"] ?? "this server",
|
|
65
|
+
notifier: notifierFor(must(parseNotify(env["NOTIFIER"])), platformDir),
|
|
66
|
+
});
|
|
67
|
+
};
|
|
68
|
+
/** Where runs/ is: <owner>/<id>/{meta.json,log}. */
|
|
69
|
+
export const runsDir = (s) => join(s.platformDir, "runs");
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { typed } from "./typed.js";
|
|
2
|
+
const kinds = { "https://github.com": "github", "https://gitlab.com": "gitlab" };
|
|
3
|
+
/**
|
|
4
|
+
* GitHub for https://github.com, GitLab for https://gitlab.com, a Forgejo for any other host; undefined for a URL none understands.
|
|
5
|
+
* The deployer (statuses, webhook signatures) and kayra (setting up those webhooks) read a repository the same way.
|
|
6
|
+
*/
|
|
7
|
+
export const forgeRepo = (repo) => {
|
|
8
|
+
const match = /^(https?:\/\/[^/]+)\/(.+)\/([^/]+?)(\.git)?\/?$/.exec(repo);
|
|
9
|
+
if (match === null)
|
|
10
|
+
return undefined;
|
|
11
|
+
const [, origin, owner, name] = match;
|
|
12
|
+
if (origin === undefined || owner === undefined || name === undefined)
|
|
13
|
+
return undefined;
|
|
14
|
+
return typed({ kind: kinds[origin] ?? "forgejo", origin, owner, name });
|
|
15
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The rules names follow on both sides: the fleet's schemas (core/fleet/brand.ts)
|
|
3
|
+
* and the deployer's constructors (deployer/brand.ts), which may not import zod.
|
|
4
|
+
*/
|
|
5
|
+
export const names = {
|
|
6
|
+
app: { pattern: /^[a-z][a-z0-9-]*$/, what: "an app name (lowercase letters, digits, dashes)" },
|
|
7
|
+
subdomain: { pattern: /^[a-z0-9]([a-z0-9-]*[a-z0-9])?$/, what: "a subdomain" },
|
|
8
|
+
/** A route's path prefix: no backtick, quote or `$`, so it cannot leave its Traefik rule or meet Compose's interpolation. */
|
|
9
|
+
routePath: { pattern: /^\/[A-Za-z0-9._~%/-]*$/, what: "a path (/, then letters, digits and ._~%/-)" },
|
|
10
|
+
serviceName: { pattern: /^[a-zA-Z0-9][a-zA-Z0-9_.-]*$/, what: "a compose service name" },
|
|
11
|
+
/** A Traefik duration. */
|
|
12
|
+
period: { pattern: /^[1-9][0-9]*(ms|s|m|h)$/, what: "a period such as 10s, 10m or 1h" },
|
|
13
|
+
};
|
package/cli/dist/main.js
CHANGED
|
@@ -82,7 +82,7 @@ const execute = async (steps, about, framing) => {
|
|
|
82
82
|
process.exitCode = interrupt.signal.aborted ? 130 : passed ? 0 : 1;
|
|
83
83
|
};
|
|
84
84
|
const found = flatMap(findFleetRoot(here.value), loadFleet);
|
|
85
|
-
// Outside a fleet only what works in an app's repository runs (app check).
|
|
85
|
+
// Outside a fleet only what works in an app's repository runs (app init, app check).
|
|
86
86
|
const fleet = found.ok ? found.value : { root: fleetRoot(here.value), servers: [] };
|
|
87
87
|
const args = run(parser(fleet), runOptions(version));
|
|
88
88
|
const short = shortener([
|
|
@@ -138,30 +138,51 @@ else {
|
|
|
138
138
|
else
|
|
139
139
|
await execute(steps.value, invocation(target), operation.bare !== true);
|
|
140
140
|
}
|
|
141
|
-
else if (call.name === "status") {
|
|
142
|
-
const { offline } = call.input;
|
|
143
|
-
const { initial, updates } = stream(context, "status", call.input);
|
|
144
|
-
// On a terminal the table is there at once, its cells filled in as the answers arrive; the report itself goes to stdout.
|
|
145
|
-
const draw = (looks, frame) => Object.freeze(statusView(looks, { frame, room: screens.err.columns - 1, offline }).map((line) => paint(truncate(line, screens.err.columns - 1), screens.err.colors)));
|
|
146
|
-
const looks = !json && screens.out.live && screens.err.live
|
|
147
|
-
? await watch((raw) => process.stderr.write(raw), initial, updates, draw)
|
|
148
|
-
: await settle(initial, updates);
|
|
149
|
-
(json
|
|
150
|
-
? [JSON.stringify(statusJson(looks), null, 2)]
|
|
151
|
-
: statusView(looks, { frame: "", room: screens.out.live ? screens.out.columns : Infinity, offline })).forEach(io.out);
|
|
152
|
-
}
|
|
153
|
-
else if (call.name === "validate") {
|
|
154
|
-
const reports = await query(context, "validate", call.input);
|
|
155
|
-
if (!reports.ok)
|
|
156
|
-
fail(reports.error);
|
|
157
|
-
else {
|
|
158
|
-
(json ? [JSON.stringify(validateJson(reports.value), null, 2)] : validateView(reports.value)).forEach(io.out);
|
|
159
|
-
// eslint-disable-next-line functional/immutable-data -- the exit status; process.exit() could cut piped output short
|
|
160
|
-
process.exitCode = reports.value.some((each) => overall(each.findings) === "problem") ? 1 : 0;
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
141
|
else {
|
|
164
|
-
|
|
165
|
-
|
|
142
|
+
switch (call.name) {
|
|
143
|
+
case "status": {
|
|
144
|
+
const { offline } = call.input;
|
|
145
|
+
const { initial, updates } = stream(context, "status", call.input);
|
|
146
|
+
// On a terminal the table is there at once, its cells filled in as the answers arrive; the report itself goes to stdout.
|
|
147
|
+
const draw = (looks, frame) => Object.freeze(statusView(looks, { frame, room: screens.err.columns - 1, offline }).map((line) => paint(truncate(line, screens.err.columns - 1), screens.err.colors)));
|
|
148
|
+
const looks = !json && screens.out.live && screens.err.live
|
|
149
|
+
? await watch((raw) => process.stderr.write(raw), initial, updates, draw)
|
|
150
|
+
: await settle(initial, updates);
|
|
151
|
+
(json
|
|
152
|
+
? [JSON.stringify(statusJson(looks), null, 2)]
|
|
153
|
+
: statusView(looks, { frame: "", room: screens.out.live ? screens.out.columns : Infinity, offline })).forEach(io.out);
|
|
154
|
+
break;
|
|
155
|
+
}
|
|
156
|
+
case "app.values": {
|
|
157
|
+
const values = await query(context, "app.values", call.input);
|
|
158
|
+
if (!values.ok)
|
|
159
|
+
fail(values.error);
|
|
160
|
+
else if (json)
|
|
161
|
+
io.out(JSON.stringify(values.value, null, 2));
|
|
162
|
+
else {
|
|
163
|
+
io.out(`${values.value.app} on ${values.value.server} · cached contract: ${values.value.manifest}`);
|
|
164
|
+
values.value.config.forEach((each) => { io.out(`config ${each.key}: ${each.state}`); });
|
|
165
|
+
values.value.secrets.forEach((each) => { io.out(`secret ${each.key}: ${each.state}`); });
|
|
166
|
+
if (values.value.hint !== null)
|
|
167
|
+
io.out(values.value.hint);
|
|
168
|
+
}
|
|
169
|
+
break;
|
|
170
|
+
}
|
|
171
|
+
case "validate": {
|
|
172
|
+
const reports = await query(context, "validate", call.input);
|
|
173
|
+
if (!reports.ok)
|
|
174
|
+
fail(reports.error);
|
|
175
|
+
else {
|
|
176
|
+
(json ? [JSON.stringify(validateJson(reports.value), null, 2)] : validateView(reports.value)).forEach(io.out);
|
|
177
|
+
// eslint-disable-next-line functional/immutable-data -- the exit status; process.exit() could cut piped output short
|
|
178
|
+
process.exitCode = reports.value.some((each) => overall(each.findings) === "problem") ? 1 : 0;
|
|
179
|
+
}
|
|
180
|
+
break;
|
|
181
|
+
}
|
|
182
|
+
case "version":
|
|
183
|
+
// Optique answers `kayra version` and `--version` itself, before this.
|
|
184
|
+
io.out(version);
|
|
185
|
+
break;
|
|
186
|
+
}
|
|
166
187
|
}
|
|
167
188
|
}
|
|
@@ -66,6 +66,7 @@ services:
|
|
|
66
66
|
command: ["builder"]
|
|
67
67
|
environment:
|
|
68
68
|
- WEBHOOK_SECRET=${WEBHOOK_SECRET:-}
|
|
69
|
+
- WEBHOOKS=${WEBHOOKS:-true}
|
|
69
70
|
- BUILDKIT_HOST=tcp://buildkitd:1234
|
|
70
71
|
- REGISTRY_PUSH_HOST=registry:5000
|
|
71
72
|
volumes:
|
|
@@ -122,6 +123,7 @@ services:
|
|
|
122
123
|
- PLATFORM_DIR=/opt/platform
|
|
123
124
|
- PLATFORM_RENOVATE=${PLATFORM_RENOVATE:-false}
|
|
124
125
|
- RENOVATE_SCHEDULE=${RENOVATE_SCHEDULE:-0 4 * * 1}
|
|
126
|
+
- DEPLOY_POLL=${DEPLOY_POLL:-17 * * * *}
|
|
125
127
|
- RENOVATE_PLATFORM=${RENOVATE_PLATFORM:-github}
|
|
126
128
|
- RENOVATE_ENDPOINT=${RENOVATE_ENDPOINT:-}
|
|
127
129
|
- RENOVATE_GIT_URL=${RENOVATE_GIT_URL:-}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@yunuseon/kayra",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.20.0",
|
|
4
4
|
"description": "A self-hosted app platform and the CLI that runs it: Traefik, Authelia, a registry, rootless BuildKit and a small deployer per server, set up with OpenTofu and Ansible.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Yunus Öztürk",
|
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
"build:web": "npm --prefix web ci --silent && npm --prefix web run build -- --outDir ../cli/dist/browser --emptyOutDir",
|
|
38
38
|
"prepack": "npm run build && npm run build:web",
|
|
39
39
|
"typecheck": "tsc -p cli --noEmit",
|
|
40
|
-
"lint": "cd cli && eslint --flag unstable_native_nodejs_ts_config .",
|
|
40
|
+
"lint": "cd cli && NODE_ENV=test eslint --flag unstable_native_nodejs_ts_config .",
|
|
41
41
|
"test": "node --test 'cli/test/**/*.test.ts'",
|
|
42
42
|
"schemas": "node cli/scripts/schemas.ts",
|
|
43
43
|
"contract": "node cli/scripts/contract.ts",
|
package/schema/app.json
CHANGED
|
@@ -12,15 +12,77 @@
|
|
|
12
12
|
"items": {
|
|
13
13
|
"type": "string"
|
|
14
14
|
},
|
|
15
|
-
"description": "Compose files, relative to the app root, in order."
|
|
15
|
+
"description": "Compose files, relative to the app root, in order. No Traefik label, no platform network: routes say how the app is reached."
|
|
16
16
|
},
|
|
17
|
-
"
|
|
17
|
+
"routes": {
|
|
18
|
+
"description": "How the app is reached: each route a host (and path) to a service's port. Read at the commit being deployed; a new host needs kayra apps.",
|
|
18
19
|
"type": "array",
|
|
19
20
|
"items": {
|
|
20
|
-
"type": "
|
|
21
|
-
"
|
|
22
|
-
|
|
23
|
-
|
|
21
|
+
"type": "object",
|
|
22
|
+
"properties": {
|
|
23
|
+
"host": {
|
|
24
|
+
"description": "Its hostname, <host>.<domain>. The app's hosts are its routes' hosts.",
|
|
25
|
+
"type": "string",
|
|
26
|
+
"pattern": "^[a-z0-9]([a-z0-9-]*[a-z0-9])?$"
|
|
27
|
+
},
|
|
28
|
+
"path": {
|
|
29
|
+
"description": "A path prefix: the route answers below it, and beats its host's route without one.",
|
|
30
|
+
"type": "string",
|
|
31
|
+
"pattern": "^\\/[A-Za-z0-9._~%/-]*$"
|
|
32
|
+
},
|
|
33
|
+
"service": {
|
|
34
|
+
"description": "The compose service that answers it.",
|
|
35
|
+
"type": "string",
|
|
36
|
+
"pattern": "^[a-zA-Z0-9][a-zA-Z0-9_.-]*$"
|
|
37
|
+
},
|
|
38
|
+
"port": {
|
|
39
|
+
"type": "integer",
|
|
40
|
+
"minimum": 1,
|
|
41
|
+
"maximum": 65535,
|
|
42
|
+
"description": "The port that service listens on, inside its container."
|
|
43
|
+
},
|
|
44
|
+
"rate_limit": {
|
|
45
|
+
"description": "A rate limit on this route, per client address (Traefik's rateLimit).",
|
|
46
|
+
"type": "object",
|
|
47
|
+
"properties": {
|
|
48
|
+
"average": {
|
|
49
|
+
"type": "integer",
|
|
50
|
+
"exclusiveMinimum": 0,
|
|
51
|
+
"maximum": 9007199254740991,
|
|
52
|
+
"description": "Requests a client may send per period, on average."
|
|
53
|
+
},
|
|
54
|
+
"period": {
|
|
55
|
+
"description": "The period, such as 10s, 10m or 1h.",
|
|
56
|
+
"type": "string",
|
|
57
|
+
"pattern": "^[1-9][0-9]*(ms|s|m|h)$"
|
|
58
|
+
},
|
|
59
|
+
"burst": {
|
|
60
|
+
"type": "integer",
|
|
61
|
+
"exclusiveMinimum": 0,
|
|
62
|
+
"maximum": 9007199254740991,
|
|
63
|
+
"description": "Requests a client may send at once beyond the average."
|
|
64
|
+
}
|
|
65
|
+
},
|
|
66
|
+
"required": [
|
|
67
|
+
"average",
|
|
68
|
+
"period",
|
|
69
|
+
"burst"
|
|
70
|
+
],
|
|
71
|
+
"additionalProperties": false
|
|
72
|
+
},
|
|
73
|
+
"check": {
|
|
74
|
+
"description": "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.",
|
|
75
|
+
"type": "string",
|
|
76
|
+
"pattern": "^\\/[A-Za-z0-9._~%/-]*$"
|
|
77
|
+
}
|
|
78
|
+
},
|
|
79
|
+
"required": [
|
|
80
|
+
"host",
|
|
81
|
+
"service",
|
|
82
|
+
"port"
|
|
83
|
+
],
|
|
84
|
+
"additionalProperties": false
|
|
85
|
+
}
|
|
24
86
|
},
|
|
25
87
|
"secrets": {
|
|
26
88
|
"description": "Secret keys; their values come from the fleet's apps/<app>.secrets.yml.",
|
|
@@ -39,8 +101,7 @@
|
|
|
39
101
|
},
|
|
40
102
|
"required": [
|
|
41
103
|
"name",
|
|
42
|
-
"compose"
|
|
43
|
-
"subdomains"
|
|
104
|
+
"compose"
|
|
44
105
|
],
|
|
45
106
|
"additionalProperties": false,
|
|
46
107
|
"title": "app.yml"
|
package/schema/defaults.json
CHANGED
|
@@ -38,6 +38,14 @@
|
|
|
38
38
|
],
|
|
39
39
|
"description": "Certificates by DNS-01 instead of HTTP-01, for a server the internet never reaches: the DNS provider (hetzner)."
|
|
40
40
|
},
|
|
41
|
+
"webhooks": {
|
|
42
|
+
"type": "boolean",
|
|
43
|
+
"description": "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."
|
|
44
|
+
},
|
|
45
|
+
"deploy_poll": {
|
|
46
|
+
"type": "string",
|
|
47
|
+
"description": "When the deployer looks for pushes no webhook brought, as a five-field cron spec in the server's time (default hourly: 17 * * * *)."
|
|
48
|
+
},
|
|
41
49
|
"renovate_repositories": {
|
|
42
50
|
"type": "array",
|
|
43
51
|
"items": {
|
|
@@ -38,6 +38,14 @@
|
|
|
38
38
|
],
|
|
39
39
|
"description": "Certificates by DNS-01 instead of HTTP-01, for a server the internet never reaches: the DNS provider (hetzner)."
|
|
40
40
|
},
|
|
41
|
+
"webhooks": {
|
|
42
|
+
"type": "boolean",
|
|
43
|
+
"description": "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."
|
|
44
|
+
},
|
|
45
|
+
"deploy_poll": {
|
|
46
|
+
"type": "string",
|
|
47
|
+
"description": "When the deployer looks for pushes no webhook brought, as a five-field cron spec in the server's time (default hourly: 17 * * * *)."
|
|
48
|
+
},
|
|
41
49
|
"renovate_repositories": {
|
|
42
50
|
"type": "array",
|
|
43
51
|
"items": {
|
|
@@ -4,13 +4,14 @@
|
|
|
4
4
|
# checked in the app's own repository, before a push: run by `kayra app
|
|
5
5
|
# check`, which has checked app.yml against its schema first.
|
|
6
6
|
#
|
|
7
|
-
# - app.yml's compose files exist, inside the app; its
|
|
8
|
-
# the platform's (hosts.conf)
|
|
7
|
+
# - app.yml's compose files exist, inside the app; its routes' hosts are
|
|
8
|
+
# not the platform's (hosts.conf)
|
|
9
9
|
# - every docker/image.json: its image in the app's namespace, a commit
|
|
10
10
|
# touching its inputs (resolve-images.sh --plan, as the builder runs it)
|
|
11
11
|
# - the compose config those files resolve to passes the compose policy
|
|
12
|
-
# (compose-policy.sh, as the deployer runs it
|
|
13
|
-
#
|
|
12
|
+
# (compose-policy.sh, as the deployer runs it: no Traefik label, no
|
|
13
|
+
# platform network, each route to one of its services), with placeholder
|
|
14
|
+
# values for the images, config and secrets, and hosts under example.test
|
|
14
15
|
#
|
|
15
16
|
# Needs git, jq, yq and the docker CLI with Compose (no daemon: `compose
|
|
16
17
|
# config` only reads files). Written for macOS's bash 3.2 too: no mapfile.
|
|
@@ -28,7 +29,8 @@ pass() { echo "✓ $*"; }
|
|
|
28
29
|
|
|
29
30
|
name="$(yq -r '.name' "$manifest")"
|
|
30
31
|
files="$(yq -r '.compose[]' "$manifest")"
|
|
31
|
-
|
|
32
|
+
routes="$(yq -o=json -I0 '.routes // []' "$manifest")"
|
|
33
|
+
subdomains="$(yq -r '.routes // [] | map(.host) | unique | .[]' "$manifest")"
|
|
32
34
|
reserved="$(awk '!/^[[:space:]]*(#|$)/ {print $1}' "${KAYRA_ROOT}/hosts.conf")"
|
|
33
35
|
|
|
34
36
|
# ── app.yml ─────────────────────────────────────────────────────────────────
|
|
@@ -39,9 +41,10 @@ while IFS= read -r file; do
|
|
|
39
41
|
esac
|
|
40
42
|
done <<< "$files"
|
|
41
43
|
while IFS= read -r sub; do
|
|
42
|
-
if grep -qxF -- "$sub" <<< "$reserved"; then fail "
|
|
44
|
+
if [ -n "$sub" ] && grep -qxF -- "$sub" <<< "$reserved"; then fail "route host ${sub} is the platform's"; fi
|
|
43
45
|
done <<< "$subdomains"
|
|
44
|
-
|
|
46
|
+
described="$(yq -r '.routes // [] | map(.host + (.path // "") + " → " + .service + ":" + (.port | tostring)) | join(", ")' "$manifest")"
|
|
47
|
+
[ "$failed" = 0 ] && pass "app.yml: compose $(paste -sd' ' - <<< "$files") · routes ${described:-none}"
|
|
45
48
|
|
|
46
49
|
# ── Images ──────────────────────────────────────────────────────────────────
|
|
47
50
|
if plan="$(bash "${KAYRA_ROOT}/scripts/platform/resolve-images.sh" "$name" "$root" --plan)"; then
|
|
@@ -71,8 +74,8 @@ while IFS= read -r file; do set -- "$@" -f "${root}/${file}"; done <<< "$files"
|
|
|
71
74
|
|| { fail "compose: docker compose config failed (above)"; exit 1; }
|
|
72
75
|
|
|
73
76
|
set --
|
|
74
|
-
while IFS= read -r sub; do set -- "$@" "${sub}.${domain}"; done <<< "$subdomains"
|
|
75
|
-
if violations="$(bash "${KAYRA_ROOT}/scripts/platform/compose-policy.sh" "$name" "$@" < "${work}/config.json")"; then
|
|
77
|
+
while IFS= read -r sub; do [ -z "$sub" ] || set -- "$@" "${sub}.${domain}"; done <<< "$subdomains"
|
|
78
|
+
if violations="$(bash "${KAYRA_ROOT}/scripts/platform/compose-policy.sh" "$name" "$domain" "$routes" "$@" < "${work}/config.json")"; then
|
|
76
79
|
pass "compose policy: admitted"
|
|
77
80
|
else
|
|
78
81
|
while IFS= read -r line; do fail "compose policy: ${line}"; done <<< "$violations"
|
|
@@ -4,14 +4,15 @@
|
|
|
4
4
|
# app role reads). A missing clone is
|
|
5
5
|
# fetched with the operator's own git credentials (kayra doctor checks them).
|
|
6
6
|
#
|
|
7
|
-
# Usage: FLEET_ROOT=<fleet> bash scripts/local/app-manifests.sh [--subdomains] <server-name>
|
|
8
|
-
# --subdomains print the apps'
|
|
7
|
+
# Usage: FLEET_ROOT=<fleet> bash scripts/local/app-manifests.sh [--subdomains|--routes] <server-name>
|
|
8
|
+
# --subdomains print the apps' hosts instead, their routes' (for certs and /etc/hosts)
|
|
9
|
+
# --routes print each route as "<subdomain> <path>", / where it has none (for verify)
|
|
9
10
|
set -euo pipefail
|
|
10
11
|
|
|
11
12
|
FLEET_ROOT="${FLEET_ROOT:?the directory of the fleet (servers/), set by kayra}"
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
name="${1:?Usage: app-manifests.sh [--subdomains] <server-name>}"
|
|
13
|
+
mode=manifests
|
|
14
|
+
case "${1:-}" in --subdomains) mode=subdomains; shift ;; --routes) mode=routes; shift ;; esac
|
|
15
|
+
name="${1:?Usage: app-manifests.sh [--subdomains|--routes] <server-name>}"
|
|
15
16
|
descriptor="${FLEET_ROOT}/servers/${name}/server.yml"
|
|
16
17
|
|
|
17
18
|
yq -o json -I0 '.apps // [] | .[]' "$descriptor" | while read -r app; do
|
|
@@ -22,5 +23,9 @@ yq -o json -I0 '.apps // [] | .[]' "$descriptor" | while read -r app; do
|
|
|
22
23
|
git clone -q --depth 1 --branch "$(jq -r '.ref // "main"' <<< "$app")" "$repo" "$clone"
|
|
23
24
|
fi
|
|
24
25
|
manifest="${clone}/${path}/app.yml"
|
|
25
|
-
|
|
26
|
+
case "$mode" in
|
|
27
|
+
subdomains) yq '.routes // [] | map(.host) | unique | .[]' "$manifest" ;;
|
|
28
|
+
routes) yq '.routes // [] | map(.host + " " + (.path // "/")) | unique | .[]' "$manifest" ;;
|
|
29
|
+
*) echo "$manifest" ;;
|
|
30
|
+
esac
|
|
26
31
|
done
|