@catladder/pipeline 3.28.0 → 3.30.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.
@@ -719,8 +719,7 @@ before_script:
719
719
  export DOCKER_COPY_AND_INSTALL_APP="ENV YARN_ENABLE_INLINE_BUILDS=1
720
720
  COPY --chown=node:node $APP_DIR .
721
721
  RUN yarn plugin import workspace-tools
722
- RUN yarn workspaces focus --production
723
- RUN yarn rebuild"
722
+ RUN yarn workspaces focus --production"
724
723
  - |-
725
724
  export DOCKER_COPY_WORKSPACE_FILES="COPY --chown=node:node api/package.json /app/api/package.json
726
725
  COPY --chown=node:node api/yarn.lock /app/api/yarn.lock
@@ -947,8 +946,7 @@ before_script:
947
946
  export DOCKER_COPY_AND_INSTALL_APP="ENV YARN_ENABLE_INLINE_BUILDS=1
948
947
  COPY --chown=node:node $APP_DIR .
949
948
  RUN yarn plugin import workspace-tools
950
- RUN yarn workspaces focus --production
951
- RUN yarn rebuild"
949
+ RUN yarn workspaces focus --production"
952
950
  - |-
953
951
  export DOCKER_COPY_WORKSPACE_FILES="COPY --chown=node:node api/package.json /app/api/package.json
954
952
  COPY --chown=node:node api/yarn.lock /app/api/yarn.lock
@@ -1183,8 +1181,7 @@ before_script:
1183
1181
  export DOCKER_COPY_AND_INSTALL_APP="ENV YARN_ENABLE_INLINE_BUILDS=1
1184
1182
  COPY --chown=node:node $APP_DIR .
1185
1183
  RUN yarn plugin import workspace-tools
1186
- RUN yarn workspaces focus --production
1187
- RUN yarn rebuild"
1184
+ RUN yarn workspaces focus --production"
1188
1185
  - |-
1189
1186
  export DOCKER_COPY_WORKSPACE_FILES="COPY --chown=node:node api/package.json /app/api/package.json
1190
1187
  COPY --chown=node:node api/yarn.lock /app/api/yarn.lock
@@ -1404,8 +1401,7 @@ before_script:
1404
1401
  export DOCKER_COPY_AND_INSTALL_APP="ENV YARN_ENABLE_INLINE_BUILDS=1
1405
1402
  COPY --chown=node:node $APP_DIR .
1406
1403
  RUN yarn plugin import workspace-tools
1407
- RUN yarn workspaces focus --production
1408
- RUN yarn rebuild"
1404
+ RUN yarn workspaces focus --production"
1409
1405
  - |-
1410
1406
  export DOCKER_COPY_WORKSPACE_FILES="COPY --chown=node:node api/package.json /app/api/package.json
1411
1407
  COPY --chown=node:node api/yarn.lock /app/api/yarn.lock
@@ -1625,8 +1621,7 @@ before_script:
1625
1621
  export DOCKER_COPY_AND_INSTALL_APP="ENV YARN_ENABLE_INLINE_BUILDS=1
1626
1622
  COPY --chown=node:node $APP_DIR .
1627
1623
  RUN yarn plugin import workspace-tools
1628
- RUN yarn workspaces focus --production
1629
- RUN yarn rebuild"
1624
+ RUN yarn workspaces focus --production"
1630
1625
  - |-
1631
1626
  export DOCKER_COPY_WORKSPACE_FILES="COPY --chown=node:node www/package.json /app/www/package.json
1632
1627
  COPY --chown=node:node www/yarn.lock /app/www/yarn.lock
@@ -1856,8 +1851,7 @@ before_script:
1856
1851
  export DOCKER_COPY_AND_INSTALL_APP="ENV YARN_ENABLE_INLINE_BUILDS=1
1857
1852
  COPY --chown=node:node $APP_DIR .
1858
1853
  RUN yarn plugin import workspace-tools
1859
- RUN yarn workspaces focus --production
1860
- RUN yarn rebuild"
1854
+ RUN yarn workspaces focus --production"
1861
1855
  - |-
1862
1856
  export DOCKER_COPY_WORKSPACE_FILES="COPY --chown=node:node www/package.json /app/www/package.json
1863
1857
  COPY --chown=node:node www/yarn.lock /app/www/yarn.lock
@@ -2095,8 +2089,7 @@ before_script:
2095
2089
  export DOCKER_COPY_AND_INSTALL_APP="ENV YARN_ENABLE_INLINE_BUILDS=1
