@spine-event-engine/deployment-gke 2.0.0-snapshot.2
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/LICENSE +201 -0
- package/README.md +375 -0
- package/REFERENCE.md +54 -0
- package/dist/discovery/gke-log.d.ts +11 -0
- package/dist/discovery/gke-log.d.ts.map +1 -0
- package/dist/discovery/gke-log.js +44 -0
- package/dist/discovery/gke-log.js.map +1 -0
- package/dist/discovery/gke-node-discovery.d.ts +104 -0
- package/dist/discovery/gke-node-discovery.d.ts.map +1 -0
- package/dist/discovery/gke-node-discovery.js +198 -0
- package/dist/discovery/gke-node-discovery.js.map +1 -0
- package/dist/discovery/node-dns-resolver.d.ts +58 -0
- package/dist/discovery/node-dns-resolver.d.ts.map +1 -0
- package/dist/discovery/node-dns-resolver.js +78 -0
- package/dist/discovery/node-dns-resolver.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +15 -0
- package/dist/index.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/examples/application.ts +91 -0
- package/examples/deployment-settings.ts +85 -0
- package/examples/gateway.ts +75 -0
- package/package.json +40 -0
- package/terraform/.terraform.lock.hcl +22 -0
- package/terraform/main.tf +303 -0
- package/terraform/terraform.tfvars.example +27 -0
- package/terraform/variables.tf +191 -0
- package/terraform/versions.tf +15 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,375 @@
|
|
|
1
|
+
# Deploy a Spine TS application on GKE
|
|
2
|
+
|
|
3
|
+
`@spine-event-engine/deployment-gke` helps one standalone Gateway find ready
|
|
4
|
+
Spine TS application nodes through a Kubernetes headless Service. This guide
|
|
5
|
+
adds an editable Terraform starting point for a private, one-Gateway GKE
|
|
6
|
+
deployment. It is deliberately storage-neutral: your application chooses the
|
|
7
|
+
storage and supplies its configuration.
|
|
8
|
+
|
|
9
|
+
This is a guide for people deploying an application. For exact discovery API
|
|
10
|
+
and lifecycle behavior, see the [deployment reference](REFERENCE.md).
|
|
11
|
+
|
|
12
|
+
## Before you begin
|
|
13
|
+
|
|
14
|
+
You need an existing GKE cluster, `gcloud`, `kubectl`, Terraform 1.6 or newer,
|
|
15
|
+
and images for three processes:
|
|
16
|
+
|
|
17
|
+
- your Spine TS application-node image;
|
|
18
|
+
- your standalone Gateway image; and
|
|
19
|
+
- an image running the simple delivery server.
|
|
20
|
+
|
|
21
|
+
Publish immutable image references before deployment. The template does not
|
|
22
|
+
create a GKE cluster, an image registry, an identity provider, or application
|
|
23
|
+
secrets. Authenticate `gcloud` and select the cluster first:
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
gcloud container clusters get-credentials CLUSTER --location REGION --project PROJECT
|
|
27
|
+
kubectl create namespace spine-app
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
Create the two Secrets through your normal secret-management process before
|
|
31
|
+
running Terraform. Terraform receives only their names; it never receives or
|
|
32
|
+
creates their values. The application Secret holds application-selected
|
|
33
|
+
settings, including storage settings when the application needs them. The
|
|
34
|
+
Gateway Secret holds separate identity and session settings.
|
|
35
|
+
|
|
36
|
+
## What this deployment creates
|
|
37
|
+
|
|
38
|
+
The Terraform module creates three private Kubernetes Deployments and three
|
|
39
|
+
ClusterIP Services. One Service is headless: Kubernetes publishes the ready
|
|
40
|
+
Node Coordinator endpoint of each application Pod in DNS. The Gateway uses that
|
|
41
|
+
DNS name with `GkeNodeDiscovery`; it does not call the Kubernetes API or
|
|
42
|
+
maintain a separate node registry. Managed application children remain
|
|
43
|
+
loopback-only and are not Service endpoints.
|
|
44
|
+
|
|
45
|
+
```mermaid
|
|
46
|
+
flowchart LR
|
|
47
|
+
Edge["Operator-managed TLS and authentication edge"] --> Gateway["One standalone Gateway"]
|
|
48
|
+
Gateway --> DNS["Headless application Service DNS"]
|
|
49
|
+
DNS --> App1["Application node"]
|
|
50
|
+
DNS --> App2["Application node"]
|
|
51
|
+
App1 --> Delivery["One simple delivery server"]
|
|
52
|
+
App2 --> Delivery
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
The template intentionally keeps Gateway, application, and delivery traffic
|
|
56
|
+
private. It does not create a public load balancer, TLS certificate, or
|
|
57
|
+
authentication policy. Connect the `gateway` ClusterIP Service to the public
|
|
58
|
+
TLS/authentication edge your operators choose. That edge is responsible for
|
|
59
|
+
admitting browser traffic; the Gateway then forwards authorized requests to
|
|
60
|
+
the application nodes.
|
|
61
|
+
|
|
62
|
+
The simple delivery server is useful for this supported topology, but it is
|
|
63
|
+
in-memory, single-replica, and not highly available. It loses its state when
|
|
64
|
+
it restarts. Choose an operationally suitable delivery design before depending
|
|
65
|
+
on it for a critical production workload.
|
|
66
|
+
|
|
67
|
+
This template has one Gateway and a fixed deployment shape. Multiple-Gateway
|
|
68
|
+
behavior and Cloud Run are outside the supported offering.
|
|
69
|
+
|
|
70
|
+
## Configure the template
|
|
71
|
+
|
|
72
|
+
Copy the supplied variable file and replace every placeholder with values for
|
|
73
|
+
your cluster and delivery pipeline:
|
|
74
|
+
|
|
75
|
+
```bash
|
|
76
|
+
cd packages/deployment-gke/terraform
|
|
77
|
+
cp terraform.tfvars.example terraform.tfvars
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
`terraform.tfvars` asks for the existing Secret names, immutable images, and
|
|
81
|
+
the kubeconfig context selected by `gcloud`. It defaults to two application
|
|
82
|
+
nodes, one Gateway, and one delivery server. The Gateway and delivery-server
|
|
83
|
+
replica counts are intentionally fixed at one in this topology.
|
|
84
|
+
|
|
85
|
+
Your application and Gateway entrypoints remain application code. The template
|
|
86
|
+
uses `HOST=0.0.0.0` and the matching `PORT` value for every container so its
|
|
87
|
+
private Kubernetes Service can reach the process. Keep that listener convention
|
|
88
|
+
in your image entrypoints. Put one small configuration owner beside the two
|
|
89
|
+
entrypoints, then have each entrypoint read its injected settings rather than
|
|
90
|
+
hard-coding the Terraform defaults:
|
|
91
|
+
|
|
92
|
+
Both supplied entrypoints bind `host: "0.0.0.0"` so the Kubernetes Service can
|
|
93
|
+
reach their listeners.
|
|
94
|
+
|
|
95
|
+
```ts
|
|
96
|
+
// docs-snippet-path: packages/deployment-gke/examples/deployment-settings.ts
|
|
97
|
+
export type DeploymentEnvironment = Readonly<Record<string, string | undefined>>;
|
|
98
|
+
|
|
99
|
+
export const DeploymentSettings = Object.freeze({
|
|
100
|
+
port(environment: DeploymentEnvironment, name: "PORT" | "BACKEND_DISCOVERY_PORT"): number {
|
|
101
|
+
const value = environment[name];
|
|
102
|
+
const port = Number(value);
|
|
103
|
+
if (typeof value !== "string" || !Number.isInteger(port) || port < 1 || port > 65_535)
|
|
104
|
+
throw new Error(`${name} must be an integer from 1 through 65535.`);
|
|
105
|
+
return port;
|
|
106
|
+
},
|
|
107
|
+
|
|
108
|
+
serviceName(environment: DeploymentEnvironment): string {
|
|
109
|
+
const value = environment.BACKEND_DISCOVERY_SERVICE?.trim();
|
|
110
|
+
if (value === undefined || value.length === 0)
|
|
111
|
+
throw new Error("BACKEND_DISCOVERY_SERVICE must not be blank.");
|
|
112
|
+
return value;
|
|
113
|
+
},
|
|
114
|
+
});
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
The [complete shared settings owner](examples/deployment-settings.ts) is a
|
|
118
|
+
small source file. Each Node.js entrypoint supplies `process.env` to it.
|
|
119
|
+
The Gateway reads `"BACKEND_DISCOVERY_PORT"` and
|
|
120
|
+
`BACKEND_DISCOVERY_SERVICE` from the same source.
|
|
121
|
+
|
|
122
|
+
The standalone Gateway uses the headless Service name and application port from
|
|
123
|
+
the module. Choose one admission mode for it: authenticated mode supplies
|
|
124
|
+
sessions and may supply named durable subscription bindings; public mode
|
|
125
|
+
supplies `publicAccess: true`, and the framework owns process-local bindings.
|
|
126
|
+
Both modes supply authorization, trusted actor-context resolution, allowed
|
|
127
|
+
origins, a clock, and a type registry. The complete
|
|
128
|
+
[server browser guide](../server/README.md#serve-browser-clients) and
|
|
129
|
+
[browser authentication guide](../../docs/BROWSER_CLIENT_AUTH_EXTENSION_GUIDE.md)
|
|
130
|
+
explain those application integration points.
|
|
131
|
+
|
|
132
|
+
```ts
|
|
133
|
+
// docs-snippet-path: packages/deployment-gke/examples/gateway.ts
|
|
134
|
+
import { GkeNodeDiscovery } from "@spine-event-engine/deployment-gke";
|
|
135
|
+
import { Server, type BrowserServerOptions } from "@spine-event-engine/server";
|
|
136
|
+
|
|
137
|
+
type GatewayBrowserOptions = BrowserServerOptions extends infer Options
|
|
138
|
+
? Options extends BrowserServerOptions
|
|
139
|
+
? Omit<Options, "host" | "port" | "discovery">
|
|
140
|
+
: never
|
|
141
|
+
: never;
|
|
142
|
+
|
|
143
|
+
import { DeploymentSettings, type DeploymentEnvironment } from "./deployment-settings.js";
|
|
144
|
+
|
|
145
|
+
export interface GatewayOptions {
|
|
146
|
+
readonly browser: GatewayBrowserOptions;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
export const GatewayEntrypoint = Object.freeze({
|
|
150
|
+
async run(
|
|
151
|
+
options: GatewayOptions,
|
|
152
|
+
environment: DeploymentEnvironment = process.env,
|
|
153
|
+
): Promise<void> {
|
|
154
|
+
const discovery = new GkeNodeDiscovery({
|
|
155
|
+
serviceName: DeploymentSettings.serviceName(environment),
|
|
156
|
+
port: DeploymentSettings.port(environment, "BACKEND_DISCOVERY_PORT"),
|
|
157
|
+
});
|
|
158
|
+
const server = Server.atPort(DeploymentSettings.port(environment, "PORT"), {
|
|
159
|
+
host: "0.0.0.0",
|
|
160
|
+
browser: {
|
|
161
|
+
...options.browser,
|
|
162
|
+
discovery,
|
|
163
|
+
},
|
|
164
|
+
});
|
|
165
|
+
await server.run();
|
|
166
|
+
},
|
|
167
|
+
});
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
The [complete Gateway entrypoint](examples/gateway.ts) receives your typed
|
|
171
|
+
browser collaborators as `GatewayOptions`. In authenticated mode, supply
|
|
172
|
+
sessions, authorization, trusted actor-context resolution, allowed origins, a
|
|
173
|
+
clock, type registry, and optionally named durable subscription bindings. In
|
|
174
|
+
public mode, supply `publicAccess: true` with the shared collaborators; it
|
|
175
|
+
cannot accept bindings because the framework owns process-local ones.
|
|
176
|
+
|
|
177
|
+
The application entrypoint uses the same configuration source for its managed
|
|
178
|
+
Coordinator. Set `application_process_count` and `delivery_shard_count`
|
|
179
|
+
explicitly in Terraform. The former starts complete local replicas; the latter
|
|
180
|
+
is passed to your context assembly and is not inferred from hardware:
|
|
181
|
+
|
|
182
|
+
```ts
|
|
183
|
+
// docs-snippet-path: packages/deployment-gke/examples/application.ts
|
|
184
|
+
import {
|
|
185
|
+
ManagedServerApplication,
|
|
186
|
+
type ManagedServerApplicationHandle,
|
|
187
|
+
type ManagedServerApplicationOptions,
|
|
188
|
+
type RunningServer,
|
|
189
|
+
} from "@spine-event-engine/server";
|
|
190
|
+
|
|
191
|
+
import { DeploymentSettings, type DeploymentEnvironment } from "./deployment-settings.js";
|
|
192
|
+
|
|
193
|
+
export interface ApplicationOptions {
|
|
194
|
+
readonly moduleUrl: string;
|
|
195
|
+
readonly createServer: (options: {
|
|
196
|
+
readonly host: string;
|
|
197
|
+
readonly port: number;
|
|
198
|
+
readonly deliveryShardCount: number;
|
|
199
|
+
}) => Promise<RunningServer>;
|
|
200
|
+
readonly synchronize?: ManagedServerApplicationOptions["synchronize"];
|
|
201
|
+
readonly restart?: ManagedServerApplicationOptions["restart"];
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
export const ApplicationEntrypoint = Object.freeze({
|
|
205
|
+
async run(
|
|
206
|
+
options: ApplicationOptions,
|
|
207
|
+
environment: DeploymentEnvironment = process.env,
|
|
208
|
+
): Promise<ManagedServerApplicationHandle> {
|
|
209
|
+
const deliveryShardCount = DeploymentSettings.deliveryShardCount(environment);
|
|
210
|
+
return await ManagedServerApplication.run({
|
|
211
|
+
processCount: DeploymentSettings.processCount(environment),
|
|
212
|
+
host: "0.0.0.0",
|
|
213
|
+
port: DeploymentSettings.port(environment, "PORT"),
|
|
214
|
+
moduleUrl: options.moduleUrl,
|
|
215
|
+
createServer: async ({ host, port }) =>
|
|
216
|
+
await options.createServer({ host, port, deliveryShardCount }),
|
|
217
|
+
...(options.synchronize === undefined ? {} : { synchronize: options.synchronize }),
|
|
218
|
+
...(options.restart === undefined ? {} : { restart: options.restart }),
|
|
219
|
+
});
|
|
220
|
+
},
|
|
221
|
+
});
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
The [complete application entrypoint](examples/application.ts) receives its
|
|
225
|
+
typed bounded-context, service, and resource configuration as
|
|
226
|
+
`ApplicationOptions`.
|
|
227
|
+
|
|
228
|
+
The ConfigMap in the template exposes matching service and port values as a
|
|
229
|
+
simple convention. Adapt the names or use another configuration loader; Spine
|
|
230
|
+
TS does not require a particular environment-variable format. Authenticated
|
|
231
|
+
production startup rejects missing or volatile bindings before opening its
|
|
232
|
+
browser listener. `DurableSubscriptionBindings` is the supplied durable option;
|
|
233
|
+
give it a stable namespace and storage factory configured by the Gateway
|
|
234
|
+
process. Use shared persistent storage across Gateway replacements; an
|
|
235
|
+
in-memory store does not preserve bindings when a Gateway is replaced. Public
|
|
236
|
+
mode has no supplied bindings: its framework-owned process-local definitions
|
|
237
|
+
end when the Gateway is replaced.
|
|
238
|
+
|
|
239
|
+
## Deploy
|
|
240
|
+
|
|
241
|
+
Terraform applies Kubernetes resources to the cluster selected by your
|
|
242
|
+
kubeconfig. Keep cluster creation separate from this module, then run:
|
|
243
|
+
|
|
244
|
+
```bash
|
|
245
|
+
terraform init
|
|
246
|
+
terraform fmt -check
|
|
247
|
+
terraform validate
|
|
248
|
+
terraform plan -var-file=terraform.tfvars
|
|
249
|
+
terraform apply -var-file=terraform.tfvars
|
|
250
|
+
```
|
|
251
|
+
|
|
252
|
+
`plan` should show one Gateway Deployment, one delivery Deployment, one
|
|
253
|
+
application Deployment, and only private Services. Review it before `apply`.
|
|
254
|
+
|
|
255
|
+
## Verify the deployment
|
|
256
|
+
|
|
257
|
+
Wait for the Deployments, then inspect the headless Service endpoints:
|
|
258
|
+
|
|
259
|
+
```bash
|
|
260
|
+
kubectl get deployment,pod,service --namespace spine-app
|
|
261
|
+
kubectl rollout status deployment/application --namespace spine-app
|
|
262
|
+
kubectl rollout status deployment/gateway --namespace spine-app
|
|
263
|
+
kubectl rollout status deployment/delivery --namespace spine-app
|
|
264
|
+
kubectl get endpointslice --namespace spine-app \
|
|
265
|
+
--selector kubernetes.io/service-name=application
|
|
266
|
+
kubectl logs --namespace spine-app deployment/gateway
|
|
267
|
+
```
|
|
268
|
+
|
|
269
|
+
A ready application Pod appears in the EndpointSlice and therefore becomes an
|
|
270
|
+
available Gateway backend. An unready Pod is not published because the Service
|
|
271
|
+
sets `publishNotReadyAddresses` to `false`. The Gateway refreshes the DNS
|
|
272
|
+
answer and reconciles its backend connections. A Gateway log or an application
|
|
273
|
+
metrics should show the expected ready backend count.
|
|
274
|
+
|
|
275
|
+
## Scale application nodes
|
|
276
|
+
|
|
277
|
+
Spine TS never changes replica counts. When autoscaling is disabled, operators
|
|
278
|
+
scale the identical application Deployment by changing the Terraform input:
|
|
279
|
+
|
|
280
|
+
```bash
|
|
281
|
+
terraform apply -var-file=terraform.tfvars -var=application_replicas=4
|
|
282
|
+
terraform apply -var-file=terraform.tfvars -var=application_replicas=1
|
|
283
|
+
```
|
|
284
|
+
|
|
285
|
+
Scaling to zero is also explicit. The Gateway remains available but reports no
|
|
286
|
+
backend until a ready application node returns:
|
|
287
|
+
|
|
288
|
+
```bash
|
|
289
|
+
terraform apply -var-file=terraform.tfvars -var=application_replicas=0
|
|
290
|
+
terraform apply -var-file=terraform.tfvars -var=application_replicas=2
|
|
291
|
+
```
|
|
292
|
+
|
|
293
|
+
The optional HPA is disabled by default. Its minimum is one application node.
|
|
294
|
+
When your platform team already operates an external-metrics adapter, set
|
|
295
|
+
`autoscaling_enabled = true` and choose its metric name, target, minimum, and
|
|
296
|
+
maximum in `terraform.tfvars`.
|
|
297
|
+
When it is enabled, Terraform deliberately omits the Deployment replica value
|
|
298
|
+
so routine applies do not reset changes made by the HPA. To return to manual
|
|
299
|
+
capacity, disable autoscaling and set `application_replicas` in the same apply.
|
|
300
|
+
CPU alone cannot wake an application Deployment from zero because no Pod is
|
|
301
|
+
running to report CPU. On Standard GKE, Google documents KEDA as the scale from
|
|
302
|
+
zero path. For that policy, set `autoscaling_enabled = false` and let
|
|
303
|
+
operator-managed KEDA be the sole autoscaler for the Deployment. Never run the
|
|
304
|
+
module HPA and a KEDA-managed HPA together. Add the KEDA configuration
|
|
305
|
+
separately; this editable template does not install CRDs or assume a metric
|
|
306
|
+
provider.
|
|
307
|
+
|
|
308
|
+
## Replace an application version
|
|
309
|
+
|
|
310
|
+
Use immutable image digests and keep the previous digest in your deployment
|
|
311
|
+
record. A compatible replacement can use Kubernetes' normal rolling update:
|
|
312
|
+
|
|
313
|
+
```bash
|
|
314
|
+
terraform apply -var-file=terraform.tfvars \
|
|
315
|
+
-var='application_image=REGION-docker.pkg.dev/PROJECT/spine/application@sha256:NEW'
|
|
316
|
+
```
|
|
317
|
+
|
|
318
|
+
During overlap, old and new nodes can process work. Pending Inbox work may run
|
|
319
|
+
under the new business logic, so operators—not Spine TS—must decide whether the
|
|
320
|
+
two versions are compatible. For an incompatible replacement, first disable
|
|
321
|
+
the module HPA if it controls capacity, stop every application node, apply the new
|
|
322
|
+
image, then restore one chosen capacity policy:
|
|
323
|
+
|
|
324
|
+
```bash
|
|
325
|
+
terraform apply -var-file=terraform.tfvars \
|
|
326
|
+
-var=autoscaling_enabled=false -var=application_replicas=0
|
|
327
|
+
terraform apply -var-file=terraform.tfvars \
|
|
328
|
+
-var='application_image=REGION-docker.pkg.dev/PROJECT/spine/application@sha256:NEW' \
|
|
329
|
+
-var=application_replicas=2
|
|
330
|
+
```
|
|
331
|
+
|
|
332
|
+
Keep manual capacity by leaving `autoscaling_enabled = false`. Restore the
|
|
333
|
+
module HPA by applying `autoscaling_enabled = true` only when KEDA is absent.
|
|
334
|
+
For KEDA, leave the module HPA disabled and restore the operator-managed KEDA
|
|
335
|
+
policy only after the new application version is ready. Before the stop-all
|
|
336
|
+
step, suspend or remove the KEDA policy so it cannot create a node while the
|
|
337
|
+
replacement is intentionally at zero.
|
|
338
|
+
|
|
339
|
+
Replacing the single Gateway interrupts connected clients. The
|
|
340
|
+
Gateway-configured durable subscription registry preserves definitions across
|
|
341
|
+
the replacement; clients reconnect and re-query authoritative state after the
|
|
342
|
+
Gateway is ready again.
|
|
343
|
+
|
|
344
|
+
## Roll back
|
|
345
|
+
|
|
346
|
+
Roll back by applying a known compatible image digest and the prior replica
|
|
347
|
+
count. For an incompatible rollback, first disable the module HPA, use the
|
|
348
|
+
same stop-all, apply-old-image, start sequence, then restore exactly one of
|
|
349
|
+
manual replicas, the module HPA, or the operator-managed KEDA policy. Confirm
|
|
350
|
+
ready application endpoints and a successful Gateway connection before
|
|
351
|
+
declaring the rollback complete. Suspend or remove the KEDA policy before the
|
|
352
|
+
stop-all step, then restore it only after the old version is ready.
|
|
353
|
+
|
|
354
|
+
## Troubleshooting
|
|
355
|
+
|
|
356
|
+
| Symptom | Check | Likely next step |
|
|
357
|
+
| -------------------------- | ---------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------- |
|
|
358
|
+
| Gateway has no backend | `kubectl get endpointslice -n spine-app -l kubernetes.io/service-name=application` | Check application logs and readiness; only ready Pods enter headless DNS. |
|
|
359
|
+
| Pods do not start | `kubectl describe pod -n spine-app POD` | Verify image access, ServiceAccount permissions, and that both existing Secret names are correct. |
|
|
360
|
+
| Terraform cannot connect | `kubectl config current-context` | Re-run `gcloud container clusters get-credentials` and match `kubeconfig_context`. |
|
|
361
|
+
| HPA shows no data | `kubectl describe hpa -n spine-app application` | Confirm the external-metrics adapter and metric name; the template does not install either. |
|
|
362
|
+
| Browser clients disconnect | Gateway logs and the public edge | Expect interruption during Gateway replacement; reconnect and re-query. |
|
|
363
|
+
|
|
364
|
+
## Remove the deployment
|
|
365
|
+
|
|
366
|
+
Remove only the Terraform-managed resources when the application is no longer
|
|
367
|
+
needed:
|
|
368
|
+
|
|
369
|
+
```bash
|
|
370
|
+
terraform destroy -var-file=terraform.tfvars
|
|
371
|
+
```
|
|
372
|
+
|
|
373
|
+
The existing namespace, image registry, public edge, and Secrets are
|
|
374
|
+
managed by the operator and remain. Delete them separately only after verifying that no
|
|
375
|
+
other workload needs them.
|
package/REFERENCE.md
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
# GKE deployment reference
|
|
2
|
+
|
|
3
|
+
The [deployment guide](README.md) is for people deploying an application. This
|
|
4
|
+
reference records the exact package and Terraform-template contract.
|
|
5
|
+
|
|
6
|
+
## Discovery package
|
|
7
|
+
|
|
8
|
+
`GkeNodeDiscovery` implements `NodeDiscovery`. It reads A and AAAA answers for
|
|
9
|
+
a headless-Service DNS name and publishes each successful answer as a complete
|
|
10
|
+
ready-Coordinator snapshot. Each answer reaches one node-local Coordinator,
|
|
11
|
+
not a managed child listener. Its default refresh interval is 10 seconds. A
|
|
12
|
+
positive DNS TTL can schedule an earlier refresh; zero, missing, and unusable
|
|
13
|
+
TTLs use the configured interval. Empty and name-not-found answers publish an
|
|
14
|
+
empty snapshot immediately and retry at the configured interval.
|
|
15
|
+
|
|
16
|
+
HTTPS connects to Pod IP addresses while retaining the configured Service name
|
|
17
|
+
for TLS server-name verification. Resolver failures retain the last valid
|
|
18
|
+
membership until its deadline, then publish one empty snapshot while retries
|
|
19
|
+
continue. `close()` cancels timers and resolver work, waits for admitted work,
|
|
20
|
+
and prevents later snapshots.
|
|
21
|
+
|
|
22
|
+
Supplying discovery through `ServerOptions.browser` selects standalone Gateway
|
|
23
|
+
hosting. The Server does not build or attach local contexts in that mode, and
|
|
24
|
+
closing the Gateway stops discovery. When an application supplies both fixed
|
|
25
|
+
`backend` URLs and discovery, discovery is the active membership source; fixed
|
|
26
|
+
URLs are not reconciled.
|
|
27
|
+
|
|
28
|
+
## Terraform template
|
|
29
|
+
|
|
30
|
+
`terraform/` targets an existing Kubernetes context. It does not provision a
|
|
31
|
+
GKE cluster. The module uses versioned Kubernetes-provider resources and keeps
|
|
32
|
+
the three process Services private. `application` is headless with
|
|
33
|
+
`publish_not_ready_addresses = false`; its ready Coordinator endpoint addresses
|
|
34
|
+
are the Gateway discovery source. `gateway` and `delivery` each have exactly one
|
|
35
|
+
replica. The delivery server is in-memory and not highly available.
|
|
36
|
+
|
|
37
|
+
The module creates no Kubernetes Secret and accepts only the names of
|
|
38
|
+
operator-created application and Gateway Secrets. It selects no storage engine,
|
|
39
|
+
identity provider, public load balancer, TLS certificate, Cloud Run service, or
|
|
40
|
+
application command. The topology has exactly one Gateway; Multiple-Gateway
|
|
41
|
+
behavior is outside its contract. Application code configures
|
|
42
|
+
`GkeNodeDiscovery`, storage, identity, and public-edge integration.
|
|
43
|
+
|
|
44
|
+
`autoscaling_enabled` defaults to `false`. When true, the module creates one
|
|
45
|
+
external-metric HPA with a minimum of one and the operator's metric, target,
|
|
46
|
+
and maximum
|
|
47
|
+
and omits the Deployment replica value, leaving capacity control with the
|
|
48
|
+
HPA. When false, Terraform manages `application_replicas`. The HPA is not a
|
|
49
|
+
scale-to-zero mechanism; external request or queue activation such as
|
|
50
|
+
operator-managed KEDA is required for that behavior on Standard GKE. KEDA is
|
|
51
|
+
the sole autoscaler for its target Deployment: set `autoscaling_enabled` to
|
|
52
|
+
`false` before applying a KEDA policy. Suspend or remove KEDA before an
|
|
53
|
+
incompatible stop-all replacement or rollback, and restore it only after the
|
|
54
|
+
selected version is ready.
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { ILogLayer } from "loglayer";
|
|
2
|
+
/**
|
|
3
|
+
* Records a contained GKE discovery warning without changing discovery outcomes.
|
|
4
|
+
*
|
|
5
|
+
* @param logger Receives the contained record when supplied.
|
|
6
|
+
*/
|
|
7
|
+
export declare const gkeDiscoveryLog: Readonly<{
|
|
8
|
+
warn(logger: ILogLayer | undefined): void;
|
|
9
|
+
isPromiseLike(value: unknown): value is PromiseLike<unknown>;
|
|
10
|
+
}>;
|
|
11
|
+
//# sourceMappingURL=gke-log.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gke-log.d.ts","sourceRoot":"","sources":["../../src/discovery/gke-log.ts"],"names":[],"mappings":"AAcA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAE1C;;;;GAIG;AACH,eAAO,MAAM,eAAe,EAAE,QAAQ,CAAC;IACrC,IAAI,CAAC,MAAM,EAAE,SAAS,GAAG,SAAS,GAAG,IAAI,CAAC;IAC1C,aAAa,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,WAAW,CAAC,OAAO,CAAC,CAAC;CAC9D,CAyBC,CAAC"}
|