@caelo-cms/provisioning 0.11.19 → 0.11.20
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 +32 -0
- package/dist/aws-task-roles.d.ts +11 -0
- package/dist/aws-task-roles.d.ts.map +1 -1
- package/dist/aws-task-roles.js +19 -0
- package/dist/aws-task-roles.js.map +1 -1
- package/dist/azure-secrets.d.ts +22 -0
- package/dist/azure-secrets.d.ts.map +1 -0
- package/dist/azure-secrets.js +14 -0
- package/dist/azure-secrets.js.map +1 -0
- package/dist/caddy.d.ts +7 -0
- package/dist/caddy.d.ts.map +1 -1
- package/dist/caddy.js +22 -1
- package/dist/caddy.js.map +1 -1
- package/dist/cli.js +3 -0
- package/dist/cli.js.map +1 -1
- package/dist/gateway-armor.d.ts +24 -0
- package/dist/gateway-armor.d.ts.map +1 -0
- package/dist/gateway-armor.js +118 -0
- package/dist/gateway-armor.js.map +1 -0
- package/dist/gateway-edge.d.ts +128 -0
- package/dist/gateway-edge.d.ts.map +1 -0
- package/dist/gateway-edge.js +211 -0
- package/dist/gateway-edge.js.map +1 -0
- package/dist/infra-contract.d.ts +1 -1
- package/dist/infra-contract.d.ts.map +1 -1
- package/dist/infra-contract.js +21 -1
- package/dist/infra-contract.js.map +1 -1
- package/dist/lifecycle.d.ts.map +1 -1
- package/dist/lifecycle.js +8 -1
- package/dist/lifecycle.js.map +1 -1
- package/dist/pool-budget-stack.d.ts +22 -0
- package/dist/pool-budget-stack.d.ts.map +1 -1
- package/dist/pool-budget-stack.js +22 -1
- package/dist/pool-budget-stack.js.map +1 -1
- package/dist/public-service-shape.d.ts +45 -0
- package/dist/public-service-shape.d.ts.map +1 -0
- package/dist/public-service-shape.js +90 -0
- package/dist/public-service-shape.js.map +1 -0
- package/dist/remote-mcp-edge.d.ts +1 -1
- package/dist/remote-mcp-edge.js +1 -1
- package/dist/remote-mcp.d.ts.map +1 -1
- package/dist/remote-mcp.js +12 -2
- package/dist/remote-mcp.js.map +1 -1
- package/dist/serverless-backend.d.ts +27 -0
- package/dist/serverless-backend.d.ts.map +1 -0
- package/dist/serverless-backend.js +30 -0
- package/dist/serverless-backend.js.map +1 -0
- package/dist/stack-contract.d.ts +6 -0
- package/dist/stack-contract.d.ts.map +1 -1
- package/dist/stack-contract.js +24 -0
- package/dist/stack-contract.js.map +1 -1
- package/dist/stack-converge.d.ts +13 -0
- package/dist/stack-converge.d.ts.map +1 -1
- package/dist/stack-converge.js +27 -0
- package/dist/stack-converge.js.map +1 -1
- package/dist/staging-gateway-setup.d.ts +5 -0
- package/dist/staging-gateway-setup.d.ts.map +1 -1
- package/dist/staging-gateway-setup.js +60 -19
- package/dist/staging-gateway-setup.js.map +1 -1
- package/dist/upgrade/app-roll.d.ts +5 -1
- package/dist/upgrade/app-roll.d.ts.map +1 -1
- package/dist/upgrade/app-roll.js +20 -3
- package/dist/upgrade/app-roll.js.map +1 -1
- package/dist/upgrade/converge.d.ts.map +1 -1
- package/dist/upgrade/converge.js +27 -4
- package/dist/upgrade/converge.js.map +1 -1
- package/dist/upgrade/health.d.ts +13 -3
- package/dist/upgrade/health.d.ts.map +1 -1
- package/dist/upgrade/health.js +24 -7
- package/dist/upgrade/health.js.map +1 -1
- package/dist/upgrade/load-balancer-get.d.ts +17 -0
- package/dist/upgrade/load-balancer-get.d.ts.map +1 -0
- package/dist/upgrade/load-balancer-get.js +38 -0
- package/dist/upgrade/load-balancer-get.js.map +1 -0
- package/dist/upgrader-gcp.d.ts.map +1 -1
- package/dist/upgrader-gcp.js +8 -1
- package/dist/upgrader-gcp.js.map +1 -1
- package/dist/wizards/gcp-cost.d.ts +9 -0
- package/dist/wizards/gcp-cost.d.ts.map +1 -1
- package/dist/wizards/gcp-cost.js +69 -34
- package/dist/wizards/gcp-cost.js.map +1 -1
- package/package.json +2 -2
- package/src/aws-task-roles.ts +22 -0
- package/src/azure-secrets.ts +38 -0
- package/src/caddy.test.ts +19 -2
- package/src/caddy.ts +23 -0
- package/src/cli.ts +5 -0
- package/src/gateway-armor.ts +135 -0
- package/src/gateway-bootstrap.test.ts +1 -0
- package/src/gateway-edge.test.ts +262 -0
- package/src/gateway-edge.ts +256 -0
- package/src/gateway-env-isolation.test.ts +45 -6
- package/src/infra-contract.test.ts +5 -3
- package/src/infra-contract.ts +21 -1
- package/src/lifecycle.ts +8 -1
- package/src/pool-budget-stack.ts +25 -0
- package/src/pool-budget-stacks.test.ts +31 -0
- package/src/public-service-shape.test.ts +166 -0
- package/src/public-service-shape.ts +131 -0
- package/src/remote-mcp-edge.ts +1 -1
- package/src/remote-mcp.test.ts +38 -1
- package/src/remote-mcp.ts +25 -3
- package/src/serverless-backend.ts +47 -0
- package/src/stack-contract.test.ts +13 -0
- package/src/stack-contract.ts +25 -0
- package/src/stack-converge.test.ts +28 -1
- package/src/stack-converge.ts +30 -0
- package/src/staging-gateway-setup.test.ts +55 -3
- package/src/staging-gateway-setup.ts +79 -27
- package/src/upgrade/app-roll.ts +27 -3
- package/src/upgrade/converge.ts +33 -4
- package/src/upgrade/health.test.ts +88 -13
- package/src/upgrade/health.ts +32 -7
- package/src/upgrade/load-balancer-get.ts +64 -0
- package/src/upgrade/upgrade.test.ts +96 -3
- package/src/upgrader-gcp.ts +8 -1
- package/src/wizards/gcp-cost.ts +78 -35
- package/stacks/aws/index.ts +24 -22
- package/stacks/azure/index.ts +152 -64
- package/stacks/gcp/index.ts +35 -47
- package/stacks/gcp-firebase/index.ts +25 -13
|
@@ -14,9 +14,11 @@ import {
|
|
|
14
14
|
liveContainerEnv,
|
|
15
15
|
liveDatabaseHost,
|
|
16
16
|
liveDirectVpc,
|
|
17
|
+
liveMaxInstances,
|
|
17
18
|
liveServiceAccount,
|
|
18
19
|
planContractEnv,
|
|
19
20
|
planEnvUpdate,
|
|
21
|
+
planMaxInstances,
|
|
20
22
|
planNoVpc,
|
|
21
23
|
policyGrants,
|
|
22
24
|
removeRetiredIamBindings,
|
|
@@ -849,7 +851,7 @@ describe("ensureStackInvariants", () => {
|
|
|
849
851
|
]),
|
|
850
852
|
],
|
|
851
853
|
"run services get-iam-policy": [
|
|
852
|
-
policy([{ role: "roles/run.invoker", members: [IAP_AGENT] }]),
|
|
854
|
+
policy([{ role: "roles/run.invoker", members: [IAP_AGENT, "allUsers"] }]),
|
|
853
855
|
],
|
|
854
856
|
"compute backend-buckets list": [ok("caelo-production-static-backend-9f8e7d6\n")],
|
|
855
857
|
"compute firewall-rules list": [ok("[]")],
|
|
@@ -1145,3 +1147,28 @@ describe("liveDirectVpc / planNoVpc (#1328)", () => {
|
|
|
1145
1147
|
expect(planNoVpc(false)).toEqual({ ok: true, flags: [], changes: [] });
|
|
1146
1148
|
});
|
|
1147
1149
|
});
|
|
1150
|
+
|
|
1151
|
+
describe("planMaxInstances (#1463)", () => {
|
|
1152
|
+
const described = (annotations: Record<string, string>) =>
|
|
1153
|
+
JSON.stringify({ spec: { template: { metadata: { annotations } } } });
|
|
1154
|
+
|
|
1155
|
+
it("reads the revision template's scale-out, null when unset", () => {
|
|
1156
|
+
expect(liveMaxInstances(described({ "autoscaling.knative.dev/maxScale": "100" }))).toBe(100);
|
|
1157
|
+
expect(liveMaxInstances(described({}))).toBeNull();
|
|
1158
|
+
});
|
|
1159
|
+
|
|
1160
|
+
it("lowers a value above the budget, an unset one included", () => {
|
|
1161
|
+
expect(planMaxInstances(100, 10)).toEqual({
|
|
1162
|
+
ok: true,
|
|
1163
|
+
flags: ["--max-instances=10"],
|
|
1164
|
+
changes: ["max instances: 100 → 10"],
|
|
1165
|
+
});
|
|
1166
|
+
expect(planMaxInstances(null, 10).flags).toEqual(["--max-instances=10"]);
|
|
1167
|
+
expect(planMaxInstances(Number.NaN, 10).flags).toEqual(["--max-instances=10"]);
|
|
1168
|
+
});
|
|
1169
|
+
|
|
1170
|
+
it("never raises what an operator lowered", () => {
|
|
1171
|
+
expect(planMaxInstances(3, 10).flags).toEqual([]);
|
|
1172
|
+
expect(planMaxInstances(10, 10).flags).toEqual([]);
|
|
1173
|
+
});
|
|
1174
|
+
});
|
package/src/stack-converge.ts
CHANGED
|
@@ -27,6 +27,8 @@
|
|
|
27
27
|
* timeout, in the same `services update`.
|
|
28
28
|
* - {@link planCpuIdle}: request-based CPU where the contract wants it
|
|
29
29
|
* (`SERVICE_CPU_IDLE`), in the same `services update`.
|
|
30
|
+
* - {@link planMaxInstances} (#1463): a gateway's scale-out down to what
|
|
31
|
+
* the connection budget allows, in the same `services update`.
|
|
30
32
|
*/
|
|
31
33
|
|
|
32
34
|
import { isIpLiteral } from "@caelo-cms/shared";
|
|
@@ -1219,6 +1221,34 @@ export function planCpuIdle(live: boolean, desired: boolean): RollAdditionsPlan
|
|
|
1219
1221
|
};
|
|
1220
1222
|
}
|
|
1221
1223
|
|
|
1224
|
+
/**
|
|
1225
|
+
* The most instances a described service may start: the revision template's
|
|
1226
|
+
* `autoscaling.knative.dev/maxScale` annotation. Null without one, which is
|
|
1227
|
+
* Cloud Run's default of 100.
|
|
1228
|
+
*/
|
|
1229
|
+
export function liveMaxInstances(serviceJson: string): number | null {
|
|
1230
|
+
const svc = JSON.parse(serviceJson) as {
|
|
1231
|
+
spec?: { template?: { metadata?: { annotations?: Record<string, string> } } };
|
|
1232
|
+
};
|
|
1233
|
+
const raw = svc.spec?.template?.metadata?.annotations?.["autoscaling.knative.dev/maxScale"];
|
|
1234
|
+
return raw === undefined ? null : Number(raw);
|
|
1235
|
+
}
|
|
1236
|
+
|
|
1237
|
+
/**
|
|
1238
|
+
* `--max-instances=<ceiling>` when the service may start more instances than
|
|
1239
|
+
* the connection budget has room for (#1463). Never raises the value: a roll
|
|
1240
|
+
* cannot see the stack's `gatewayMaxInstances`, and a lower live value is the
|
|
1241
|
+
* operator's. An unset or unreadable value counts as above the ceiling.
|
|
1242
|
+
*/
|
|
1243
|
+
export function planMaxInstances(live: number | null, ceiling: number): RollAdditionsPlan {
|
|
1244
|
+
if (live !== null && live <= ceiling) return { ok: true, flags: [], changes: [] };
|
|
1245
|
+
return {
|
|
1246
|
+
ok: true,
|
|
1247
|
+
flags: [`--max-instances=${ceiling}`],
|
|
1248
|
+
changes: [`max instances: ${live ?? "(default 100)"} → ${ceiling}`],
|
|
1249
|
+
};
|
|
1250
|
+
}
|
|
1251
|
+
|
|
1222
1252
|
/**
|
|
1223
1253
|
* Whether the service's revision template egresses into a VPC (Direct VPC
|
|
1224
1254
|
* egress, the stacks' `vpcAccess.networkInterfaces`).
|
|
@@ -150,7 +150,7 @@ describe("the gcp-firebase edge: a second Hosting site", () => {
|
|
|
150
150
|
expect(SITE.length).toBeLessThanOrEqual(30);
|
|
151
151
|
});
|
|
152
152
|
|
|
153
|
-
it("creates the site, one `**` rewrite to the staging gateway, the custom domain;
|
|
153
|
+
it("creates the site, one `**` rewrite to the staging gateway, the custom domain; keeps the old mapping while the DNS has not moved", async () => {
|
|
154
154
|
const { run, calls } = fakeGcloud({
|
|
155
155
|
...adminWith(LIVE_SITE),
|
|
156
156
|
"auth print-access-token": ok("tok\n"),
|
|
@@ -204,6 +204,7 @@ describe("the gcp-firebase edge: a second Hosting site", () => {
|
|
|
204
204
|
expect(r.dnsRecords).toEqual([
|
|
205
205
|
{ name: "staging.acme.com", type: "A", value: "199.36.158.100" },
|
|
206
206
|
]);
|
|
207
|
+
expect(r.domainMappingKept).toBe(true);
|
|
207
208
|
const version = requests.find((q) => q.method === "POST" && q.url.endsWith("/versions"));
|
|
208
209
|
expect(JSON.parse(version?.body ?? "{}")).toEqual({
|
|
209
210
|
config: {
|
|
@@ -224,10 +225,58 @@ describe("the gcp-firebase edge: a second Hosting site", () => {
|
|
|
224
225
|
q.method === "POST" && q.url.includes("customDomains?customDomainId=staging.acme.com"),
|
|
225
226
|
),
|
|
226
227
|
).toBe(true);
|
|
227
|
-
//
|
|
228
|
-
expect(calls
|
|
228
|
+
// #1455 — the mapping holds the host's certificate until the DNS moved.
|
|
229
|
+
expect(calls.some((c) => c.startsWith("beta run domain-mappings delete"))).toBe(false);
|
|
229
230
|
});
|
|
230
231
|
|
|
232
|
+
it.each([
|
|
233
|
+
["OWNERSHIP_ACTIVE", true],
|
|
234
|
+
// DNS moved, but Hosting does not serve the host yet.
|
|
235
|
+
["OWNERSHIP_PENDING", false],
|
|
236
|
+
])(
|
|
237
|
+
"#1455 — old mapping with DNS on the staging site, ownership %s",
|
|
238
|
+
async (ownershipState, gone) => {
|
|
239
|
+
const { run, calls } = fakeGcloud({
|
|
240
|
+
...adminWith(LIVE_SITE),
|
|
241
|
+
"auth print-access-token": ok("tok\n"),
|
|
242
|
+
"beta run domain-mappings describe": ok("staging.acme.com\n"),
|
|
243
|
+
"beta run domain-mappings delete": ok(),
|
|
244
|
+
});
|
|
245
|
+
const http: HttpFetch = async (url) => ({
|
|
246
|
+
ok: true,
|
|
247
|
+
status: 200,
|
|
248
|
+
text: async () =>
|
|
249
|
+
JSON.stringify({
|
|
250
|
+
...(url.includes("/customDomains/") && !gone
|
|
251
|
+
? {
|
|
252
|
+
requiredDnsUpdates: {
|
|
253
|
+
desired: [
|
|
254
|
+
{ records: [{ domainName: "staging.acme.com.", type: "TXT", rdata: "tok" }] },
|
|
255
|
+
],
|
|
256
|
+
},
|
|
257
|
+
}
|
|
258
|
+
: {}),
|
|
259
|
+
name: `sites/${SITE}/versions/v1`,
|
|
260
|
+
hostState: "HOST_ACTIVE",
|
|
261
|
+
ownershipState,
|
|
262
|
+
}),
|
|
263
|
+
});
|
|
264
|
+
const r = await ensureStagingGatewayEdge(
|
|
265
|
+
{
|
|
266
|
+
provider: "gcp-firebase",
|
|
267
|
+
projectId: "acme",
|
|
268
|
+
region: "europe-west1",
|
|
269
|
+
env: "production",
|
|
270
|
+
domain: "acme.com",
|
|
271
|
+
stagingHost: "staging.acme.com",
|
|
272
|
+
},
|
|
273
|
+
{ run, http },
|
|
274
|
+
);
|
|
275
|
+
expect(r.ok && r.domainMappingKept).toBe(!gone);
|
|
276
|
+
expect(calls.some((c) => c.startsWith("beta run domain-mappings delete"))).toBe(gone);
|
|
277
|
+
},
|
|
278
|
+
);
|
|
279
|
+
|
|
231
280
|
it("waits for the records Firebase works out after the custom domain is created", async () => {
|
|
232
281
|
const { run } = fakeGcloud({
|
|
233
282
|
...adminWith(LIVE_SITE),
|
|
@@ -375,6 +424,9 @@ describe("the gcp edge: the staging host's own rule on the load balancer", () =>
|
|
|
375
424
|
expect(r.dnsRecords).toEqual([
|
|
376
425
|
{ name: "staging.acme.com", type: "A", value: "136.81.196.111" },
|
|
377
426
|
]);
|
|
427
|
+
expect(calls.find((c) => c.startsWith("compute backend-services create"))).toContain(
|
|
428
|
+
"--protocol=HTTPS --port-name=http",
|
|
429
|
+
);
|
|
378
430
|
expect(calls.find((c) => c.startsWith("compute backend-services create"))).not.toContain(
|
|
379
431
|
"--security-policy",
|
|
380
432
|
);
|
|
@@ -11,8 +11,9 @@
|
|
|
11
11
|
* - `gcp-firebase` (E13 a): a second Firebase Hosting site with one `**`
|
|
12
12
|
* rewrite to the staging gateway, the staging host as that site's
|
|
13
13
|
* custom domain. The Cloud Run domain mapping that sent the staging
|
|
14
|
-
* host to the old gateway service (#650) is deleted
|
|
15
|
-
*
|
|
14
|
+
* host to the old gateway service (#650) is deleted once the host's DNS
|
|
15
|
+
* points at the new site (#1455): nothing may lead to the staged files
|
|
16
|
+
* but the gate.
|
|
16
17
|
* - `gcp`: the staging host gets its own host rule on the site's load
|
|
17
18
|
* balancer, routed in full to the staging gateway's serverless NEG and
|
|
18
19
|
* backend (the gateway's Cloud Armor policy as an extra layer, E3), and
|
|
@@ -33,12 +34,7 @@
|
|
|
33
34
|
*/
|
|
34
35
|
|
|
35
36
|
import { createHash } from "node:crypto";
|
|
36
|
-
import {
|
|
37
|
-
DB_PUBLIC_POOL_MAX_ENV,
|
|
38
|
-
DEFAULT_STAGING_GATEWAY_MAX_INSTANCES,
|
|
39
|
-
GATEWAY_POOL_MAX,
|
|
40
|
-
isIpLiteral,
|
|
41
|
-
} from "@caelo-cms/shared";
|
|
37
|
+
import { DEFAULT_STAGING_GATEWAY_MAX_INSTANCES, isIpLiteral } from "@caelo-cms/shared";
|
|
42
38
|
import { gcloud as defaultGcloud, isGcloudNotFound } from "./gcloud.js";
|
|
43
39
|
import { type GcloudRunner, realSleep, runWithRetry, type Sleep } from "./gcloud-retry.js";
|
|
44
40
|
import {
|
|
@@ -50,11 +46,16 @@ import {
|
|
|
50
46
|
stagingGatewayEdgeNames,
|
|
51
47
|
stagingGatewayServiceAccountEmail,
|
|
52
48
|
} from "./gcp-names.js";
|
|
49
|
+
import { GATEWAY_POOL_ENV } from "./pool-budget-stack.js";
|
|
53
50
|
import {
|
|
54
51
|
type EnsureOutcome,
|
|
55
52
|
ensureStagingGatewayServiceAccount,
|
|
56
53
|
type HttpFetch,
|
|
57
54
|
} from "./runtime-secrets.js";
|
|
55
|
+
import {
|
|
56
|
+
repairServerlessBackendPort,
|
|
57
|
+
SERVERLESS_BACKEND_CREATE_FLAGS,
|
|
58
|
+
} from "./serverless-backend.js";
|
|
58
59
|
import {
|
|
59
60
|
type CloudRunEnvVar,
|
|
60
61
|
cloudRunServicePrefix,
|
|
@@ -141,7 +142,7 @@ export function stagingGatewayDeployArgs(inputs: StagingGatewayServiceInputs): s
|
|
|
141
142
|
...env.flatMap((e) => ("value" in e ? [`${e.name}=${e.value}`] : [])),
|
|
142
143
|
// The connection budget's share of one instance (pool-budget.ts): the
|
|
143
144
|
// stacks set the same on the live gateway.
|
|
144
|
-
`${
|
|
145
|
+
...GATEWAY_POOL_ENV.map((e) => `${e.name}=${e.value}`),
|
|
145
146
|
];
|
|
146
147
|
const secrets = env.flatMap((e) =>
|
|
147
148
|
"valueSource" in e
|
|
@@ -471,6 +472,11 @@ export type StagingEdgeResult =
|
|
|
471
472
|
readonly done: string[];
|
|
472
473
|
/** The records the staging host needs at the registrar (Settings → Updates shows them too). */
|
|
473
474
|
readonly dnsRecords: StagingDnsRecord[];
|
|
475
|
+
/**
|
|
476
|
+
* #1455 — the host's DNS still points at its Cloud Run domain mapping,
|
|
477
|
+
* so the mapping stayed: see {@link settleStagingDomainMapping}.
|
|
478
|
+
*/
|
|
479
|
+
readonly domainMappingKept: boolean;
|
|
474
480
|
}
|
|
475
481
|
| { readonly ok: false; readonly error: string; readonly done: string[] };
|
|
476
482
|
|
|
@@ -530,6 +536,18 @@ export function isFirebaseStagingConfig(
|
|
|
530
536
|
);
|
|
531
537
|
}
|
|
532
538
|
|
|
539
|
+
/**
|
|
540
|
+
* Whether Hosting serves the host, in its own words: the check #1455 turns
|
|
541
|
+
* on, the same one Settings → Updates uses (`readStagingHostDns`). The DNS
|
|
542
|
+
* pointing at Hosting (`HOST_ACTIVE`, also for a CNAME to the site's `web.app`
|
|
543
|
+
* name: searchviu-website, 2026-11-05) is not enough while ownership is
|
|
544
|
+
* pending.
|
|
545
|
+
*/
|
|
546
|
+
function firebaseHostActive(customDomain: unknown): boolean {
|
|
547
|
+
const domain = customDomain as { hostState?: string; ownershipState?: string } | null;
|
|
548
|
+
return domain?.hostState === "HOST_ACTIVE" && domain.ownershipState === "OWNERSHIP_ACTIVE";
|
|
549
|
+
}
|
|
550
|
+
|
|
533
551
|
/** The DNS records a Firebase custom domain asks for (`requiredDnsUpdates.desired`). */
|
|
534
552
|
export function firebaseDesiredRecords(customDomain: unknown): StagingDnsRecord[] {
|
|
535
553
|
const desired = (
|
|
@@ -668,7 +686,8 @@ async function ensureFirebaseStagingSite(
|
|
|
668
686
|
// v0.11.16, 2026-11-04).
|
|
669
687
|
const sleep = deps.sleep ?? ((ms: number) => new Promise<void>((r) => setTimeout(r, ms)));
|
|
670
688
|
let dnsRecords = firebaseDesiredRecords(domain.json);
|
|
671
|
-
|
|
689
|
+
let hostActive = firebaseHostActive(domain.json);
|
|
690
|
+
for (let i = 0; !hostActive && dnsRecords.length === 0 && i < FIREBASE_DNS_POLLS; i++) {
|
|
672
691
|
await sleep(FIREBASE_DNS_POLL_MS);
|
|
673
692
|
const again = await call(domainPath);
|
|
674
693
|
if (!again.ok) {
|
|
@@ -677,32 +696,48 @@ async function ensureFirebaseStagingSite(
|
|
|
677
696
|
);
|
|
678
697
|
}
|
|
679
698
|
dnsRecords = firebaseDesiredRecords(again.json);
|
|
699
|
+
hostActive = firebaseHostActive(again.json);
|
|
680
700
|
}
|
|
681
|
-
if (
|
|
701
|
+
if (!hostActive && dnsRecords.length === 0) {
|
|
682
702
|
return fail(
|
|
683
703
|
`Firebase Hosting has not said which DNS records ${t.stagingHost} needs after ${(FIREBASE_DNS_POLLS * FIREBASE_DNS_POLL_MS) / 1000} s. Nothing is wrong with what was set up; re-run the installer to print them.`,
|
|
684
704
|
);
|
|
685
705
|
}
|
|
686
706
|
|
|
687
707
|
// 4. The old route: the Cloud Run domain mapping (#650) to the service
|
|
688
|
-
// that is now the MCP-Auth-Proxy.
|
|
689
|
-
|
|
690
|
-
const mapping = await deleteStagingDomainMapping(t, run);
|
|
708
|
+
// that is now the MCP-Auth-Proxy.
|
|
709
|
+
const mapping = await settleStagingDomainMapping(t, hostActive, run);
|
|
691
710
|
if (!mapping.ok) return fail(mapping.error);
|
|
692
|
-
if (mapping.deleted)
|
|
711
|
+
if (mapping.outcome === "deleted") {
|
|
712
|
+
done.push(`deleted the Cloud Run domain mapping of ${t.stagingHost}`);
|
|
713
|
+
}
|
|
693
714
|
|
|
694
|
-
return { ok: true, done, dnsRecords };
|
|
715
|
+
return { ok: true, done, dnsRecords, domainMappingKept: mapping.outcome === "kept" };
|
|
695
716
|
}
|
|
696
717
|
|
|
697
718
|
/**
|
|
698
|
-
*
|
|
699
|
-
*
|
|
700
|
-
*
|
|
719
|
+
* The staging host's Cloud Run domain mapping (#650), if there is one: gone
|
|
720
|
+
* once the host's DNS points at Hosting, kept until then (#1455).
|
|
721
|
+
*
|
|
722
|
+
* While the host is still a CNAME to `ghs.googlehosted.com` the mapping holds
|
|
723
|
+
* its certificate, and Hosting can issue none, so deleting it turns the host
|
|
724
|
+
* into a TLS error (0.11.17 on searchviu-website). The mapping leads to the
|
|
725
|
+
* MCP-Auth-Proxy, which forwards nothing (#1331) and answers its fixed 404,
|
|
726
|
+
* so keeping it opens no way around the staging gate. It cannot be pointed at
|
|
727
|
+
* the staging gateway instead: Cloud Run refuses a second mapping of a host
|
|
728
|
+
* in the same region even with `--force-override`, delete + create drops the
|
|
729
|
+
* certificate, and create needs a verified owner of the domain, which the
|
|
730
|
+
* converge job's account is not (all tried on caelo-p0-tmp-1104, 2026-11-05).
|
|
731
|
+
* The next converge after the DNS change deletes it.
|
|
732
|
+
*
|
|
733
|
+
* Needs the gcloud `beta` component; without it the mapping is reported as
|
|
734
|
+
* unknown rather than guessed away.
|
|
701
735
|
*/
|
|
702
|
-
async function
|
|
736
|
+
async function settleStagingDomainMapping(
|
|
703
737
|
t: StagingGatewayTarget,
|
|
738
|
+
hostActive: boolean,
|
|
704
739
|
run: GcloudRunner,
|
|
705
|
-
): Promise<{ ok: true;
|
|
740
|
+
): Promise<{ ok: true; outcome: "none" | "kept" | "deleted" } | { ok: false; error: string }> {
|
|
706
741
|
const scope = [`--domain=${t.stagingHost}`, `--region=${t.region}`, `--project=${t.projectId}`];
|
|
707
742
|
const described = await run([
|
|
708
743
|
"beta",
|
|
@@ -714,16 +749,17 @@ async function deleteStagingDomainMapping(
|
|
|
714
749
|
]);
|
|
715
750
|
if (!described.ok) {
|
|
716
751
|
if (isGcloudNotFound(described.stderr)) {
|
|
717
|
-
return { ok: true,
|
|
752
|
+
return { ok: true, outcome: "none" };
|
|
718
753
|
}
|
|
719
754
|
return {
|
|
720
755
|
ok: false,
|
|
721
756
|
error: `read the Cloud Run domain mapping of ${t.stagingHost}: ${described.stderr.trim()}`,
|
|
722
757
|
};
|
|
723
758
|
}
|
|
759
|
+
if (!hostActive) return { ok: true, outcome: "kept" };
|
|
724
760
|
const deleted = await run(["beta", "run", "domain-mappings", "delete", ...scope, "--quiet"]);
|
|
725
761
|
return deleted.ok
|
|
726
|
-
? { ok: true,
|
|
762
|
+
? { ok: true, outcome: "deleted" }
|
|
727
763
|
: {
|
|
728
764
|
ok: false,
|
|
729
765
|
error: `delete the Cloud Run domain mapping of ${t.stagingHost}: ${deleted.stderr.trim()}`,
|
|
@@ -884,8 +920,12 @@ async function ensureGcpEdge(
|
|
|
884
920
|
project,
|
|
885
921
|
"--format=json",
|
|
886
922
|
]);
|
|
887
|
-
let backendJson: {
|
|
888
|
-
|
|
923
|
+
let backendJson: {
|
|
924
|
+
selfLink?: string;
|
|
925
|
+
securityPolicy?: string;
|
|
926
|
+
portName?: string;
|
|
927
|
+
backends?: { group?: string }[];
|
|
928
|
+
} = {};
|
|
889
929
|
if (!backend.ok) {
|
|
890
930
|
if (!isGcloudNotFound(backend.stderr)) {
|
|
891
931
|
return fail(`describe ${names.backend}: ${backend.stderr.trim()}`);
|
|
@@ -898,7 +938,7 @@ async function ensureGcpEdge(
|
|
|
898
938
|
"--global",
|
|
899
939
|
project,
|
|
900
940
|
"--load-balancing-scheme=EXTERNAL_MANAGED",
|
|
901
|
-
|
|
941
|
+
...SERVERLESS_BACKEND_CREATE_FLAGS,
|
|
902
942
|
"--format=json",
|
|
903
943
|
"--quiet",
|
|
904
944
|
]);
|
|
@@ -909,6 +949,13 @@ async function ensureGcpEdge(
|
|
|
909
949
|
} else {
|
|
910
950
|
backendJson = (safeJson(backend.stdout) ?? {}) as typeof backendJson;
|
|
911
951
|
}
|
|
952
|
+
const port = await repairServerlessBackendPort(
|
|
953
|
+
run,
|
|
954
|
+
{ name: names.backend, portName: backendJson.portName },
|
|
955
|
+
project,
|
|
956
|
+
);
|
|
957
|
+
if (port.error) return fail(port.error);
|
|
958
|
+
if (port.repaired) done.push(`set ${names.backend}'s port name to http`);
|
|
912
959
|
// `backend-services create` has no --security-policy: `update` attaches it,
|
|
913
960
|
// here and on a backend an earlier run left without one. The URL map is
|
|
914
961
|
// only pointed at this backend afterwards, so it is never served unguarded.
|
|
@@ -1089,7 +1136,12 @@ async function ensureGcpEdge(
|
|
|
1089
1136
|
`expected one external address for ${t.stagingHost}, found ${ips.join(", ") || "none"}`,
|
|
1090
1137
|
);
|
|
1091
1138
|
}
|
|
1092
|
-
return {
|
|
1139
|
+
return {
|
|
1140
|
+
ok: true,
|
|
1141
|
+
done,
|
|
1142
|
+
dnsRecords: [{ name: t.stagingHost, type: "A", value: ip }],
|
|
1143
|
+
domainMappingKept: false,
|
|
1144
|
+
};
|
|
1093
1145
|
}
|
|
1094
1146
|
|
|
1095
1147
|
/** An OAuth access token as gcloud prints one: base64url-ish characters only. */
|
package/src/upgrade/app-roll.ts
CHANGED
|
@@ -32,6 +32,7 @@ import {
|
|
|
32
32
|
stagingGatewayServiceAccountEmail,
|
|
33
33
|
} from "../gcp-names.js";
|
|
34
34
|
import type { ImageDigests } from "../install-state.js";
|
|
35
|
+
import { GATEWAY_MAX_INSTANCES_CEILING, GATEWAY_POOL_ENV } from "../pool-budget-stack.js";
|
|
35
36
|
import {
|
|
36
37
|
adminMediaVolume,
|
|
37
38
|
CLOUD_RUN_SLUGS,
|
|
@@ -54,11 +55,13 @@ import {
|
|
|
54
55
|
liveContainerMemory,
|
|
55
56
|
liveCpuIdle,
|
|
56
57
|
liveDirectVpc,
|
|
58
|
+
liveMaxInstances,
|
|
57
59
|
liveTimeoutSeconds,
|
|
58
60
|
liveVolumes,
|
|
59
61
|
planAdminMemory,
|
|
60
62
|
planContractEnv,
|
|
61
63
|
planCpuIdle,
|
|
64
|
+
planMaxInstances,
|
|
62
65
|
planMediaVolume,
|
|
63
66
|
planNoVpc,
|
|
64
67
|
planRequestTimeout,
|
|
@@ -142,6 +145,8 @@ export interface ServicePlan {
|
|
|
142
145
|
readonly liveCpuIdle: boolean;
|
|
143
146
|
/** Whether the service egresses into the install's VPC now. */
|
|
144
147
|
readonly liveDirectVpc: boolean;
|
|
148
|
+
/** Most instances the service may start now (null = Cloud Run's default). */
|
|
149
|
+
readonly liveMaxInstances: number | null;
|
|
145
150
|
}
|
|
146
151
|
|
|
147
152
|
/** A service plan plus the changes its roll applies. */
|
|
@@ -151,7 +156,9 @@ export interface RollPlan extends ServicePlan {
|
|
|
151
156
|
/**
|
|
152
157
|
* #553 — e.g. `--memory=2Gi` when the admin runs below the stack default;
|
|
153
158
|
* #806 — `--timeout=3600` when the gateway runs below its contract timeout;
|
|
154
|
-
* `--cpu-throttling` when the contract wants request-based CPU
|
|
159
|
+
* `--cpu-throttling` when the contract wants request-based CPU;
|
|
160
|
+
* #1463 — `--max-instances=10` when a gateway may start more instances than
|
|
161
|
+
* the connection budget has room for.
|
|
155
162
|
*/
|
|
156
163
|
readonly resourceFlags: readonly string[];
|
|
157
164
|
readonly resourceChanges: readonly string[];
|
|
@@ -250,6 +257,7 @@ export async function planAppRoll(
|
|
|
250
257
|
liveTimeout: liveTimeoutSeconds(json),
|
|
251
258
|
liveCpuIdle: liveCpuIdle(json),
|
|
252
259
|
liveDirectVpc: liveDirectVpc(json),
|
|
260
|
+
liveMaxInstances: liveMaxInstances(json),
|
|
253
261
|
});
|
|
254
262
|
}
|
|
255
263
|
const env = planEnv(install, services, {});
|
|
@@ -320,16 +328,24 @@ export async function planAppRoll(
|
|
|
320
328
|
// leaves the VPC in the same revision that drops its database env.
|
|
321
329
|
const vpc = SERVICE_VPC_EGRESS[s.slug] ? null : planNoVpc(s.liveDirectVpc);
|
|
322
330
|
const vpcFlags = vpc?.ok ? vpc.flags : [];
|
|
331
|
+
// #1463 — every gateway instance holds three of its login's connections,
|
|
332
|
+
// so the scale-out rides the roll with the pool env (planEnv below).
|
|
333
|
+
const scale =
|
|
334
|
+
s.slug === "gateway" || s.slug === "staging-gateway"
|
|
335
|
+
? planMaxInstances(s.liveMaxInstances, GATEWAY_MAX_INSTANCES_CEILING[s.slug])
|
|
336
|
+
: null;
|
|
337
|
+
const scaleFlags = scale?.ok ? scale.flags : [];
|
|
323
338
|
return {
|
|
324
339
|
...s,
|
|
325
340
|
envFlags: env.services[s.slug].flags,
|
|
326
341
|
envChanges: env.services[s.slug].changes,
|
|
327
|
-
resourceFlags: [...memoryFlags, ...timeoutFlags, ...cpuFlags, ...vpcFlags],
|
|
342
|
+
resourceFlags: [...memoryFlags, ...timeoutFlags, ...cpuFlags, ...vpcFlags, ...scaleFlags],
|
|
328
343
|
resourceChanges: [
|
|
329
344
|
...memoryFlags.map((f) => `${s.liveMemory ?? "(default)"} → ${f}`),
|
|
330
345
|
...(timeout?.ok ? timeout.changes : []),
|
|
331
346
|
...(cpu.ok ? cpu.changes : []),
|
|
332
347
|
...(vpc?.ok ? vpc.changes : []),
|
|
348
|
+
...(scale?.ok ? scale.changes : []),
|
|
333
349
|
],
|
|
334
350
|
volumeFlags: [...(s.slug === "admin" ? media.flags : []), ...secretFiles[s.slug].flags],
|
|
335
351
|
volumeChanges: [...(s.slug === "admin" ? media.changes : []), ...secretFiles[s.slug].changes],
|
|
@@ -370,6 +386,14 @@ function planEnv(
|
|
|
370
386
|
const deployed = Object.fromEntries(
|
|
371
387
|
services.map((s) => [s.slug, { serviceName: s.serviceName, liveEnv: s.liveEnv }]),
|
|
372
388
|
) as Record<RollSlug, DeployedService>;
|
|
389
|
+
// #1463 — the gateways' pool env is the stacks', outside the contract: it
|
|
390
|
+
// used to reach an install only through `pulumi up`, so an install from
|
|
391
|
+
// before the budget never got it.
|
|
392
|
+
const extraEnv = {
|
|
393
|
+
...adjust.extraEnv,
|
|
394
|
+
gateway: [...(adjust.extraEnv?.gateway ?? []), ...GATEWAY_POOL_ENV],
|
|
395
|
+
"staging-gateway": [...(adjust.extraEnv?.["staging-gateway"] ?? []), ...GATEWAY_POOL_ENV],
|
|
396
|
+
};
|
|
373
397
|
return planContractEnv(
|
|
374
398
|
{
|
|
375
399
|
provider: install.provider,
|
|
@@ -382,7 +406,7 @@ function planEnv(
|
|
|
382
406
|
deployed,
|
|
383
407
|
{
|
|
384
408
|
leaveUntouched: adjust.leaveUntouched ?? [],
|
|
385
|
-
|
|
409
|
+
extraEnv,
|
|
386
410
|
...(adjust.databaseHost ? { databaseHost: adjust.databaseHost } : {}),
|
|
387
411
|
},
|
|
388
412
|
);
|
package/src/upgrade/converge.ts
CHANGED
|
@@ -38,6 +38,7 @@ import {
|
|
|
38
38
|
moveServicesToDnsHost,
|
|
39
39
|
} from "../cloudsql-tls.js";
|
|
40
40
|
import { ensureConvergeJob } from "../converge-job-setup.js";
|
|
41
|
+
import { ensureGatewayArmorRules } from "../gateway-armor.js";
|
|
41
42
|
import { findSqlInstance, planPublicRoleSwitch } from "../gateway-credentials.js";
|
|
42
43
|
import type { GcloudRunner, Sleep } from "../gcloud-retry.js";
|
|
43
44
|
import { schedulerServiceAccountEmail, upgraderServiceAccountEmail } from "../gcp-names.js";
|
|
@@ -451,13 +452,35 @@ export function startConverge(
|
|
|
451
452
|
incomplete = true;
|
|
452
453
|
}
|
|
453
454
|
|
|
455
|
+
async function gatewayArmor(): Promise<void> {
|
|
456
|
+
// #1339 — on `gcp` the gateway's Cloud Armor policy gets its per-path
|
|
457
|
+
// rules (gateway-edge.ts). An extra layer over the gateway's own limits
|
|
458
|
+
// (E3 of #763), so a failure warns; the old rules stay in force.
|
|
459
|
+
if (install.provider !== "gcp") return;
|
|
460
|
+
const s = r.step("Bringing the gateway's Cloud Armor rules up to date...");
|
|
461
|
+
const armor = await ensureGatewayArmorRules(
|
|
462
|
+
{ projectId: install.projectId, env: install.env },
|
|
463
|
+
runDeps,
|
|
464
|
+
);
|
|
465
|
+
for (const line of armor.done) r.info(` ${line}`);
|
|
466
|
+
if (armor.ok) {
|
|
467
|
+
s.done(`Cloud Armor rules of ${armor.policy} in place`);
|
|
468
|
+
return;
|
|
469
|
+
}
|
|
470
|
+
s.warned(`Cloud Armor rules not updated: ${armor.error}`);
|
|
471
|
+
r.warn(
|
|
472
|
+
"The upgrade continues; the gateway keeps its own rate limits, and the edge keeps the old catch-all ban until every new rule is in (each rule is replaced in place, never removed first). Re-run upgrade once the cause is fixed.",
|
|
473
|
+
);
|
|
474
|
+
incomplete = true;
|
|
475
|
+
}
|
|
476
|
+
|
|
454
477
|
async function stagingEdge(): Promise<void> {
|
|
455
478
|
// #1330 — route the staging host to the staging gateway and nowhere
|
|
456
479
|
// else: gcp-firebase's second Hosting site (and the old Cloud Run domain
|
|
457
|
-
// mapping deleted), gcp's host rule, backend
|
|
458
|
-
// (staging-gateway-setup.ts). Only staging depends on
|
|
459
|
-
// warns; the records the staging host needs are printed
|
|
460
|
-
// Updates shows them too).
|
|
480
|
+
// mapping deleted once the DNS moved, #1455), gcp's host rule, backend
|
|
481
|
+
// and certificate (staging-gateway-setup.ts). Only staging depends on
|
|
482
|
+
// it, so a failure warns; the records the staging host needs are printed
|
|
483
|
+
// (Settings → Updates shows them too, verify_dns_records checks them).
|
|
461
484
|
const s = r.step(`Routing the staging host ${install.stagingHost} to the staging gateway...`);
|
|
462
485
|
const edge = await ensureStagingGatewayEdge(
|
|
463
486
|
{
|
|
@@ -479,6 +502,11 @@ export function startConverge(
|
|
|
479
502
|
);
|
|
480
503
|
for (const d of edge.dnsRecords) r.info(` ${d.name} ${d.type} ${d.value}`);
|
|
481
504
|
}
|
|
505
|
+
if (edge.domainMappingKept) {
|
|
506
|
+
r.warn(
|
|
507
|
+
`${install.stagingHost} still points at its old Cloud Run route, so this update keeps that route and the address keeps its certificate. Once the services have rolled it answers 404 until the records above are set; then the staging site is back. The next update that changes the cloud setup removes the old route.`,
|
|
508
|
+
);
|
|
509
|
+
}
|
|
482
510
|
return;
|
|
483
511
|
}
|
|
484
512
|
s.warned(`The staging host is not routed yet: ${edge.error}`);
|
|
@@ -872,6 +900,7 @@ export function startConverge(
|
|
|
872
900
|
await auditJob();
|
|
873
901
|
await captureJob();
|
|
874
902
|
await remoteMcpEdge();
|
|
903
|
+
await gatewayArmor();
|
|
875
904
|
await stagingEdge();
|
|
876
905
|
return true;
|
|
877
906
|
},
|