2096
2090
  COPY --chown=node:node $APP_DIR .
2097
2091
  RUN yarn plugin import workspace-tools
2098
- RUN yarn workspaces focus --production
2099
- RUN yarn rebuild"
2092
+ RUN yarn workspaces focus --production"
2100
2093
  - |-
2101
2094
  export DOCKER_COPY_WORKSPACE_FILES="COPY --chown=node:node www/package.json /app/www/package.json
2102
2095
  COPY --chown=node:node www/yarn.lock /app/www/yarn.lock
@@ -2319,8 +2312,7 @@ before_script:
2319
2312
  export DOCKER_COPY_AND_INSTALL_APP="ENV YARN_ENABLE_INLINE_BUILDS=1
2320
2313
  COPY --chown=node:node $APP_DIR .
2321
2314
  RUN yarn plugin import workspace-tools
2322
- RUN yarn workspaces focus --production
2323
- RUN yarn rebuild"
2315
+ RUN yarn workspaces focus --production"
2324
2316
  - |-
2325
2317
  export DOCKER_COPY_WORKSPACE_FILES="COPY --chown=node:node www/package.json /app/www/package.json
2326
2318
  COPY --chown=node:node www/yarn.lock /app/www/yarn.lock
@@ -0,0 +1,11 @@
1
+ import { createYamlLocalPipeline } from "./__utils__/helpers";
2
+ import config from "./cloud-run-execute-script-on-deploy";
3
+
4
+ /**
5
+ * This test is auto-generated.
6
+ * Modifications will be overwritten on every `yarn test` run!
7
+ */
8
+
9
+ it("matches snapshot for cloud-run-execute-script-on-deploy local pipeline YAML", async () => {
10
+ expect(await createYamlLocalPipeline(config)).toMatchSnapshot();
11
+ });
@@ -0,0 +1,47 @@
1
+ import type { Config } from "../src";
2
+
3
+ const config = {
4
+ appName: "test-app",
5
+ customerName: "pan",
6
+ components: {
7
+ app: {
8
+ dir: "app",
9
+ build: {
10
+ type: "node",
11
+ },
12
+ deploy: {
13
+ type: "google-cloudrun",
14
+ projectId: "google-project-id",
15
+ region: "europe-west6",
16
+ execute: {
17
+ "pre-deploy-script": {
18
+ type: "script",
19
+ script: ["echo 'deploying'"],
20
+ when: "preDeploy",
21
+ },
22
+ "post-deploy-script": {
23
+ type: "script",
24
+ script: ["echo 'deployed'"],
25
+ when: "postDeploy",
26
+ },
27
+ "pre-stop-script": {
28
+ type: "script",
29
+ script: ["echo 'stopping'"],
30
+ when: "preStop",
31
+ },
32
+ "post-stop-script": {
33
+ type: "script",
34
+ script: ["echo 'stopped'"],
35
+ when: "postStop",
36
+ },
37
+ },
38
+ },
39
+ },
40
+ },
41
+ } satisfies Config;
42
+
43
+ export default config;
44
+
45
+ export const information = {
46
+ title: "Cloud Run: Execute script on deploy",
47
+ };
@@ -11,6 +11,9 @@ const config = {
11
11
  builds: {
12
12
  myWorkspace: {
13
13
  type: "node",
14
+ dockerDefaults: {
15
+ yarnRebuildEnabled: false,
16
+ },
14
17
  },
15
18
  },
16
19
  components: {
package/package.json CHANGED
@@ -53,7 +53,7 @@
53
53
  }
54
54
  ],
55
55
  "license": "MIT",
56
- "version": "3.28.0",
56
+ "version": "3.30.0",
57
57
  "scripts": {
58
58
  "build:tsc": "yarn tsc",
59
59
  "build": "yarn build:compile && yarn build:inline-variables",
@@ -69,12 +69,19 @@ RUN ${YARN_INSTALL_CLASSIC} --production
69
69
  );
70
70
  }
71
71
 
72
+ const yarnRebuildEnabledDefault =
73
+ context.build.type === "fromWorkspace"
74
+ ? (context.build.workspaceBuildConfig.dockerDefaults
75
+ ?.yarnRebuildEnabled ?? true)
76
+ : true;
77
+
72
78
  const yarnRebuildEnabled =
73
79
  "docker" in context.build.config &&
