@caelo-cms/provisioning 0.12.9 → 0.12.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/agent-db.js +76 -3
- package/dist/cli.js +23 -2
- package/dist/cli.js.map +1 -1
- package/dist/collection-stores.d.ts +5 -0
- package/dist/collection-stores.d.ts.map +1 -0
- package/dist/collection-stores.js +21 -0
- package/dist/collection-stores.js.map +1 -0
- package/dist/collections-setup.d.ts +66 -0
- package/dist/collections-setup.d.ts.map +1 -0
- package/dist/collections-setup.js +252 -0
- package/dist/collections-setup.js.map +1 -0
- package/dist/compose.d.ts +27 -0
- package/dist/compose.d.ts.map +1 -1
- package/dist/compose.js +52 -1
- package/dist/compose.js.map +1 -1
- package/dist/gateway-edge.d.ts +13 -0
- package/dist/gateway-edge.d.ts.map +1 -1
- package/dist/gateway-edge.js +22 -0
- package/dist/gateway-edge.js.map +1 -1
- package/dist/gcp-names.d.ts +18 -48
- package/dist/gcp-names.d.ts.map +1 -1
- package/dist/gcp-names.js +11 -69
- package/dist/gcp-names.js.map +1 -1
- package/dist/infra-contract.d.ts +1 -1
- package/dist/infra-contract.d.ts.map +1 -1
- package/dist/infra-contract.js +35 -1
- package/dist/infra-contract.js.map +1 -1
- package/dist/reporting-job-catalog.d.ts +111 -0
- package/dist/reporting-job-catalog.d.ts.map +1 -0
- package/dist/reporting-job-catalog.js +306 -0
- package/dist/reporting-job-catalog.js.map +1 -0
- package/dist/reporting-job-setup.d.ts +11 -68
- package/dist/reporting-job-setup.d.ts.map +1 -1
- package/dist/reporting-job-setup.js +44 -100
- package/dist/reporting-job-setup.js.map +1 -1
- package/dist/runtime-secrets.d.ts.map +1 -1
- package/dist/runtime-secrets.js +3 -0
- package/dist/runtime-secrets.js.map +1 -1
- package/dist/self-hosted-backup.d.ts.map +1 -1
- package/dist/self-hosted-backup.js +18 -6
- package/dist/self-hosted-backup.js.map +1 -1
- package/dist/stack-contract.d.ts +75 -22
- package/dist/stack-contract.d.ts.map +1 -1
- package/dist/stack-contract.js +142 -51
- package/dist/stack-contract.js.map +1 -1
- package/dist/stack-converge.d.ts +20 -1
- package/dist/stack-converge.d.ts.map +1 -1
- package/dist/stack-converge.js +105 -2
- package/dist/stack-converge.js.map +1 -1
- package/dist/staging-gateway-setup.d.ts.map +1 -1
- package/dist/staging-gateway-setup.js +10 -5
- package/dist/staging-gateway-setup.js.map +1 -1
- package/dist/upgrade/admin-image-jobs.d.ts +4 -3
- package/dist/upgrade/admin-image-jobs.d.ts.map +1 -1
- package/dist/upgrade/admin-image-jobs.js +9 -16
- package/dist/upgrade/admin-image-jobs.js.map +1 -1
- package/dist/upgrade/app-roll.d.ts.map +1 -1
- package/dist/upgrade/app-roll.js +8 -7
- package/dist/upgrade/app-roll.js.map +1 -1
- package/dist/upgrade/converge.d.ts.map +1 -1
- package/dist/upgrade/converge.js +78 -50
- package/dist/upgrade/converge.js.map +1 -1
- package/dist/upgrader-iam-preflight.d.ts.map +1 -1
- package/dist/upgrader-iam-preflight.js +8 -18
- package/dist/upgrader-iam-preflight.js.map +1 -1
- package/dist/upgrader-setup.d.ts.map +1 -1
- package/dist/upgrader-setup.js +7 -15
- package/dist/upgrader-setup.js.map +1 -1
- package/dist/visitor-query-logs.d.ts +40 -0
- package/dist/visitor-query-logs.d.ts.map +1 -0
- package/dist/visitor-query-logs.js +41 -0
- package/dist/visitor-query-logs.js.map +1 -0
- package/dist/wizards/gcp-cost.d.ts.map +1 -1
- package/dist/wizards/gcp-cost.js +17 -9
- package/dist/wizards/gcp-cost.js.map +1 -1
- package/dist/wizards/gcp.d.ts.map +1 -1
- package/dist/wizards/gcp.js +45 -35
- package/dist/wizards/gcp.js.map +1 -1
- package/package.json +2 -2
- package/src/admin-memory.test.ts +57 -1
- package/src/cli.ts +23 -1
- package/src/collection-stores.ts +28 -0
- package/src/collections-setup.test.ts +237 -0
- package/src/collections-setup.ts +317 -0
- package/src/compose.ts +54 -1
- package/src/gateway-edge.test.ts +28 -0
- package/src/gateway-edge.ts +24 -0
- package/src/gateway-env-isolation.test.ts +141 -3
- package/src/gcp-names.ts +28 -84
- package/src/infra-contract.test.ts +5 -3
- package/src/infra-contract.ts +35 -1
- package/src/remote-mcp.test.ts +13 -1
- package/src/reporting-job-catalog.test.ts +156 -0
- package/src/reporting-job-catalog.ts +426 -0
- package/src/reporting-job-setup.test.ts +119 -6
- package/src/reporting-job-setup.ts +51 -158
- package/src/runtime-secrets.test.ts +19 -4
- package/src/runtime-secrets.ts +3 -0
- package/src/self-hosted-backup.test.ts +2 -2
- package/src/self-hosted-backup.ts +18 -6
- package/src/self-hosted-compose.test.ts +9 -3
- package/src/stack-contract.test.ts +62 -4
- package/src/stack-contract.ts +172 -59
- package/src/stack-converge-secrets.test.ts +4 -0
- package/src/stack-converge.test.ts +81 -3
- package/src/stack-converge.ts +124 -3
- package/src/staging-gateway-setup.test.ts +4 -0
- package/src/staging-gateway-setup.ts +16 -6
- package/src/upgrade/admin-image-jobs.ts +13 -25
- package/src/upgrade/app-roll.ts +7 -6
- package/src/upgrade/converge.ts +94 -77
- package/src/upgrade/upgrade.test.ts +97 -2
- package/src/upgrader-iam-preflight.ts +7 -20
- package/src/upgrader-job.test.ts +3 -0
- package/src/upgrader-setup.test.ts +3 -0
- package/src/upgrader-setup.ts +6 -17
- package/src/visitor-query-logs.ts +46 -0
- package/src/wizards/gcp-cost.ts +19 -9
- package/src/wizards/gcp.ts +51 -45
- package/stacks/aws/index.ts +18 -9
- package/stacks/azure/index.ts +19 -8
- package/stacks/gcp/index.ts +54 -1
- package/stacks/gcp-firebase/index.ts +28 -1
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MPL-2.0
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* #1646 — one declaration per kind of reporting job (reporting-job-catalog.ts),
|
|
5
|
+
* and every place that sets up, moves or grants jobs follows it: a kind
|
|
6
|
+
* added to the catalog reaches the admin's env, the app-roll's image move,
|
|
7
|
+
* the upgrader's actAs and its IAM pre-flight without another edit.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import { describe, expect, it } from "bun:test";
|
|
11
|
+
import {
|
|
12
|
+
REPORTING_JOB_CATALOG,
|
|
13
|
+
reportingJobAdminEnv,
|
|
14
|
+
reportingJobEntry,
|
|
15
|
+
reportingJobName,
|
|
16
|
+
reportingJobServiceAccountEmail,
|
|
17
|
+
reportingJobServiceAccounts,
|
|
18
|
+
reportingJobSpec,
|
|
19
|
+
} from "./reporting-job-catalog.js";
|
|
20
|
+
import { adminEnvContract, databaseUrls } from "./stack-contract.js";
|
|
21
|
+
import { adminImageJobs } from "./upgrade/admin-image-jobs.js";
|
|
22
|
+
import { upgraderAccessChecks } from "./upgrader-iam-preflight.js";
|
|
23
|
+
import { upgraderAccountGrants } from "./upgrader-setup.js";
|
|
24
|
+
|
|
25
|
+
const PLACE = {
|
|
26
|
+
provider: "gcp",
|
|
27
|
+
projectId: "acme",
|
|
28
|
+
region: "europe-west1",
|
|
29
|
+
env: "production",
|
|
30
|
+
} as const;
|
|
31
|
+
|
|
32
|
+
describe("the reporting job catalog", () => {
|
|
33
|
+
it("names each kind, job, account and env var once", () => {
|
|
34
|
+
const unique = (xs: string[]) => expect(new Set(xs).size).toBe(xs.length);
|
|
35
|
+
unique(REPORTING_JOB_CATALOG.map((e) => e.kind));
|
|
36
|
+
unique(REPORTING_JOB_CATALOG.map((e) => e.name));
|
|
37
|
+
unique(REPORTING_JOB_CATALOG.flatMap((e) => [e.jobEnvVar, e.serviceAccountEnvVar]));
|
|
38
|
+
expect(REPORTING_JOB_CATALOG.map((e) => e.kind)).toEqual([
|
|
39
|
+
"quality_audit",
|
|
40
|
+
"site_import",
|
|
41
|
+
"build",
|
|
42
|
+
"collection_index",
|
|
43
|
+
"plugin_batch",
|
|
44
|
+
]);
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
it("keeps every account id within Google's 30 characters, for every stack env", () => {
|
|
48
|
+
for (const env of ["production", "staging", "development"]) {
|
|
49
|
+
for (const e of REPORTING_JOB_CATALOG) {
|
|
50
|
+
const id = reportingJobSpec(e, { ...PLACE, env }).serviceAccountId;
|
|
51
|
+
expect(id.length).toBeLessThanOrEqual(30);
|
|
52
|
+
expect(id).toMatch(/^[a-z][a-z0-9-]{4,28}[a-z0-9]$/);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
it("derives the names the kinds had before the catalog", () => {
|
|
58
|
+
expect(REPORTING_JOB_CATALOG.map((e) => reportingJobName(e, "production"))).toEqual([
|
|
59
|
+
"caelo-production-audit-run",
|
|
60
|
+
"caelo-production-import",
|
|
61
|
+
"caelo-production-build",
|
|
62
|
+
"caelo-production-index",
|
|
63
|
+
"caelo-production-plugin-batch",
|
|
64
|
+
]);
|
|
65
|
+
for (const e of REPORTING_JOB_CATALOG) {
|
|
66
|
+
const spec = reportingJobSpec(e, PLACE);
|
|
67
|
+
expect(spec.jobName).toBe(reportingJobName(e, "production"));
|
|
68
|
+
expect(`${spec.serviceAccountId}@acme.iam.gserviceaccount.com`).toBe(
|
|
69
|
+
reportingJobServiceAccountEmail(e, "acme", "production"),
|
|
70
|
+
);
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
it("grants beyond the shared line only what a kind declares, each with a reason", () => {
|
|
75
|
+
const beyond = Object.fromEntries(
|
|
76
|
+
REPORTING_JOB_CATALOG.map((e) => {
|
|
77
|
+
const s = reportingJobSpec(e, PLACE);
|
|
78
|
+
return [
|
|
79
|
+
e.kind,
|
|
80
|
+
{
|
|
81
|
+
read: s.readBuckets.map((b) => b.bucket),
|
|
82
|
+
write: s.writeBuckets.map((b) => b.bucket),
|
|
83
|
+
run: s.runJobs.map((j) => j.job),
|
|
84
|
+
},
|
|
85
|
+
];
|
|
86
|
+
}),
|
|
87
|
+
);
|
|
88
|
+
expect(beyond).toEqual({
|
|
89
|
+
quality_audit: {
|
|
90
|
+
read: ["acme-caelo-production-staging", "acme-caelo-production-audit-results"],
|
|
91
|
+
write: [],
|
|
92
|
+
run: ["caelo-production-audit"],
|
|
93
|
+
},
|
|
94
|
+
site_import: { read: [], write: [], run: [] },
|
|
95
|
+
build: { read: [], write: [], run: [] },
|
|
96
|
+
collection_index: {
|
|
97
|
+
read: ["acme-caelo-production-coll-staging"],
|
|
98
|
+
write: ["acme-caelo-production-coll-staging"],
|
|
99
|
+
run: [],
|
|
100
|
+
},
|
|
101
|
+
plugin_batch: { read: [], write: [], run: [] },
|
|
102
|
+
});
|
|
103
|
+
for (const e of REPORTING_JOB_CATALOG) {
|
|
104
|
+
const s = reportingJobSpec(e, PLACE);
|
|
105
|
+
for (const g of [...s.readBuckets, ...s.writeBuckets, ...s.runJobs]) {
|
|
106
|
+
expect(g.why.length).toBeGreaterThan(10);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
it("sets each kind up after what it needs", () => {
|
|
112
|
+
expect(reportingJobEntry("quality_audit").prerequisite).toBe("audit-job");
|
|
113
|
+
expect(reportingJobEntry("collection_index").prerequisite).toBe("collection-stores");
|
|
114
|
+
expect(() => reportingJobEntry("nope")).toThrow(/no reporting job kind "nope"/);
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
it("reaches the admin's env, the image move, the upgrader's actAs and its pre-flight", () => {
|
|
118
|
+
const env = adminEnvContract({
|
|
119
|
+
provider: "gcp",
|
|
120
|
+
projectId: "acme",
|
|
121
|
+
env: "production",
|
|
122
|
+
domain: "acme.com",
|
|
123
|
+
region: "europe-west1",
|
|
124
|
+
stagingHost: "staging.acme.com",
|
|
125
|
+
databaseUrls: databaseUrls("db1.p-label.europe-west1.sql-psa.goog"),
|
|
126
|
+
});
|
|
127
|
+
const names = env.map((v) => v.name);
|
|
128
|
+
for (const v of reportingJobAdminEnv("acme", "europe-west1", "production")) {
|
|
129
|
+
expect(env).toContainEqual(v);
|
|
130
|
+
}
|
|
131
|
+
// In catalog order, one pair per kind.
|
|
132
|
+
const pairs = REPORTING_JOB_CATALOG.flatMap((e) => [e.jobEnvVar, e.serviceAccountEnvVar]);
|
|
133
|
+
expect(names.filter((n) => pairs.includes(n))).toEqual(pairs);
|
|
134
|
+
|
|
135
|
+
const moved = adminImageJobs("production").map((j) => j.name);
|
|
136
|
+
expect(moved.slice(0, 2)).toEqual(["caelo-production-audit", "caelo-production-capture"]);
|
|
137
|
+
expect(moved.slice(2)).toEqual(
|
|
138
|
+
REPORTING_JOB_CATALOG.map((e) => reportingJobName(e, "production")),
|
|
139
|
+
);
|
|
140
|
+
|
|
141
|
+
const actAs = upgraderAccountGrants("acme", "production").map((g) => g.account);
|
|
142
|
+
const checked = upgraderAccessChecks({
|
|
143
|
+
projectId: "acme",
|
|
144
|
+
region: "europe-west1",
|
|
145
|
+
env: "production",
|
|
146
|
+
}).flatMap((c) =>
|
|
147
|
+
c.resource.kind === "service-account" && c.permissions.includes("iam.serviceAccounts.actAs")
|
|
148
|
+
? [c.resource.email]
|
|
149
|
+
: [],
|
|
150
|
+
);
|
|
151
|
+
for (const sa of reportingJobServiceAccounts("acme", "production")) {
|
|
152
|
+
expect(actAs).toContain(sa);
|
|
153
|
+
expect(checked).toContain(sa);
|
|
154
|
+
}
|
|
155
|
+
});
|
|
156
|
+
});
|
|
@@ -0,0 +1,426 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MPL-2.0
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* #1646 (epic #1644) — one declaration per kind of reporting job. A
|
|
5
|
+
* reporting job (#1359) runs bounded work outside the admin and reports
|
|
6
|
+
* back by request: a Stage's quality audit, a site import's crawl, a
|
|
7
|
+
* carried build, a Stage's collection index, a plugin's batch run. Each
|
|
8
|
+
* kind is ONE entry of {@link REPORTING_JOB_CATALOG}: its names, the admin
|
|
9
|
+
* env vars that point at it, its machine, its grants beyond the shared
|
|
10
|
+
* line, what must exist before it can be set up, and how the CLI talks
|
|
11
|
+
* about it. Everything that sets up, moves or grants jobs iterates the
|
|
12
|
+
* catalog: the admin's env contract, the wizard, every converge, the
|
|
13
|
+
* app-roll's image move, the upgrader's actAs, its IAM pre-flight and the
|
|
14
|
+
* operator-access IAP list. A new kind is one entry here plus its kind in
|
|
15
|
+
* admin-core (reporting-jobs/kinds.ts; the scripts parity test pins the env
|
|
16
|
+
* var names of both).
|
|
17
|
+
*
|
|
18
|
+
* Outside the catalog stay the two jobs that are not reporting jobs: the
|
|
19
|
+
* Lighthouse audit job (audit-job-setup.ts: parallel tasks, a results
|
|
20
|
+
* bucket, no IAP access) and the capture job (capture-job-setup.ts: renders
|
|
21
|
+
* untrusted pages, so no IAP access and no read right anywhere). Their
|
|
22
|
+
* trust line differs from the shared one, so folding them in would change
|
|
23
|
+
* what they may do.
|
|
24
|
+
*
|
|
25
|
+
* Pure module: stack-contract.ts (the admin's env contract) imports it.
|
|
26
|
+
* The setup itself is reporting-job-setup.ts.
|
|
27
|
+
*/
|
|
28
|
+
|
|
29
|
+
import { COLLECTIONS_STAGING_STORE_ENV, gcpCollectionStore } from "./collection-stores.js";
|
|
30
|
+
import {
|
|
31
|
+
auditJobName,
|
|
32
|
+
auditJobResource,
|
|
33
|
+
gcpBucketName,
|
|
34
|
+
reportingJobAccountId,
|
|
35
|
+
} from "./gcp-names.js";
|
|
36
|
+
import type { GcpProvider } from "./stack-contract.js";
|
|
37
|
+
|
|
38
|
+
/** Where a kind's job goes. */
|
|
39
|
+
export interface ReportingJobPlace {
|
|
40
|
+
readonly provider: GcpProvider;
|
|
41
|
+
readonly projectId: string;
|
|
42
|
+
readonly region: string;
|
|
43
|
+
/** Pulumi stack name (`production`). */
|
|
44
|
+
readonly env: string;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/** What one kind of reporting job needs beyond the shared grants. */
|
|
48
|
+
export interface ReportingJobSpec {
|
|
49
|
+
/** How the CLI names it ("quality-audit runner"). */
|
|
50
|
+
readonly label: string;
|
|
51
|
+
readonly jobName: string;
|
|
52
|
+
readonly serviceAccountId: string;
|
|
53
|
+
readonly displayName: string;
|
|
54
|
+
readonly description: string;
|
|
55
|
+
/** The job's env (`KEY=value`; never a secret). */
|
|
56
|
+
readonly env: readonly string[];
|
|
57
|
+
readonly cpu: string;
|
|
58
|
+
readonly memory: string;
|
|
59
|
+
/** One execution's ceiling (admin-core protocol.ts `JOB_TIMING.maxRunSeconds`). */
|
|
60
|
+
readonly taskTimeoutSeconds: number;
|
|
61
|
+
/** Read-only bucket access it needs, each with the reason. */
|
|
62
|
+
readonly readBuckets: readonly { readonly bucket: string; readonly why: string }[];
|
|
63
|
+
/**
|
|
64
|
+
* Buckets it creates objects in (`roles/storage.objectCreator`: create
|
|
65
|
+
* only, no overwrite, no delete, no read — pair it with a read bucket when
|
|
66
|
+
* the job reads there too), each with the reason. Reviewed per kind: only
|
|
67
|
+
* the collection index job has one.
|
|
68
|
+
*/
|
|
69
|
+
readonly writeBuckets: readonly { readonly bucket: string; readonly why: string }[];
|
|
70
|
+
/** Jobs it starts itself, with its order as an override (and reads their executions). */
|
|
71
|
+
readonly runJobs: readonly { readonly job: string; readonly why: string }[];
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/** What a kind declares of its job; the catalog adds its label and names. */
|
|
75
|
+
export type ReportingKindJob = Omit<ReportingJobSpec, "label" | "jobName" | "serviceAccountId">;
|
|
76
|
+
|
|
77
|
+
/** What a kind's setup waits for: its step comes after that one, and is skipped without it. */
|
|
78
|
+
export type ReportingJobPrerequisite =
|
|
79
|
+
/** The Lighthouse audit job (audit-job-setup.ts), whose tasks it starts. */
|
|
80
|
+
| "audit-job"
|
|
81
|
+
/** The collection stores (collections-setup.ts), where it reads and writes. */
|
|
82
|
+
| "collection-stores";
|
|
83
|
+
|
|
84
|
+
/** One kind of reporting job. */
|
|
85
|
+
export interface ReportingJobKindEntry {
|
|
86
|
+
/** The kind's name in admin-core (reporting-jobs/protocol.ts `REPORTING_JOB_KINDS`). */
|
|
87
|
+
readonly kind: string;
|
|
88
|
+
/** The issue that added it, for the CLI's history lines. */
|
|
89
|
+
readonly issue: string;
|
|
90
|
+
/**
|
|
91
|
+
* Job name and service-account id suffix: `caelo-<env>-<name>`. An
|
|
92
|
+
* account id has at most 30 characters (the catalog test checks it for
|
|
93
|
+
* every stack env).
|
|
94
|
+
*/
|
|
95
|
+
readonly name: string;
|
|
96
|
+
/** The admin env var naming the job (`projects/<p>/locations/<r>/jobs/<j>`). */
|
|
97
|
+
readonly jobEnvVar: string;
|
|
98
|
+
/** The admin env var naming the one account whose reports the admin takes for it. */
|
|
99
|
+
readonly serviceAccountEnvVar: string;
|
|
100
|
+
/** How the CLI names it ("quality-audit runner"). */
|
|
101
|
+
readonly label: string;
|
|
102
|
+
readonly prerequisite: ReportingJobPrerequisite | null;
|
|
103
|
+
/** Its job: machine, env and grants beyond the shared line. */
|
|
104
|
+
readonly job: (place: ReportingJobPlace) => ReportingKindJob;
|
|
105
|
+
/** The wizard's spinner lines. */
|
|
106
|
+
readonly wizard: { readonly starting: string; readonly ready: string };
|
|
107
|
+
/** The converge's step lines, and what fails until it succeeds. */
|
|
108
|
+
readonly converge: {
|
|
109
|
+
readonly step: string;
|
|
110
|
+
readonly ready: string;
|
|
111
|
+
readonly consequence: string;
|
|
112
|
+
};
|
|
113
|
+
/** What fails while its image lags behind the admin's (upgrade/admin-image-jobs.ts). */
|
|
114
|
+
readonly lagging: string;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/** `caelo-<env>-<name>`: the kind's job name. */
|
|
118
|
+
export function reportingJobName(entry: Pick<ReportingJobKindEntry, "name">, env: string): string {
|
|
119
|
+
return reportingJobAccountId(env, entry.name);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/** The job's full resource name, as the admin's env carries it. */
|
|
123
|
+
export function reportingJobResource(
|
|
124
|
+
entry: Pick<ReportingJobKindEntry, "name">,
|
|
125
|
+
projectId: string,
|
|
126
|
+
region: string,
|
|
127
|
+
env: string,
|
|
128
|
+
): string {
|
|
129
|
+
return `projects/${projectId}/locations/${region}/jobs/${reportingJobName(entry, env)}`;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/** The kind's service account email. */
|
|
133
|
+
export function reportingJobServiceAccountEmail(
|
|
134
|
+
entry: Pick<ReportingJobKindEntry, "name">,
|
|
135
|
+
projectId: string,
|
|
136
|
+
env: string,
|
|
137
|
+
): string {
|
|
138
|
+
return `${reportingJobAccountId(env, entry.name)}@${projectId}.iam.gserviceaccount.com`;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* The audit runner (#1359): the whole quality audit of a Stage. It serves
|
|
143
|
+
* the staged build from its staging slot to its own findings checks, starts
|
|
144
|
+
* the Lighthouse tasks on the audit job (#875) and reads their results.
|
|
145
|
+
*/
|
|
146
|
+
function auditRunnerJob(place: ReportingJobPlace): ReportingKindJob {
|
|
147
|
+
const { projectId, region, env, provider } = place;
|
|
148
|
+
const staging = gcpBucketName(projectId, env, "staging");
|
|
149
|
+
const results = gcpBucketName(projectId, env, "audit-results");
|
|
150
|
+
return {
|
|
151
|
+
displayName: "Caelo quality-audit runner",
|
|
152
|
+
description:
|
|
153
|
+
"Runs a Stage's quality audit and reports to the admin; reads the staged build and the Lighthouse results, starts the Lighthouse tasks, nothing else.",
|
|
154
|
+
env: [
|
|
155
|
+
`CAELO_PROVIDER=${provider}`,
|
|
156
|
+
`CAELO_STAGING_BUCKET=${staging}`,
|
|
157
|
+
`CAELO_AUDIT_JOB=${auditJobResource(projectId, region, env)}`,
|
|
158
|
+
`CAELO_AUDIT_RESULTS_BUCKET=${results}`,
|
|
159
|
+
],
|
|
160
|
+
cpu: "1",
|
|
161
|
+
memory: "2Gi",
|
|
162
|
+
// admin-core JOB_TIMING.quality_audit.maxRunSeconds.
|
|
163
|
+
taskTimeoutSeconds: 3600,
|
|
164
|
+
readBuckets: [
|
|
165
|
+
{ bucket: staging, why: "it serves the staged build to the findings checks" },
|
|
166
|
+
{ bucket: results, why: "it reads the Lighthouse tasks' results" },
|
|
167
|
+
],
|
|
168
|
+
writeBuckets: [],
|
|
169
|
+
runJobs: [{ job: auditJobName(env), why: "it starts the Lighthouse tasks" }],
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
/**
|
|
174
|
+
* The site-import crawler (#1360): one site import's crawl. It reads
|
|
175
|
+
* third-party pages, so it holds nothing beyond the shared grants: no
|
|
176
|
+
* bucket, no other job. It fetches robots.txt and sitemaps itself, through
|
|
177
|
+
* the SSRF guard; every page render is the admin's, which starts the
|
|
178
|
+
* capture job and keeps the screenshot, so the crawler never runs a
|
|
179
|
+
* browser and never touches the capture job or its bucket.
|
|
180
|
+
*/
|
|
181
|
+
function importCrawlJob(place: ReportingJobPlace): ReportingKindJob {
|
|
182
|
+
return {
|
|
183
|
+
displayName: "Caelo site-import crawler",
|
|
184
|
+
description:
|
|
185
|
+
"Crawls a site the Owner approved for import and reports each page to the admin; fetches robots.txt and sitemaps through the SSRF guard, nothing else.",
|
|
186
|
+
env: [`CAELO_PROVIDER=${place.provider}`],
|
|
187
|
+
cpu: "1",
|
|
188
|
+
// The frontier and up to four rendered pages' HTML at once.
|
|
189
|
+
memory: "2Gi",
|
|
190
|
+
// admin-core JOB_TIMING.site_import.maxRunSeconds: a longer crawl goes
|
|
191
|
+
// on in the next attempt, from its checkpoint.
|
|
192
|
+
taskTimeoutSeconds: 6 * 3600,
|
|
193
|
+
readBuckets: [],
|
|
194
|
+
writeBuckets: [],
|
|
195
|
+
runJobs: [],
|
|
196
|
+
};
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
/**
|
|
200
|
+
* The build carrier (#1574): one Stage's, Publish live's or production
|
|
201
|
+
* build's request. It sends one report, `run`, and the admin runs the build
|
|
202
|
+
* inside that request on its own database and rights, so the carrier holds
|
|
203
|
+
* nothing beyond the shared grants: it reads nothing, fetches nothing,
|
|
204
|
+
* builds nothing. Smallest machine: it only waits for the answer.
|
|
205
|
+
*/
|
|
206
|
+
function buildCarrierJob(place: ReportingJobPlace): ReportingKindJob {
|
|
207
|
+
return {
|
|
208
|
+
displayName: "Caelo build carrier",
|
|
209
|
+
description:
|
|
210
|
+
"Holds the admin request a Stage, Publish live or production build runs in, so the build ends when nobody waits for it; reports to the admin, nothing else.",
|
|
211
|
+
env: [`CAELO_PROVIDER=${place.provider}`],
|
|
212
|
+
cpu: "1",
|
|
213
|
+
memory: "512Mi",
|
|
214
|
+
// admin-core JOB_TIMING.build.maxRunSeconds: the admin's request limit
|
|
215
|
+
// (the build stops two minutes before it) plus room to start and end.
|
|
216
|
+
taskTimeoutSeconds: 3600 + 5 * 60,
|
|
217
|
+
readBuckets: [],
|
|
218
|
+
writeBuckets: [],
|
|
219
|
+
runJobs: [],
|
|
220
|
+
};
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
/**
|
|
224
|
+
* Epic #1644 (R2, #1648) — the collection index job: the plugin collection
|
|
225
|
+
* releases of a Stage. It asks the admin which collections changed, reads
|
|
226
|
+
* their change files and previous releases from the staging collection
|
|
227
|
+
* store, writes the new release's files there (each content-named and
|
|
228
|
+
* written once, so create-only access is enough) and reports each release.
|
|
229
|
+
* It holds no database credential and no secret; the bucket is the only
|
|
230
|
+
* thing it reaches beyond the shared grants, and nothing of the live store.
|
|
231
|
+
* Sized for a 50,000-page rebuild with on-CPU embeddings (R7): 2 vCPU, 4 GiB.
|
|
232
|
+
*/
|
|
233
|
+
function collectionIndexJob(place: ReportingJobPlace): ReportingKindJob {
|
|
234
|
+
const store = gcpBucketName(place.projectId, place.env, "coll-staging");
|
|
235
|
+
return {
|
|
236
|
+
displayName: "Caelo collection index job",
|
|
237
|
+
description:
|
|
238
|
+
"Builds a Stage's plugin collection releases and reports them to the admin; reads and creates files in the staging collection store, nothing else.",
|
|
239
|
+
env: [
|
|
240
|
+
`CAELO_PROVIDER=${place.provider}`,
|
|
241
|
+
`${COLLECTIONS_STAGING_STORE_ENV}=${gcpCollectionStore(place.projectId, place.env, "staging")}`,
|
|
242
|
+
],
|
|
243
|
+
cpu: "2",
|
|
244
|
+
memory: "4Gi",
|
|
245
|
+
// admin-core JOB_TIMING.collection_index.maxRunSeconds.
|
|
246
|
+
taskTimeoutSeconds: 3600,
|
|
247
|
+
readBuckets: [
|
|
248
|
+
{ bucket: store, why: "it reads the Stage's change files and the previous releases" },
|
|
249
|
+
],
|
|
250
|
+
writeBuckets: [{ bucket: store, why: "it writes the new releases' files" }],
|
|
251
|
+
runJobs: [],
|
|
252
|
+
};
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
/**
|
|
256
|
+
* Epic #1644 (R5, #1646) — the plugin batch job: one run of a plugin's
|
|
257
|
+
* declared batch operation (a backfill, say), its code in the Deno sandbox
|
|
258
|
+
* inside the job. It holds the shared grants and nothing else: no bucket,
|
|
259
|
+
* no other job, no database, no secret. Every storage or collection call
|
|
260
|
+
* the plugin makes goes to the admin as a report, where the plugin's
|
|
261
|
+
* grants and the host's rules decide it, as for any plugin call. 2 GiB:
|
|
262
|
+
* the sandbox's heap (256 MiB) next to Bun and the batches in flight.
|
|
263
|
+
*/
|
|
264
|
+
function pluginBatchJob(place: ReportingJobPlace): ReportingKindJob {
|
|
265
|
+
return {
|
|
266
|
+
displayName: "Caelo plugin batch job",
|
|
267
|
+
description:
|
|
268
|
+
"Runs a plugin's batch operation in the plugin sandbox and reports every call it makes to the admin; reaches nothing else.",
|
|
269
|
+
env: [`CAELO_PROVIDER=${place.provider}`],
|
|
270
|
+
cpu: "1",
|
|
271
|
+
memory: "2Gi",
|
|
272
|
+
// admin-core JOB_TIMING.plugin_batch.maxRunSeconds plus room to start and end.
|
|
273
|
+
taskTimeoutSeconds: 3600 + 5 * 60,
|
|
274
|
+
readBuckets: [],
|
|
275
|
+
writeBuckets: [],
|
|
276
|
+
runJobs: [],
|
|
277
|
+
};
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
/**
|
|
281
|
+
* Every kind, in setup order: the wizard and the converge set them up in
|
|
282
|
+
* this order, the admin's env lists them in it, and the app-roll moves
|
|
283
|
+
* them in it (after the audit and capture jobs).
|
|
284
|
+
*/
|
|
285
|
+
export const REPORTING_JOB_CATALOG: readonly ReportingJobKindEntry[] = [
|
|
286
|
+
{
|
|
287
|
+
kind: "quality_audit",
|
|
288
|
+
issue: "#1359",
|
|
289
|
+
name: "audit-run",
|
|
290
|
+
jobEnvVar: "CAELO_AUDIT_RUNNER_JOB",
|
|
291
|
+
serviceAccountEnvVar: "CAELO_AUDIT_RUNNER_SERVICE_ACCOUNT",
|
|
292
|
+
// It starts the Lighthouse tasks: its run grant is on that job.
|
|
293
|
+
prerequisite: "audit-job",
|
|
294
|
+
label: "quality-audit runner",
|
|
295
|
+
job: auditRunnerJob,
|
|
296
|
+
wizard: {
|
|
297
|
+
starting: "Setting up the quality-audit runner (audits outside the admin)...",
|
|
298
|
+
ready: "Quality-audit runner ready",
|
|
299
|
+
},
|
|
300
|
+
converge: {
|
|
301
|
+
step: "Ensuring the quality-audit runner (audits outside the admin)...",
|
|
302
|
+
ready: "Quality-audit runner ready (Stage audits run in their own job)",
|
|
303
|
+
consequence: "Stage audits fail after their last attempt",
|
|
304
|
+
},
|
|
305
|
+
lagging: "Stage audits wait for it and fail after their last attempt",
|
|
306
|
+
},
|
|
307
|
+
{
|
|
308
|
+
kind: "site_import",
|
|
309
|
+
issue: "#1360",
|
|
310
|
+
name: "import",
|
|
311
|
+
jobEnvVar: "CAELO_IMPORT_CRAWL_JOB",
|
|
312
|
+
serviceAccountEnvVar: "CAELO_IMPORT_CRAWL_SERVICE_ACCOUNT",
|
|
313
|
+
prerequisite: null,
|
|
314
|
+
label: "site-import crawler",
|
|
315
|
+
job: importCrawlJob,
|
|
316
|
+
wizard: {
|
|
317
|
+
starting: "Setting up the site-import crawler (crawls outside the admin)...",
|
|
318
|
+
ready: "Site-import crawler ready",
|
|
319
|
+
},
|
|
320
|
+
converge: {
|
|
321
|
+
step: "Ensuring the site-import crawler (crawls outside the admin)...",
|
|
322
|
+
ready: "Site-import crawler ready (site imports crawl in their own job)",
|
|
323
|
+
consequence: "site imports fail after their last attempt",
|
|
324
|
+
},
|
|
325
|
+
lagging: "site imports wait for it and fail after their last attempt",
|
|
326
|
+
},
|
|
327
|
+
{
|
|
328
|
+
kind: "build",
|
|
329
|
+
issue: "#1574",
|
|
330
|
+
name: "build",
|
|
331
|
+
jobEnvVar: "CAELO_BUILD_CARRIER_JOB",
|
|
332
|
+
serviceAccountEnvVar: "CAELO_BUILD_CARRIER_SERVICE_ACCOUNT",
|
|
333
|
+
prerequisite: null,
|
|
334
|
+
label: "build carrier",
|
|
335
|
+
job: buildCarrierJob,
|
|
336
|
+
wizard: {
|
|
337
|
+
starting: "Setting up the build carrier (builds that outlast their request)...",
|
|
338
|
+
ready: "Build carrier ready",
|
|
339
|
+
},
|
|
340
|
+
converge: {
|
|
341
|
+
step: "Ensuring the build carrier (builds that outlast their request)...",
|
|
342
|
+
ready: "Build carrier ready (a build nobody waits for still ends)",
|
|
343
|
+
consequence:
|
|
344
|
+
"an agent's Stage and every Stage or Publish live button fail at once with this reason",
|
|
345
|
+
},
|
|
346
|
+
lagging: "an agent's Stage and the Stage and Publish live buttons fail (Stage again)",
|
|
347
|
+
},
|
|
348
|
+
{
|
|
349
|
+
kind: "collection_index",
|
|
350
|
+
issue: "#1648",
|
|
351
|
+
name: "index",
|
|
352
|
+
jobEnvVar: "CAELO_COLLECTION_INDEX_JOB",
|
|
353
|
+
serviceAccountEnvVar: "CAELO_COLLECTION_INDEX_SERVICE_ACCOUNT",
|
|
354
|
+
// It reads and writes the staging collection store.
|
|
355
|
+
prerequisite: "collection-stores",
|
|
356
|
+
label: "collection index job",
|
|
357
|
+
job: collectionIndexJob,
|
|
358
|
+
wizard: {
|
|
359
|
+
starting: "Setting up the collection index job (a Stage's search index outside the admin)...",
|
|
360
|
+
ready: "Collection index job ready",
|
|
361
|
+
},
|
|
362
|
+
converge: {
|
|
363
|
+
step: "Ensuring the collection index job (a Stage's search index outside the admin)...",
|
|
364
|
+
ready: "Collection index job ready (a Stage's plugin indexes build in their own job)",
|
|
365
|
+
consequence: "a Stage's plugin collections (a site search) fail after their last attempt",
|
|
366
|
+
},
|
|
367
|
+
lagging: "a Stage's plugin collections fail after their last attempt (Stage again)",
|
|
368
|
+
},
|
|
369
|
+
{
|
|
370
|
+
kind: "plugin_batch",
|
|
371
|
+
issue: "#1646",
|
|
372
|
+
name: "plugin-batch",
|
|
373
|
+
jobEnvVar: "CAELO_PLUGIN_BATCH_JOB",
|
|
374
|
+
serviceAccountEnvVar: "CAELO_PLUGIN_BATCH_SERVICE_ACCOUNT",
|
|
375
|
+
prerequisite: null,
|
|
376
|
+
label: "plugin batch job",
|
|
377
|
+
job: pluginBatchJob,
|
|
378
|
+
wizard: {
|
|
379
|
+
starting: "Setting up the plugin batch job (plugins' batch runs outside the admin)...",
|
|
380
|
+
ready: "Plugin batch job ready",
|
|
381
|
+
},
|
|
382
|
+
converge: {
|
|
383
|
+
step: "Ensuring the plugin batch job (plugins' batch runs outside the admin)...",
|
|
384
|
+
ready: "Plugin batch job ready (a plugin's batch run has its own job)",
|
|
385
|
+
consequence: "plugins' batch runs (backfills) fail after their last attempt",
|
|
386
|
+
},
|
|
387
|
+
lagging: "plugins' batch runs fail after their last attempt",
|
|
388
|
+
},
|
|
389
|
+
];
|
|
390
|
+
|
|
391
|
+
/** The full spec of `entry`'s job at `place`: what reporting-job-setup.ts sets up. */
|
|
392
|
+
export function reportingJobSpec(
|
|
393
|
+
entry: ReportingJobKindEntry,
|
|
394
|
+
place: ReportingJobPlace,
|
|
395
|
+
): ReportingJobSpec {
|
|
396
|
+
return {
|
|
397
|
+
label: entry.label,
|
|
398
|
+
jobName: reportingJobName(entry, place.env),
|
|
399
|
+
serviceAccountId: reportingJobAccountId(place.env, entry.name),
|
|
400
|
+
...entry.job(place),
|
|
401
|
+
};
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
/** The catalog entry of `kind`; throws for a kind it does not have. */
|
|
405
|
+
export function reportingJobEntry(kind: string): ReportingJobKindEntry {
|
|
406
|
+
const entry = REPORTING_JOB_CATALOG.find((e) => e.kind === kind);
|
|
407
|
+
if (!entry) throw new Error(`no reporting job kind "${kind}" in the catalog`);
|
|
408
|
+
return entry;
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
/** Every kind's pair of admin env vars, in catalog order (stack-contract.ts adminEnvContract). */
|
|
412
|
+
export function reportingJobAdminEnv(
|
|
413
|
+
projectId: string,
|
|
414
|
+
region: string,
|
|
415
|
+
env: string,
|
|
416
|
+
): { readonly name: string; readonly value: string }[] {
|
|
417
|
+
return REPORTING_JOB_CATALOG.flatMap((e) => [
|
|
418
|
+
{ name: e.jobEnvVar, value: reportingJobResource(e, projectId, region, env) },
|
|
419
|
+
{ name: e.serviceAccountEnvVar, value: reportingJobServiceAccountEmail(e, projectId, env) },
|
|
420
|
+
]);
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
/** Every kind's service account email: the upgrader's actAs, the operator-access IAP list. */
|
|
424
|
+
export function reportingJobServiceAccounts(projectId: string, env: string): string[] {
|
|
425
|
+
return REPORTING_JOB_CATALOG.map((e) => reportingJobServiceAccountEmail(e, projectId, env));
|
|
426
|
+
}
|