@pattform/api-kit 2.6.9 → 2.8.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/dist/GcpProjectComponent.js +7 -1
- package/dist/HostedApiComponent.d.ts +73 -0
- package/dist/HostedApiComponent.js +97 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +3 -1
- package/package.json +1 -1
|
@@ -60,7 +60,8 @@ class GcpProjectComponent extends pulumi.ComponentResource {
|
|
|
60
60
|
}
|
|
61
61
|
}
|
|
62
62
|
exports.GcpProjectComponent = GcpProjectComponent;
|
|
63
|
-
// Backend defaults: Cloud Run + Firestore + Storage + Artifact Registry
|
|
63
|
+
// Backend defaults: Cloud Run + Firestore + Storage + Artifact Registry, plus
|
|
64
|
+
// Firebase Hosting, which HostedApiComponent uses as the API edge.
|
|
64
65
|
const DEFAULT_SERVICES = [
|
|
65
66
|
"run.googleapis.com",
|
|
66
67
|
"firestore.googleapis.com",
|
|
@@ -68,12 +69,17 @@ const DEFAULT_SERVICES = [
|
|
|
68
69
|
"storage.googleapis.com",
|
|
69
70
|
"iam.googleapis.com",
|
|
70
71
|
"iamcredentials.googleapis.com",
|
|
72
|
+
"firebase.googleapis.com",
|
|
73
|
+
"firebasehosting.googleapis.com",
|
|
71
74
|
];
|
|
72
75
|
// Project roles the deploy SA needs to create those resources from Pulumi.
|
|
76
|
+
// firebasehosting.admin lets it stand up the HostedApiComponent edge (site,
|
|
77
|
+
// version, release, custom domain); without it HostingSite creation 403s.
|
|
73
78
|
const DEFAULT_DEPLOY_ROLES = [
|
|
74
79
|
"roles/run.admin",
|
|
75
80
|
"roles/datastore.owner",
|
|
76
81
|
"roles/storage.admin",
|
|
77
82
|
"roles/artifactregistry.admin",
|
|
78
83
|
"roles/iam.serviceAccountUser",
|
|
84
|
+
"roles/firebasehosting.admin",
|
|
79
85
|
];
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import * as pulumi from "@pulumi/pulumi";
|
|
2
|
+
import * as gcp from "@pulumi/gcp";
|
|
3
|
+
/**
|
|
4
|
+
* HostedApiComponent
|
|
5
|
+
* Fronts one or more Cloud Run services with a Firebase Hosting site: custom
|
|
6
|
+
* domain, managed TLS, path-based routing and a CDN, at no fixed monthly cost.
|
|
7
|
+
*
|
|
8
|
+
* Replaces ApiComponent, which put an AWS API Gateway in front of Cloud Run.
|
|
9
|
+
* That cost ~115ms p50 on every request (measured Sydney-to-Sydney) and, more
|
|
10
|
+
* importantly for the platform, the obvious GCP replacement (a global external
|
|
11
|
+
* Application Load Balancer) bills a forwarding rule by the hour whether or not
|
|
12
|
+
* traffic arrives. api-kit components are vended per client, so any fixed floor
|
|
13
|
+
* multiplies across every client. Firebase Hosting has none.
|
|
14
|
+
*
|
|
15
|
+
* Hosting forwards the FULL request path to the backend: a rewrite matching
|
|
16
|
+
* "/builder/**" delivers "/builder/teams" to Cloud Run, it does not strip the
|
|
17
|
+
* prefix the way an API Gateway ApiMapping did. Give each service a matching
|
|
18
|
+
* context path (Spring: SERVER_SERVLET_CONTEXT_PATH=/builder) so its routes line
|
|
19
|
+
* up. Verified against a GraalVM native image: the env var binds at runtime and
|
|
20
|
+
* leaves a separate management port untouched, so health probes keep working.
|
|
21
|
+
*/
|
|
22
|
+
export declare class HostedApiComponent extends pulumi.ComponentResource {
|
|
23
|
+
private readonly site;
|
|
24
|
+
private readonly version;
|
|
25
|
+
private readonly release;
|
|
26
|
+
private readonly customDomain?;
|
|
27
|
+
/** Public base URL callers should use, e.g. https://api.partplanner.io */
|
|
28
|
+
readonly endpoint: pulumi.Output<string>;
|
|
29
|
+
/** Firebase-assigned default URL, useful for smoke testing before DNS moves. */
|
|
30
|
+
readonly defaultUrl: pulumi.Output<string>;
|
|
31
|
+
/**
|
|
32
|
+
* DNS records Firebase needs before it will serve the custom domain and
|
|
33
|
+
* issue a certificate. Empty once the domain is fully verified. Surfaced
|
|
34
|
+
* rather than created here because the values are only known after Firebase
|
|
35
|
+
* inspects the domain, the same reason AppComponent reports rather than
|
|
36
|
+
* creates its validation records.
|
|
37
|
+
*/
|
|
38
|
+
readonly requiredDnsUpdates: pulumi.Output<gcp.types.output.firebase.HostingCustomDomainRequiredDnsUpdate[]>;
|
|
39
|
+
constructor(name: string, args: HostedApiComponentArgs, opts?: pulumi.ComponentResourceOptions);
|
|
40
|
+
}
|
|
41
|
+
export interface HostedApiRoute {
|
|
42
|
+
/**
|
|
43
|
+
* Leading path segment that selects this service, without slashes, e.g.
|
|
44
|
+
* "builder". The service receives the full path INCLUDING this prefix, so
|
|
45
|
+
* it must be mounted at a matching context path.
|
|
46
|
+
*/
|
|
47
|
+
pathPrefix: string;
|
|
48
|
+
/** Cloud Run service name, e.g. "builder-prod". */
|
|
49
|
+
serviceName: pulumi.Input<string>;
|
|
50
|
+
/** Defaults to the component's region. */
|
|
51
|
+
region?: pulumi.Input<string>;
|
|
52
|
+
}
|
|
53
|
+
export interface HostedApiComponentArgs {
|
|
54
|
+
/**
|
|
55
|
+
* Custom domain to serve on, e.g. "api.partplanner.io". Omit to use only the
|
|
56
|
+
* Firebase-assigned URL, which is handy for a first deploy before DNS moves.
|
|
57
|
+
*/
|
|
58
|
+
apiDomain?: pulumi.Input<string>;
|
|
59
|
+
/** One entry per Cloud Run service behind this domain. */
|
|
60
|
+
routes: HostedApiRoute[];
|
|
61
|
+
/** Hosting site id. Defaults to the component name. Must be globally unique. */
|
|
62
|
+
siteId?: pulumi.Input<string>;
|
|
63
|
+
/** Defaults to gcp:project. */
|
|
64
|
+
project?: pulumi.Input<string>;
|
|
65
|
+
/** Default Cloud Run region for routes that do not set their own. Defaults to gcp:region. */
|
|
66
|
+
region?: pulumi.Input<string>;
|
|
67
|
+
/**
|
|
68
|
+
* Block the deploy until Firebase has verified the domain's DNS. Defaults to
|
|
69
|
+
* false so the first deploy can report the records it needs. See
|
|
70
|
+
* requiredDnsUpdates.
|
|
71
|
+
*/
|
|
72
|
+
waitDnsVerification?: pulumi.Input<boolean>;
|
|
73
|
+
}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.HostedApiComponent = void 0;
|
|
4
|
+
const pulumi = require("@pulumi/pulumi");
|
|
5
|
+
const gcp = require("@pulumi/gcp");
|
|
6
|
+
/**
|
|
7
|
+
* HostedApiComponent
|
|
8
|
+
* Fronts one or more Cloud Run services with a Firebase Hosting site: custom
|
|
9
|
+
* domain, managed TLS, path-based routing and a CDN, at no fixed monthly cost.
|
|
10
|
+
*
|
|
11
|
+
* Replaces ApiComponent, which put an AWS API Gateway in front of Cloud Run.
|
|
12
|
+
* That cost ~115ms p50 on every request (measured Sydney-to-Sydney) and, more
|
|
13
|
+
* importantly for the platform, the obvious GCP replacement (a global external
|
|
14
|
+
* Application Load Balancer) bills a forwarding rule by the hour whether or not
|
|
15
|
+
* traffic arrives. api-kit components are vended per client, so any fixed floor
|
|
16
|
+
* multiplies across every client. Firebase Hosting has none.
|
|
17
|
+
*
|
|
18
|
+
* Hosting forwards the FULL request path to the backend: a rewrite matching
|
|
19
|
+
* "/builder/**" delivers "/builder/teams" to Cloud Run, it does not strip the
|
|
20
|
+
* prefix the way an API Gateway ApiMapping did. Give each service a matching
|
|
21
|
+
* context path (Spring: SERVER_SERVLET_CONTEXT_PATH=/builder) so its routes line
|
|
22
|
+
* up. Verified against a GraalVM native image: the env var binds at runtime and
|
|
23
|
+
* leaves a separate management port untouched, so health probes keep working.
|
|
24
|
+
*/
|
|
25
|
+
class HostedApiComponent extends pulumi.ComponentResource {
|
|
26
|
+
constructor(name, args, opts) {
|
|
27
|
+
var _a, _b, _c, _d;
|
|
28
|
+
super("custom:pattform:HostedApiComponent", name, args, opts);
|
|
29
|
+
const gcpConfig = new pulumi.Config("gcp");
|
|
30
|
+
const defaultRegion = (_a = args.region) !== null && _a !== void 0 ? _a : gcpConfig.require("region");
|
|
31
|
+
const project = (_b = args.project) !== null && _b !== void 0 ? _b : gcpConfig.get("project");
|
|
32
|
+
if (args.routes.length === 0) {
|
|
33
|
+
throw new Error(`HostedApiComponent "${name}" needs at least one route.`);
|
|
34
|
+
}
|
|
35
|
+
const duplicatePrefix = args.routes
|
|
36
|
+
.map(r => r.pathPrefix.replace(/^\/+|\/+$/g, ""))
|
|
37
|
+
.find((prefix, i, all) => all.indexOf(prefix) !== i);
|
|
38
|
+
if (duplicatePrefix) {
|
|
39
|
+
throw new Error(`HostedApiComponent "${name}" has two routes for path prefix "${duplicatePrefix}". ` +
|
|
40
|
+
`Hosting applies the first matching rewrite, so the second would never be reached.`);
|
|
41
|
+
}
|
|
42
|
+
this.site = new gcp.firebase.HostingSite(`hosted-api-${name}-site`, {
|
|
43
|
+
project: project,
|
|
44
|
+
siteId: (_c = args.siteId) !== null && _c !== void 0 ? _c : name,
|
|
45
|
+
}, { parent: this });
|
|
46
|
+
// One rewrite per service. Trailing "/**" so the prefix and everything
|
|
47
|
+
// under it routes to that service; Hosting matches these in order.
|
|
48
|
+
const rewrites = args.routes.map(route => {
|
|
49
|
+
var _a;
|
|
50
|
+
const prefix = route.pathPrefix.replace(/^\/+|\/+$/g, "");
|
|
51
|
+
return {
|
|
52
|
+
glob: `/${prefix}/**`,
|
|
53
|
+
run: {
|
|
54
|
+
serviceId: route.serviceName,
|
|
55
|
+
region: (_a = route.region) !== null && _a !== void 0 ? _a : defaultRegion,
|
|
56
|
+
},
|
|
57
|
+
};
|
|
58
|
+
});
|
|
59
|
+
this.version = new gcp.firebase.HostingVersion(`hosted-api-${name}-version`, {
|
|
60
|
+
siteId: this.site.siteId,
|
|
61
|
+
config: {
|
|
62
|
+
rewrites: rewrites,
|
|
63
|
+
},
|
|
64
|
+
}, { parent: this });
|
|
65
|
+
this.release = new gcp.firebase.HostingRelease(`hosted-api-${name}-release`, {
|
|
66
|
+
siteId: this.site.siteId,
|
|
67
|
+
versionName: this.version.name,
|
|
68
|
+
message: `Pattform HostedApiComponent: ${args.routes.map(r => r.pathPrefix).join(", ")}`,
|
|
69
|
+
}, { parent: this });
|
|
70
|
+
if (args.apiDomain) {
|
|
71
|
+
this.customDomain = new gcp.firebase.HostingCustomDomain(`hosted-api-${name}-domain`, {
|
|
72
|
+
project: project,
|
|
73
|
+
siteId: this.site.siteId,
|
|
74
|
+
customDomain: args.apiDomain,
|
|
75
|
+
// Off by default so the first deploy returns immediately with the
|
|
76
|
+
// records Firebase wants, instead of blocking on DNS that has not
|
|
77
|
+
// been created yet. Flip it on once the records are in place if
|
|
78
|
+
// you want the stack to gate on verification.
|
|
79
|
+
waitDnsVerification: (_d = args.waitDnsVerification) !== null && _d !== void 0 ? _d : false,
|
|
80
|
+
}, { parent: this, dependsOn: [this.release] });
|
|
81
|
+
}
|
|
82
|
+
// Already includes the scheme, e.g. https://<site>.web.app
|
|
83
|
+
this.defaultUrl = this.site.defaultUrl;
|
|
84
|
+
this.endpoint = args.apiDomain
|
|
85
|
+
? pulumi.interpolate `https://${args.apiDomain}`
|
|
86
|
+
: this.defaultUrl;
|
|
87
|
+
this.requiredDnsUpdates = this.customDomain
|
|
88
|
+
? this.customDomain.requiredDnsUpdates
|
|
89
|
+
: pulumi.output([]);
|
|
90
|
+
this.registerOutputs({
|
|
91
|
+
endpoint: this.endpoint,
|
|
92
|
+
defaultUrl: this.defaultUrl,
|
|
93
|
+
requiredDnsUpdates: this.requiredDnsUpdates,
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
exports.HostedApiComponent = HostedApiComponent;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export { ContainerComponent, ContainerComponentArgs } from "./ContainerComponent";
|
|
2
2
|
export { ApiComponent, ApiComponentArgs } from "./ApiComponent";
|
|
3
|
+
export { HostedApiComponent, HostedApiComponentArgs, HostedApiRoute } from "./HostedApiComponent";
|
|
3
4
|
export { AppComponent, AppComponentArgs, DnsRecordInstruction } from "./AppComponent";
|
|
4
5
|
export { ClientAccountComponent, ClientAccountComponentArgs } from "./ClientAccountComponent";
|
|
5
6
|
export { GcpProjectComponent, GcpProjectComponentArgs } from "./GcpProjectComponent";
|
package/dist/index.js
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getClientGcpProvider = exports.getClientGcpDeploySa = exports.getClientRoleArn = exports.FormComponent = exports.GcpProjectComponent = exports.ClientAccountComponent = exports.AppComponent = exports.ApiComponent = exports.ContainerComponent = void 0;
|
|
3
|
+
exports.getClientGcpProvider = exports.getClientGcpDeploySa = exports.getClientRoleArn = exports.FormComponent = exports.GcpProjectComponent = exports.ClientAccountComponent = exports.AppComponent = exports.HostedApiComponent = exports.ApiComponent = exports.ContainerComponent = void 0;
|
|
4
4
|
var ContainerComponent_1 = require("./ContainerComponent");
|
|
5
5
|
Object.defineProperty(exports, "ContainerComponent", { enumerable: true, get: function () { return ContainerComponent_1.ContainerComponent; } });
|
|
6
6
|
var ApiComponent_1 = require("./ApiComponent");
|
|
7
7
|
Object.defineProperty(exports, "ApiComponent", { enumerable: true, get: function () { return ApiComponent_1.ApiComponent; } });
|
|
8
|
+
var HostedApiComponent_1 = require("./HostedApiComponent");
|
|
9
|
+
Object.defineProperty(exports, "HostedApiComponent", { enumerable: true, get: function () { return HostedApiComponent_1.HostedApiComponent; } });
|
|
8
10
|
var AppComponent_1 = require("./AppComponent");
|
|
9
11
|
Object.defineProperty(exports, "AppComponent", { enumerable: true, get: function () { return AppComponent_1.AppComponent; } });
|
|
10
12
|
var ClientAccountComponent_1 = require("./ClientAccountComponent");
|