74
80
  context.build.config.docker &&
75
81
  "yarnRebuildEnabled" in context.build.config.docker
76
- ? (context.build.config.docker.yarnRebuildEnabled ?? true)
77
- : true;
82
+ ? (context.build.config.docker.yarnRebuildEnabled ??
83
+ yarnRebuildEnabledDefault)
84
+ : yarnRebuildEnabledDefault;
78
85
 
79
86
  // yarn >= 4 ships with build in plugins, see https://github.com/yarnpkg/berry/pull/4253
80
87
  // trying to import those fail on this version
@@ -425,6 +425,11 @@ export type WorkspaceBuildConfigBase = {
425
425
  export type WorkspaceBuildConfigNode = {
426
426
  type: "node";
427
427
  buildCommand?: string | string[];
428
+ /**
429
+ * set docker config defaults for the node build type.
430
+ * Currently not all options are supported.
431
+ */
432
+ dockerDefaults?: Pick<BuildConfigDockerBuiltInNode, "yarnRebuildEnabled">;
428
433
  } & WorkspaceBuildConfigBase;
429
434
 
430
435
  export type WorkspaceBuildConfig = WorkspaceBuildConfigNode;
@@ -1,10 +1,8 @@
1
1
  import type { StringOrBashExpression } from "../../../../bash";
2
2
  import type { ComponentContext } from "../../../../types/context";
3
- import type {
4
- DeployConfigCloudRunExecuteOnDeploy,
5
- DeployConfigCloudRunJob,
6
- DeployConfigCloudRunService,
7
- } from "../../../types/googleCloudRun";
3
+ import { ensureArray } from "../../../../utils";
4
+ import type { DeployConfigBaseExecuteOnDeploy } from "../../../types/executeBase";
5
+ import type { DeployConfigCloudRunExecuteOnDeploy } from "../../../types/googleCloudRun";
8
6
  import { createArgsString } from "../../utils/createArgsString";
9
7
  import { getCloudRunServiceOrJobArgsArg } from "../../utils/getJobOrServiceArgs";
10
8
  import { getFullJobName } from "../../utils/jobName";
@@ -17,7 +15,7 @@ import {
17
15
 
18
16
  type Execute = {
19
17
  jobName: StringOrBashExpression;
20
- config: DeployConfigCloudRunExecuteOnDeploy;
18
+ config: DeployConfigCloudRunExecuteOnDeploy | DeployConfigBaseExecuteOnDeploy;
21
19
  };
22
20
  export const getOnDeployExecuteScript = (
23
21
  context: ComponentContext,
@@ -27,7 +25,7 @@ export const getOnDeployExecuteScript = (
27
25
 
28
26
  return executes
29
27
  .filter(({ config }) => config.when === when)
30
- .map((execute) => {
28
+ .flatMap((execute) => {
31
29
  return getJobRunScriptForExecute(context, execute);
32
30
  });
33
31
  };
@@ -37,7 +35,8 @@ const getExecutes = (context: ComponentContext): Execute[] => {
37
35
  return [
38
36
  ...getLegacyExecutes(context),
39
37
  ...Object.entries(deployConfig.execute ?? {}).flatMap(([key, value]) => {
40
- if (!value || (value.when !== "schedule" && value.type !== "job")) {
38
+ // remove all schedule executes
39
+ if (!value) {
41
40
  return [];
42
41
  }
43
42
  return [
@@ -81,22 +80,30 @@ const getLegacyExecutes = (context: ComponentContext): Execute[] => {
81
80
  const getJobRunScriptForExecute = (
82
81
  context: ComponentContext,
83
82
  { jobName, config }: Execute,
84
- ) => {
85
- const commonArgs = getCommonCloudRunArgs(context);
83
+ ): string[] => {
84
+ const type = config.type;
85
+ if (type === "script") {
86
+ return ensureArray(config.script);
87
+ } else if (type === "job") {
88
+ const commonArgs = getCommonCloudRunArgs(context);
86
89
 
87
- // always wait for completion for preStop and postStop jobs
88
- // since stop will delete the jobs afterwards, so they will fail
89
- const waitForCompletion = ["preStop", "postStop"].includes(config.when)
90
- ? true // always
91
- : "waitForCompletion" in config
92
- ? (config.waitForCompletion ?? false) // depends on config
93
- : false;
90
+ // always wait for completion for preStop and postStop jobs
91
+ // since stop will delete the jobs afterwards, so they will fail
92
+ const waitForCompletion = ["preStop", "postStop"].includes(config.when)
93
+ ? true // always
94
+ : "waitForCompletion" in config
95
+ ? (config.waitForCompletion ?? false) // depends on config
96
+ : false;
94
97
 
95
- const argString = createArgsString({
96
- ...commonArgs,
97
- wait: waitForCompletion === true ? true : undefined,
98
- args: getCloudRunServiceOrJobArgsArg(config.args),
99
- });
100
- const fullJobName = getFullJobName(context, jobName);
101
- return `${gcloudRunCmd()} jobs execute ${fullJobName.toString()} ${argString}`;
98
+ const argString = createArgsString({
99
+ ...commonArgs,
100
+ wait: waitForCompletion === true ? true : undefined,
101
+ args: getCloudRunServiceOrJobArgsArg(config.args),
102
+ });
103
+ const fullJobName = getFullJobName(context, jobName);
104
+ return [
105
+ `${gcloudRunCmd()} jobs execute ${fullJobName.toString()} ${argString}`,
106
+ ];
107
+ }
108
+ throw new Error(`unsupported execute type: ${type}`);
102
109
  };
@@ -1,4 +1,5 @@
1
1
  import type { EnvVars } from "../../types/config";
2
+ import type { DeployConfigBaseExecute } from "./executeBase";
2
3
 
3
4
  export type DeployConfigBase = {
4
5
  /**
@@ -0,0 +1,27 @@
1
+ type DeployConfigBaseExecuteScript = {
2
+ type: "script";
3
+ script: string | string[];
4
+ };
5
+ /**
6
+ * currently only supported for cloud run deployments
7
+ */
8
+ export type DeployConfigBaseExecuteOnDeploy = DeployConfigBaseExecuteScript &
9
+ (
10
+ | {
11
+ /**
12
+ * run the job before or after the deploy
13
+ */
14
+ when: "preDeploy" | "postDeploy";
15
+ /**
16
+ * whether to wait for completion of the job
17
+ */
18
+ waitForCompletion?: boolean;
19
+ }
20
+ | {
21
+ /**
22
+ * run the job before or after the environment is stopped
23
+ */
24
+ when: "preStop" | "postStop";
25
+ }
26
+ );
27
+ export type DeployConfigBaseExecute = DeployConfigBaseExecuteOnDeploy;
@@ -1,5 +1,9 @@
1
1
  import type { DBVariablesMode } from "../cloudRun/utils/database";
2
2
  import type { DeployConfigBase } from "./base";
3
+ import type {
4
+ DeployConfigBaseExecute,
5
+ DeployConfigBaseExecuteOnDeploy,
6
+ } from "./executeBase";
3
7
 
4
8
  export type Gcloudregion =
5
9
  | "asia-east1"
@@ -424,7 +428,7 @@ export type DeployConfigCloudRunJob =
424
428
  | DeployConfigCloudRunJobNormal
425
429
  | DeployConfigCloudRunJobWithSchedule;
426
430
 
427
- export type DeployConfigCloudRun = {
431
+ export type DeployConfigCloudRun = Omit<DeployConfigBase, "execute"> & {
428
432
  /**
429
433
  * cloud run deployment.
430
434
  *
@@ -469,7 +473,7 @@ export type DeployConfigCloudRun = {
469
473
  execute?: Record<string, DeployConfigCloudRunExecute | null>;
470
474
 
471
475
  debug?: boolean;
472
- } & DeployConfigBase;
476
+ };
473
477
 
474
478
  export type DeployConfigCloudRunVolumes = Record<
475
479
  string,
@@ -543,6 +547,7 @@ export type DeployConfigCloudRunExecuteOnDeploy =
543
547
  );
544
548
 
545
549
  export type DeployConfigCloudRunExecuteJob =
550
+ | DeployConfigBaseExecute
546
551
  | DeployConfigCloudRunExecuteJobScheduled
547
552
  | DeployConfigCloudRunExecuteOnDeploy;
548
553
 
@@ -573,6 +578,7 @@ export type DeployConfigCloudRunExecuteHttp = {
573
578
  } & WithSchedule;
574
579
 
575
580
  export type DeployConfigCloudRunExecute =
581
+ | DeployConfigBaseExecute
576
582
  | DeployConfigCloudRunExecuteJob
577
583
  | DeployConfigCloudRunExecuteHttp;
578
584