@catladder/pipeline 3.36.1 → 3.38.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.
@@ -0,0 +1,12 @@
1
+ import { it, expect } from "vitest";
2
+ import { createYamlLocalPipeline } from "./__utils__/helpers";
3
+ import config from "./cloud-run-session-affinity";
4
+
5
+ /**
6
+ * This test is auto-generated.
7
+ * Modifications will be overwritten on every `yarn test` run!
8
+ */
9
+
10
+ it("matches snapshot for cloud-run-session-affinity local pipeline YAML", async () => {
11
+ expect(await createYamlLocalPipeline(config)).toMatchSnapshot();
12
+ });
@@ -0,0 +1,29 @@
1
+ import type { Config } from "../src";
2
+
3
+ const config = {
4
+ appName: "test-app",
5
+ customerName: "pan",
6
+ components: {
7
+ api: {
8
+ dir: "api",
9
+ build: {
10
+ type: "node",
11
+ },
12
+ deploy: {
13
+ type: "google-cloudrun",
14
+ projectId: "google-project-id",
15
+ region: "europe-west6",
16
+
17
+ service: {
18
+ sessionAffinity: true,
19
+ },
20
+ },
21
+ },
22
+ },
23
+ } satisfies Config;
24
+
25
+ export default config;
26
+
27
+ export const information = {
28
+ title: "Cloud Run: with session affinity",
29
+ };
package/package.json CHANGED
@@ -53,7 +53,7 @@
53
53
  }
54
54
  ],
55
55
  "license": "MIT",
56
- "version": "3.36.1",
56
+ "version": "3.38.0",
57
57
  "scripts": {
58
58
  "build:tsc": "yarn tsc",
59
59
  "build": "yarn build:compile && yarn build:inline-variables",
@@ -65,6 +65,7 @@ export const getServiceDeployScript = (
65
65
  "use-http2": customConfig?.http2,
66
66
  "allow-unauthenticated": customConfig?.allowUnauthenticated ?? true,
67
67
  ingress: customConfig?.ingress ?? "all",
68
+ "session-affinity": customConfig?.sessionAffinity,
68
69
  "cpu-boost": true,
69
70
  "execution-environment": customConfig?.executionEnvironment,
70
71
  gpu: customConfig?.gpu,
@@ -202,6 +202,14 @@ export type DeployConfigCloudRunService = {
202
202
  * If you specify an image, you usually want to disable the build by setting build: false
203
203
  */
204
204
  image?: string;
205
+ /**
206
+ * whether to enable session affinity. When enabled, Cloud Run will try to route
207
+ * requests from the same client to the same instance.
208
+ *
209
+ * Passed as `--session-affinity` to gcloud.
210
+ */
211
+ sessionAffinity?: boolean;
212
+
205
213
  /**
206
214
  * args to pass to the command
207
215
  */
package/src/index.ts CHANGED
@@ -7,6 +7,7 @@ export * from "./context";
7
7
  export * from "./build";
8
8
  export * from "./deploy";
9
9
  export * from "./utils/writeFiles";
10
+ export * from "./utils/measureTime";
10
11
  export * from "./variables/VariableValue";
11
12
  export * from "./bash";
12
13
  export * from "./catenv";
@@ -0,0 +1,43 @@
1
+ import crypto from "crypto";
2
+ export const measureTime = (
3
+ logLevel: string,
4
+ label: string,
5
+ meta: Record<string, any>,
6
+ ) => {
7
+ const shortId = crypto.randomUUID().slice(0, 8);
8
+ const start = performance.now();
9
+
10
+ let logMeta = { ...meta };
11
+ const addMeta = (meta: Record<string, any>) => {
12
+ logMeta = {
13
+ ...logMeta,
14
+ ...meta,
15
+ };
16
+ };
17
+
18
+ console.log(logLevel, `[${shortId}] [START] ${label} `, {
19
+ shortId,
20
+ ...logMeta,
21
+ });
22
+
23
+ let disposed = false;
24
+
25
+ const done = () => {
26
+ if (disposed) return;
27
+ disposed = true;
28
+
29
+ const durationMs = Math.round(performance.now() - start);
30
+ const durationS = `${durationMs / 1000}s`;
31
+ console.log(logLevel, `[${shortId}] [END] ${label} | ${durationS}`, {
32
+ shortId,
33
+ durationS,
34
+ ...logMeta,
35
+ });
36
+ };
37
+
38
+ return {
39
+ done,
40
+ [Symbol.dispose]: done,
41
+ addMeta,
42
+ };
43
+ };