@catladder/pipeline 1.146.1 → 1.147.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.
Files changed (153) hide show
  1. package/dist/build/base/createAppBuildJob.d.ts +2 -2
  2. package/dist/build/base/createAppBuildJob.js +6 -6
  3. package/dist/build/base/index.d.ts +2 -2
  4. package/dist/build/base/writeBuildInfo.d.ts +2 -2
  5. package/dist/build/base/writeBuildInfo.js +1 -1
  6. package/dist/build/base/writeDotEnv.d.ts +2 -2
  7. package/dist/build/base/writeDotEnv.js +1 -1
  8. package/dist/build/custom/__tests__/testJob.test.js +11 -14
  9. package/dist/build/custom/buildJob.d.ts +2 -2
  10. package/dist/build/custom/buildJob.js +5 -5
  11. package/dist/build/custom/index.d.ts +2 -2
  12. package/dist/build/custom/testJob.d.ts +2 -2
  13. package/dist/build/custom/testJob.js +5 -5
  14. package/dist/build/docker.d.ts +32 -15
  15. package/dist/build/docker.js +41 -20
  16. package/dist/build/index.d.ts +2 -2
  17. package/dist/build/node/buildJob.d.ts +2 -2
  18. package/dist/build/node/buildJob.js +8 -8
  19. package/dist/build/node/cache.d.ts +5 -5
  20. package/dist/build/node/cache.js +5 -5
  21. package/dist/build/node/index.d.ts +4 -4
  22. package/dist/build/node/meteor.d.ts +2 -2
  23. package/dist/build/node/meteor.js +6 -6
  24. package/dist/build/node/testJob.d.ts +2 -2
  25. package/dist/build/node/testJob.js +11 -11
  26. package/dist/build/node/yarn.d.ts +4 -4
  27. package/dist/build/node/yarn.js +1 -1
  28. package/dist/build/rails/build.d.ts +2 -2
  29. package/dist/build/rails/build.js +3 -3
  30. package/dist/build/rails/index.d.ts +2 -2
  31. package/dist/build/rails/test.d.ts +2 -2
  32. package/dist/build/rails/test.js +4 -4
  33. package/dist/build/sbom.d.ts +2 -2
  34. package/dist/build/sbom.js +2 -2
  35. package/dist/build/types.d.ts +34 -26
  36. package/dist/bundles/catladder-gitlab/index.js +2 -2
  37. package/dist/constants.js +1 -1
  38. package/dist/context/getEnvironment.d.ts +2 -2
  39. package/dist/context/getEnvironmentContext.d.ts +2 -2
  40. package/dist/context/getEnvironmentVariables.d.ts +4 -4
  41. package/dist/context/getLabels.d.ts +2 -2
  42. package/dist/context/getLabels.js +1 -1
  43. package/dist/context/index.d.ts +7 -3
  44. package/dist/context/index.js +43 -12
  45. package/dist/deploy/base/deploy.d.ts +2 -2
  46. package/dist/deploy/base/deploy.js +9 -8
  47. package/dist/deploy/base/index.d.ts +2 -2
  48. package/dist/deploy/base/rollback.d.ts +2 -2
  49. package/dist/deploy/base/stop.d.ts +2 -2
  50. package/dist/deploy/cloudRun/artifactsRegistry.d.ts +7 -11
  51. package/dist/deploy/cloudRun/artifactsRegistry.js +8 -9
  52. package/dist/deploy/cloudRun/cleanup.d.ts +2 -2
  53. package/dist/deploy/cloudRun/cloudRunRevisions.d.ts +2 -2
  54. package/dist/deploy/cloudRun/cloudRunRevisions.js +4 -5
  55. package/dist/deploy/cloudRun/createJobs/cloudRunJobs.d.ts +6 -6
  56. package/dist/deploy/cloudRun/createJobs/cloudRunServices.d.ts +3 -3
  57. package/dist/deploy/cloudRun/createJobs/cloudRunServices.js +1 -1
  58. package/dist/deploy/cloudRun/createJobs/common.js +2 -1
  59. package/dist/deploy/cloudRun/createJobs/getCloudRunDeployScripts.d.ts +2 -2
  60. package/dist/deploy/cloudRun/createJobs/getCloudRunStopScripts.d.ts +2 -2
  61. package/dist/deploy/cloudRun/createJobs/index.d.ts +2 -2
  62. package/dist/deploy/cloudRun/createJobs/index.js +2 -4
  63. package/dist/deploy/cloudRun/utils/database.d.ts +3 -3
  64. package/dist/deploy/cloudRun/utils/gcloudServiceAccountLoginCommands.d.ts +2 -2
  65. package/dist/deploy/cloudRun/utils/getServiceName.d.ts +2 -2
  66. package/dist/deploy/custom/deployJob.d.ts +2 -2
  67. package/dist/deploy/custom/deployJob.js +7 -10
  68. package/dist/deploy/dockerTag/deployJob.d.ts +2 -2
  69. package/dist/deploy/dockerTag/deployJob.js +3 -5
  70. package/dist/deploy/index.d.ts +2 -2
  71. package/dist/deploy/kubernetes/cloudSql/index.d.ts +3 -3
  72. package/dist/deploy/kubernetes/cloudSql/index.js +11 -9
  73. package/dist/deploy/kubernetes/deployJob.d.ts +2 -2
  74. package/dist/deploy/kubernetes/deployJob.js +4 -7
  75. package/dist/deploy/kubernetes/kubeEnv.d.ts +2 -2
  76. package/dist/deploy/kubernetes/kubeEnv.js +2 -1
  77. package/dist/deploy/kubernetes/kubeValues.d.ts +2 -2
  78. package/dist/deploy/kubernetes/kubeValues.js +10 -10
  79. package/dist/deploy/kubernetes/mongodb.d.ts +2 -2
  80. package/dist/deploy/kubernetes/mongodb.js +11 -11
  81. package/dist/deploy/sbom.d.ts +4 -4
  82. package/dist/deploy/sbom.js +1 -1
  83. package/dist/deploy/types/index.d.ts +1 -1
  84. package/dist/deploy/types/index.js +1 -1
  85. package/dist/deploy/utils.d.ts +2 -2
  86. package/dist/deploy/utils.js +2 -1
  87. package/dist/pipeline/createJobsForComponent.d.ts +2 -2
  88. package/dist/pipeline/createJobsForComponent.js +6 -6
  89. package/dist/tsconfig.tsbuildinfo +1 -1
  90. package/dist/types/config.d.ts +2 -2
  91. package/dist/types/context.d.ts +28 -2
  92. package/examples/__snapshots__/cloud-run-storybook.ts.snap +1687 -0
  93. package/examples/__snapshots__/cloud-run-with-ngnix.ts.snap +1971 -0
  94. package/examples/cloud-run-storybook.ts +24 -0
  95. package/examples/cloud-run-with-ngnix.ts +24 -0
  96. package/package.json +1 -1
  97. package/src/build/base/createAppBuildJob.ts +9 -9
  98. package/src/build/base/index.ts +2 -2
  99. package/src/build/base/writeBuildInfo.ts +3 -3
  100. package/src/build/base/writeDotEnv.ts +3 -3
  101. package/src/build/custom/__tests__/testJob.test.ts +8 -11
  102. package/src/build/custom/buildJob.ts +10 -11
  103. package/src/build/custom/index.ts +2 -2
  104. package/src/build/custom/testJob.ts +9 -7
  105. package/src/build/docker.ts +73 -29
  106. package/src/build/index.ts +2 -2
  107. package/src/build/node/buildJob.ts +19 -15
  108. package/src/build/node/cache.ts +10 -10
  109. package/src/build/node/index.ts +6 -4
  110. package/src/build/node/meteor.ts +16 -17
  111. package/src/build/node/testJob.ts +19 -16
  112. package/src/build/node/yarn.ts +6 -8
  113. package/src/build/rails/build.ts +7 -5
  114. package/src/build/rails/index.ts +2 -2
  115. package/src/build/rails/test.ts +8 -6
  116. package/src/build/sbom.ts +5 -5
  117. package/src/build/types.ts +53 -38
  118. package/src/context/getEnvironment.ts +2 -2
  119. package/src/context/getEnvironmentContext.ts +2 -2
  120. package/src/context/getEnvironmentVariables.ts +7 -4
  121. package/src/context/getLabels.ts +3 -3
  122. package/src/context/index.ts +33 -7
  123. package/src/deploy/base/deploy.ts +10 -16
  124. package/src/deploy/base/index.ts +2 -2
  125. package/src/deploy/base/rollback.ts +2 -2
  126. package/src/deploy/base/stop.ts +2 -2
  127. package/src/deploy/cloudRun/artifactsRegistry.ts +16 -16
  128. package/src/deploy/cloudRun/cleanup.ts +2 -2
  129. package/src/deploy/cloudRun/cloudRunRevisions.ts +6 -8
  130. package/src/deploy/cloudRun/createJobs/cloudRunJobs.ts +10 -10
  131. package/src/deploy/cloudRun/createJobs/cloudRunServices.ts +4 -4
  132. package/src/deploy/cloudRun/createJobs/common.ts +1 -1
  133. package/src/deploy/cloudRun/createJobs/getCloudRunDeployScripts.ts +5 -2
  134. package/src/deploy/cloudRun/createJobs/getCloudRunStopScripts.ts +2 -2
  135. package/src/deploy/cloudRun/createJobs/index.ts +3 -6
  136. package/src/deploy/cloudRun/utils/database.ts +3 -3
  137. package/src/deploy/cloudRun/utils/gcloudServiceAccountLoginCommands.ts +4 -2
  138. package/src/deploy/cloudRun/utils/getServiceName.ts +2 -2
  139. package/src/deploy/custom/deployJob.ts +10 -8
  140. package/src/deploy/dockerTag/deployJob.ts +6 -7
  141. package/src/deploy/index.ts +2 -2
  142. package/src/deploy/kubernetes/cloudSql/index.ts +10 -7
  143. package/src/deploy/kubernetes/deployJob.ts +3 -6
  144. package/src/deploy/kubernetes/kubeEnv.ts +3 -3
  145. package/src/deploy/kubernetes/kubeValues.ts +6 -6
  146. package/src/deploy/kubernetes/mongodb.ts +14 -14
  147. package/src/deploy/sbom.ts +9 -6
  148. package/src/deploy/types/index.ts +2 -2
  149. package/src/deploy/utils.ts +3 -3
  150. package/src/pipeline/createJobsForComponent.ts +17 -17
  151. package/src/pipeline/gitlab/createGitlabJobs.ts +2 -2
  152. package/src/types/config.ts +4 -2
  153. package/src/types/context.ts +33 -2
@@ -1,10 +1,11 @@
1
+ import { isFunction } from "lodash";
1
2
  import { BUILD_TYPES } from "../build";
2
3
  import type { BuildConfig, BuildConfigType } from "../build/types";
3
4
  import { DEPLOY_TYPES } from "../deploy";
4
5
  import type { DeployConfig, DeployConfigType } from "../deploy/types";
5
6
  import type { PipelineType } from "../types";
6
7
  import type { Config, PipelineTrigger } from "../types/config";
7
- import type { Context, PackageManagerInfo } from "../types/context";
8
+ import type { ComponentContext, PackageManagerInfo } from "../types/context";
8
9
  import type { PartialDeep } from "../types/utils";
9
10
  import { mergeWithMergingArrays } from "../utils";
10
11
  import { getEnvironment } from "./getEnvironment";
@@ -13,7 +14,7 @@ import { getEnvironmentContext } from "./getEnvironmentContext";
13
14
  export * from "./getEnvironment";
14
15
  export * from "./getEnvironmentVariables";
15
16
 
16
- export type CreateContextContext = {
17
+ export type CreateComponentContextContext = {
17
18
  config: Config;
18
19
  componentName: string;
19
20
  env: string;
@@ -22,9 +23,9 @@ export type CreateContextContext = {
22
23
  packageManagerInfo?: PackageManagerInfo;
23
24
  };
24
25
 
25
- export const createContext = async (
26
- ctx: CreateContextContext,
27
- ): Promise<Context> => {
26
+ export const createComponentContext = async (
27
+ ctx: CreateComponentContextContext,
28
+ ): Promise<ComponentContext> => {
28
29
  if (!/^[a-z0-9-]+$/.test(ctx.componentName)) {
29
30
  throw new Error(
30
31
  "componentName may only contain lower case letters, numbers and -",
@@ -56,13 +57,38 @@ export const createContext = async (
56
57
  componentConfigWithoutDefaults,
57
58
  );
58
59
 
59
- return {
60
+ const environment = await getEnvironment(ctx);
61
+ const { deploy, build, customJobs, dir } = componentConfig;
62
+ const context: Omit<ComponentContext, "customJobs"> = {
60
63
  fullConfig: ctx.config,
61
64
  componentConfig,
65
+
66
+ build: {
67
+ dir: dir,
68
+ packageManagerInfo: ctx.packageManagerInfo,
69
+ config: build,
70
+ },
71
+ deploy: deploy
72
+ ? {
73
+ config: deploy,
74
+ }
75
+ : null,
62
76
  componentName: ctx.componentName,
63
- environment: await getEnvironment(ctx),
77
+ environment,
64
78
  packageManagerInfo: ctx.packageManagerInfo,
65
79
  pipelineType: ctx.pipelineType,
66
80
  trigger: ctx.trigger,
67
81
  };
82
+ const resolvedCustomJobs = isFunction(customJobs)
83
+ ? customJobs(context)
84
+ : customJobs;
85
+ return {
86
+ ...context,
87
+ customJobs: resolvedCustomJobs,
88
+ };
68
89
  };
90
+
91
+ /**
92
+ * @deprecated use createComponentContext instead
93
+ */
94
+ export const createContext = createComponentContext;
@@ -3,7 +3,7 @@ import {
3
3
  requiresDockerBuild,
4
4
  } from "../../build/docker";
5
5
  import { SBOM_BUILD_JOB_NAME } from "../../build/sbom";
6
- import type { Context } from "../../types/context";
6
+ import type { ComponentContext } from "../../types/context";
7
7
  import type { CatladderJob } from "../../types/jobs";
8
8
  import { sbomDeactivated } from "../sbom";
9
9
  import { contextIsStoppable } from "../utils";
@@ -24,7 +24,7 @@ export type DeployJobDefinition = Pick<
24
24
  | "runnerVariables"
25
25
  >;
26
26
  export const createDeployJob = (
27
- context: Context,
27
+ context: ComponentContext,
28
28
  jobDefinition: DeployJobDefinition,
29
29
  ): CatladderJob => {
30
30
  const hasDocker = requiresDockerBuild(context);
@@ -37,11 +37,11 @@ export const createDeployJob = (
37
37
  ? "4 weeks"
38
38
  : undefined;
39
39
 
40
+ const deployConfig = context.deploy?.config;
41
+
40
42
  // if auto or manual is configured explicitly, use that
41
43
  const whenDeployDefined =
42
- context.componentConfig.deploy && context.componentConfig.deploy.when
43
- ? context.componentConfig.deploy.when
44
- : undefined;
44
+ deployConfig && deployConfig.when ? deployConfig.when : undefined;
45
45
  // otherwise auto deploy if env is not prod. If its prod, deploy automatically if stage is disabled
46
46
  const whenDeployDefault =
47
47
  context.environment.envType !== "prod"
@@ -64,8 +64,8 @@ export const createDeployJob = (
64
64
  ...(sbomDeactivated(context)
65
65
  ? []
66
66
  : [{ job: SBOM_BUILD_JOB_NAME, artifacts: true }]),
67
- ...(context.componentConfig.deploy
68
- ? context.componentConfig.deploy.waitFor?.map((c) => ({
67
+ ...(deployConfig
68
+ ? deployConfig.waitFor?.map((c) => ({
69
69
  componentName: c,
70
70
  job: DEPLOY_JOB_NAME,
71
71
  artifacts: false,
@@ -91,17 +91,13 @@ export const createDeployJob = (
91
91
  ...context.environment.envVars,
92
92
  ...(hasDocker ? getDockerImageVariables(context) : {}),
93
93
  ...context.environment.jobOnlyVars.deploy.envVars,
94
- ...(context.componentConfig.deploy
95
- ? context.componentConfig.deploy.extraVars ?? {}
96
- : {}),
94
+ ...(deployConfig ? deployConfig.extraVars ?? {} : {}),
97
95
  ...jobDefinition.variables,
98
96
  },
99
97
  runnerVariables: {
100
98
  ...DEPLOY_RUNNER_VARIABLES,
101
99
  ...(jobDefinition.runnerVariables ?? {}),
102
- ...(context.componentConfig.deploy
103
- ? context.componentConfig.deploy.runnerVariables ?? {}
104
- : {}),
100
+ ...(deployConfig ? deployConfig.runnerVariables ?? {} : {}),
105
101
  },
106
102
  environment: isStoppable
107
103
  ? {
@@ -109,8 +105,6 @@ export const createDeployJob = (
109
105
  auto_stop_in: autoStop,
110
106
  }
111
107
  : undefined,
112
- jobTags: context.componentConfig.deploy
113
- ? context.componentConfig.deploy.jobTags
114
- : undefined,
108
+ jobTags: deployConfig ? deployConfig.jobTags : undefined,
115
109
  };
116
110
  };
@@ -1,11 +1,11 @@
1
- import type { Context } from "../../types/context";
1
+ import type { ComponentContext } from "../../types/context";
2
2
  import type { CatladderJob } from "../../types/jobs";
3
3
  import { createDeployJob, type DeployJobDefinition } from "./deploy";
4
4
  import { createRollbackJob, type RollbackJobDefinition } from "./rollback";
5
5
  import { createStopJob, type StopJobDefinition } from "./stop";
6
6
 
7
7
  export const createDeployementJobs = (
8
- context: Context,
8
+ context: ComponentContext,
9
9
  definitions: {
10
10
  deploy: DeployJobDefinition;
11
11
  stop?: StopJobDefinition;
@@ -1,4 +1,4 @@
1
- import type { Context } from "../../types/context";
1
+ import type { ComponentContext } from "../../types/context";
2
2
  import type { CatladderJob } from "../../types/jobs";
3
3
  import { DEPLOY_RUNNER_VARIABLES } from "./variables";
4
4
 
@@ -9,7 +9,7 @@ export type RollbackJobDefinition = Pick<
9
9
  "script" | "variables" | "runnerVariables" | "image"
10
10
  >;
11
11
  export const createRollbackJob = (
12
- context: Context,
12
+ context: ComponentContext,
13
13
  jobDefinition: RollbackJobDefinition,
14
14
  ): CatladderJob => {
15
15
  return {
@@ -1,4 +1,4 @@
1
- import type { Context } from "../../types/context";
1
+ import type { ComponentContext } from "../../types/context";
2
2
  import type { CatladderJob } from "../../types/jobs";
3
3
 
4
4
  import { DEPLOY_RUNNER_VARIABLES } from "./variables";
@@ -9,7 +9,7 @@ export type StopJobDefinition = Pick<
9
9
  "script" | "variables" | "image" | "runnerVariables"
10
10
  >;
11
11
  export const createStopJob = (
12
- context: Context,
12
+ context: ComponentContext,
13
13
  jobDefinition: StopJobDefinition,
14
14
  ): CatladderJob => {
15
15
  return {
@@ -1,22 +1,20 @@
1
1
  import type { StringOrBashExpression } from "../../bash/BashExpression";
2
2
  import { joinBashExpressions } from "../../bash/BashExpression";
3
- import type { Context } from "../../types/context";
3
+ import type { ComponentContext } from "../../types/context";
4
4
  import { allowFailureInScripts } from "../../utils/gitlab";
5
5
  import { isOfDeployType } from "../types";
6
6
  import { removeFirstLinesFromCommandOutput } from "./utils/removeFirstLinesFromCommandOutput";
7
7
 
8
- export const getArtifactsRegistryHost = ({
9
- componentConfig: { deploy },
10
- }: Context) => {
11
- if (!isOfDeployType(deploy, "google-cloudrun")) {
8
+ export const getArtifactsRegistryHost = (context: ComponentContext) => {
9
+ if (!isOfDeployType(context.deploy?.config, "google-cloudrun")) {
12
10
  // should not happen
13
11
  throw new Error("deploy config is wrong");
14
12
  }
15
- return `${deploy.region}-docker.pkg.dev`;
13
+ return `${context.deploy.config.region}-docker.pkg.dev`;
16
14
  };
17
15
 
18
- export const getArtifactsRegistryDockerUrl = (context: Context) => {
19
- const deployConfig = context.componentConfig.deploy;
16
+ export const getArtifactsRegistryDockerUrl = (context: ComponentContext) => {
17
+ const deployConfig = context.deploy?.config;
20
18
 
21
19
  if (!isOfDeployType(deployConfig, "google-cloudrun")) {
22
20
  // should not happen
@@ -35,7 +33,7 @@ export const getArtifactsRegistryDockerUrl = (context: Context) => {
35
33
  * lecacyReviewImageName is only temporary. In old versions the images had no reviewslug in review apps, which makes cleanup harder. We delete all those images now, but need the path
36
34
  */
37
35
  export const getArtifactsRegistryImageName = (
38
- context: Context,
36
+ context: ComponentContext,
39
37
  lecacyReviewImageName = false,
40
38
  ) => {
41
39
  if (lecacyReviewImageName && context.environment.envType !== "review") {
@@ -55,14 +53,16 @@ export const getArtifactsRegistryImageName = (
55
53
  return joinBashExpressions(gcloudImagePath, "/");
56
54
  };
57
55
 
58
- export const getArtifactsRegistryBuildCacheImage = (context: Context) => {
56
+ export const getArtifactsRegistryBuildCacheImage = (
57
+ context: ComponentContext,
58
+ ) => {
59
59
  const dockerUrl = getArtifactsRegistryDockerUrl(context);
60
60
  // does not include env, so that after merge, you might get more cache hits (review-->dev)
61
61
  const gcloudImagePath = [dockerUrl, "caches", context.componentName];
62
62
  return gcloudImagePath.join("/");
63
63
  };
64
64
 
65
- export const getArtifactsRegistryImage = (context: Context) =>
65
+ export const getArtifactsRegistryImage = (context: ComponentContext) =>
66
66
  `${getArtifactsRegistryImageName(context)}:$DOCKER_IMAGE_TAG`;
67
67
 
68
68
  const getDeleteImageCommands = (
@@ -96,11 +96,11 @@ const getDeleteImageCommands = (
96
96
  * @param keep how many of the newest images to keep
97
97
  * @returns
98
98
  */
99
- export const getDeleteUnusedImagesCommands = (context: Context, keep = 0) => {
100
- const deployConfig = context.componentConfig.deploy;
101
- if (deployConfig === false) {
102
- return [];
103
- }
99
+ export const getDeleteUnusedImagesCommands = (
100
+ context: ComponentContext,
101
+ keep = 0,
102
+ ) => {
103
+ const deployConfig = context.deploy?.config;
104
104
  if (!isOfDeployType(deployConfig, "google-cloudrun")) {
105
105
  // should not happen
106
106
  throw new Error("deploy config is wrong");
@@ -1,9 +1,9 @@
1
- import type { Context } from "../../types/context";
1
+ import type { ComponentContext } from "../../types/context";
2
2
  import { getDeleteUnusedImagesCommands } from "./artifactsRegistry";
3
3
  import { getDeleteUnusedRevisionsCommands } from "./cloudRunRevisions";
4
4
 
5
5
  export const getRemoveOldRevisionsAndImagesCommand = (
6
- context: Context,
6
+ context: ComponentContext,
7
7
  when: "postDeploy" | "onStop",
8
8
  ) => {
9
9
  if (when === "onStop") {
@@ -1,18 +1,19 @@
1
- import type { Context } from "../../types/context";
1
+ import type { ComponentContext } from "../../types/context";
2
2
  import { isOfDeployType } from "../types";
3
3
  import { createArgsString } from "./utils/createArgsString";
4
4
  import { getServiceName } from "./utils/getServiceName";
5
5
  import { removeFirstLinesFromCommandOutput } from "./utils/removeFirstLinesFromCommandOutput";
6
6
 
7
7
  const getListRevisionsCommand = (
8
- context: Context,
8
+ context: ComponentContext,
9
9
  args: {
10
10
  filter?: string;
11
11
  format: string;
12
12
  },
13
13
  ) => {
14
14
  const serviceName = getServiceName(context);
15
- const deployConfig = context.componentConfig.deploy;
15
+
16
+ const deployConfig = context.deploy?.config;
16
17
 
17
18
  if (!deployConfig || !isOfDeployType(deployConfig, "google-cloudrun")) {
18
19
  // should not happen
@@ -34,13 +35,10 @@ const getListRevisionsCommand = (
34
35
  };
35
36
 
36
37
  export const getDeleteUnusedRevisionsCommands = (
37
- context: Context,
38
+ context: ComponentContext,
38
39
  keep: number,
39
40
  ) => {
40
- const deployConfig = context.componentConfig.deploy;
41
- if (deployConfig === false) {
42
- return [];
43
- }
41
+ const deployConfig = context.deploy?.config;
44
42
  if (!isOfDeployType(deployConfig, "google-cloudrun")) {
45
43
  // should not happen
46
44
  throw new Error("deploy config is wrong");
@@ -1,4 +1,4 @@
1
- import type { Context } from "../../../types/context";
1
+ import type { ComponentContext } from "../../../types/context";
2
2
  import { allowFailureInScripts } from "../../../utils/gitlab";
3
3
 
4
4
  import type {
@@ -24,7 +24,7 @@ import type {
24
24
  import { ENV_VARS_FILENAME } from "./constants";
25
25
 
26
26
  const getJobRunScriptForJob = (
27
- context: Context,
27
+ context: ComponentContext,
28
28
  jobName: StringOrBashExpression,
29
29
  wait: boolean,
30
30
  ) => {
@@ -36,7 +36,7 @@ const getJobRunScriptForJob = (
36
36
  }`;
37
37
  };
38
38
 
39
- export const getDeleteSchedulesScripts = (context: Context) => {
39
+ export const getDeleteSchedulesScripts = (context: ComponentContext) => {
40
40
  const deployConfig = getCloudRunDeployConfig(context);
41
41
  const jobsWithSchedule = getCloudRunJobsWithSchedule(context);
42
42
  const argsString = createArgsString({
@@ -52,7 +52,7 @@ export const getDeleteSchedulesScripts = (context: Context) => {
52
52
  .flat();
53
53
  };
54
54
 
55
- export const getDeleteJobsScripts = (context: Context) => {
55
+ export const getDeleteJobsScripts = (context: ComponentContext) => {
56
56
  const commonArgs = getCommonCloudRunArgs(context);
57
57
  const commonArgsString = createArgsString(commonArgs);
58
58
  const jobsWithNames = getCloudRunJobsWithNames(context);
@@ -65,7 +65,7 @@ export const getDeleteJobsScripts = (context: Context) => {
65
65
  };
66
66
 
67
67
  export const getJobRunScripts = (
68
- context: Context,
68
+ context: ComponentContext,
69
69
  when: DeployConfigCloudRunJob["when"],
70
70
  ) => {
71
71
  const jobsWithNames = getCloudRunJobsWithNames(context);
@@ -81,7 +81,7 @@ export const getJobRunScripts = (
81
81
  );
82
82
  };
83
83
 
84
- export const getJobCreateScripts = (context: Context) => {
84
+ export const getJobCreateScripts = (context: ComponentContext) => {
85
85
  const jobsWithNames = getCloudRunJobsWithNames(context);
86
86
 
87
87
  return jobsWithNames
@@ -90,7 +90,7 @@ export const getJobCreateScripts = (context: Context) => {
90
90
  };
91
91
 
92
92
  const getJobCreateScriptsForJob = (
93
- context: Context,
93
+ context: ComponentContext,
94
94
  jobName: StringOrBashExpression,
95
95
  job: DeployConfigCloudRunJob,
96
96
  ) => {
@@ -132,7 +132,7 @@ const getJobCreateScriptsForJob = (
132
132
  ];
133
133
  };
134
134
 
135
- export const getCreateScheduleScripts = (context: Context) => {
135
+ export const getCreateScheduleScripts = (context: ComponentContext) => {
136
136
  const jobsWithSchedule = getCloudRunJobsWithSchedule(context);
137
137
  const deployConfig = getCloudRunDeployConfig(context);
138
138
 
@@ -160,7 +160,7 @@ export const getCreateScheduleScripts = (context: Context) => {
160
160
  .flat();
161
161
  };
162
162
 
163
- const getCloudRunJobsWithSchedule = (context: Context) => {
163
+ const getCloudRunJobsWithSchedule = (context: ComponentContext) => {
164
164
  const jobsWithNames = getCloudRunJobsWithNames(context);
165
165
 
166
166
  return jobsWithNames
@@ -179,7 +179,7 @@ const getCloudRunJobsWithSchedule = (context: Context) => {
179
179
  }));
180
180
  };
181
181
 
182
- const getCloudRunJobsWithNames = (context: Context) => {
182
+ const getCloudRunJobsWithNames = (context: ComponentContext) => {
183
183
  const deployConfig = getCloudRunDeployConfig(context);
184
184
 
185
185
  const getFullJobName = (name: string) =>
@@ -1,5 +1,5 @@
1
1
  import { getLabels } from "../../../context/getLabels";
2
- import type { Context } from "../../../types/context";
2
+ import type { ComponentContext } from "../../../types/context";
3
3
 
4
4
  import type { DeployConfigCloudRunService } from "../../types/googleCloudRun";
5
5
  import { createArgsString } from "../utils/createArgsString";
@@ -14,7 +14,7 @@ import { ENV_VARS_FILENAME } from "./constants";
14
14
  import { createVolumeConfig } from "./volumes";
15
15
 
16
16
  export const getServiceDeployScript = (
17
- context: Context,
17
+ context: ComponentContext,
18
18
  service: DeployConfigCloudRunService | true | undefined,
19
19
  nameSuffix?: string,
20
20
  ) => {
@@ -25,7 +25,7 @@ export const getServiceDeployScript = (
25
25
  const customConfig = service !== true ? service : undefined;
26
26
  const command =
27
27
  service !== true
28
- ? service?.command ?? context.componentConfig.build.startCommand
28
+ ? service?.command ?? context.build.config.startCommand
29
29
  : undefined;
30
30
 
31
31
  const commandArray = command
@@ -66,7 +66,7 @@ export const getServiceDeployScript = (
66
66
  };
67
67
 
68
68
  export const getServiceDeleteScript = (
69
- context: Context,
69
+ context: ComponentContext,
70
70
  serviceSuffix?: string,
71
71
  ) => {
72
72
  const commonArgs = getCommonCloudRunArgs(context);
@@ -30,7 +30,7 @@ export const makeLabelString = (obj: Record<string, unknown>) =>
30
30
  .join(",");
31
31
 
32
32
  export const getCloudRunDeployConfig = (context: Context) => {
33
- const deployConfig = context.componentConfig.deploy;
33
+ const deployConfig = context.deploy?.config;
34
34
  if (!isOfDeployType(deployConfig, "google-cloudrun")) {
35
35
  // should not happen
36
36
  throw new Error("deploy config is wrong");
@@ -1,5 +1,8 @@
1
1
  import { isNil, omit } from "lodash";
2
- import type { Context, UnspecifiedEnvVars } from "../../../types/context";
2
+ import type {
3
+ ComponentContext,
4
+ UnspecifiedEnvVars,
5
+ } from "../../../types/context";
3
6
  import { collapseableSection } from "../../../utils/gitlab";
4
7
  import { getDependencyTrackUploadScript } from "../../sbom";
5
8
 
@@ -25,7 +28,7 @@ import {
25
28
  yamlBashString,
26
29
  } from "../../../bash/bashYaml";
27
30
 
28
- export function getCloudRunDeployScripts(context: Context) {
31
+ export function getCloudRunDeployScripts(context: ComponentContext) {
29
32
  const deployConfig = getCloudRunDeployConfig(context);
30
33
  const allEnvVars = omit(
31
34
  context.environment.envVars,
@@ -1,4 +1,4 @@
1
- import type { Context } from "../../../types/context";
1
+ import type { ComponentContext } from "../../../types/context";
2
2
  import { getDependencyTrackDeleteScript } from "../../sbom";
3
3
 
4
4
  import { getRemoveOldRevisionsAndImagesCommand } from "../cleanup";
@@ -12,7 +12,7 @@ import {
12
12
  import { getServiceDeleteScript } from "./cloudRunServices";
13
13
  import { getCloudRunDeployConfig } from "./common";
14
14
 
15
- export function getCloudRunStopScripts(context: Context) {
15
+ export function getCloudRunStopScripts(context: ComponentContext) {
16
16
  const deployConfig = getCloudRunDeployConfig(context);
17
17
  return [
18
18
  ...gcloudServiceAccountLoginCommands(context),
@@ -1,5 +1,5 @@
1
1
  import { getRunnerImage } from "../../../runner";
2
- import type { Context } from "../../../types/context";
2
+ import type { ComponentContext } from "../../../types/context";
3
3
  import type { CatladderJob } from "../../../types/jobs";
4
4
  import { allowFailureInScripts } from "../../../utils/gitlab";
5
5
  import { createDeployementJobs } from "../../base";
@@ -10,12 +10,9 @@ import { getCloudRunDeployScripts } from "./getCloudRunDeployScripts";
10
10
  import { getCloudRunStopScripts } from "./getCloudRunStopScripts";
11
11
 
12
12
  export const createGoogleCloudRunDeployJobs = (
13
- context: Context,
13
+ context: ComponentContext,
14
14
  ): CatladderJob[] => {
15
- const deployConfig = context.componentConfig.deploy;
16
- if (deployConfig === false) {
17
- return [];
18
- }
15
+ const deployConfig = context.deploy?.config;
19
16
  if (!isOfDeployType(deployConfig, "google-cloudrun")) {
20
17
  // should not happen
21
18
  throw new Error("deploy config is wrong");
@@ -1,4 +1,4 @@
1
- import type { Context } from "../../../types";
1
+ import type { ComponentContext } from "../../../types";
2
2
  import { allowFailureInScripts, repeatOnFailure } from "../../../utils/gitlab";
3
3
  import type {
4
4
  DeployConfigCloudRun,
@@ -6,7 +6,7 @@ import type {
6
6
  } from "../../types";
7
7
 
8
8
  export const getDatabaseDeleteScript = (
9
- context: Context,
9
+ context: ComponentContext,
10
10
  deployConfig: DeployConfigCloudRun,
11
11
  ): string[] => {
12
12
  if (!deployConfig.cloudSql || !deployConfig.cloudSql.deleteDatabaseOnStop) {
@@ -35,7 +35,7 @@ export const getDatabaseDeleteScript = (
35
35
  };
36
36
 
37
37
  export const getDatabaseCreateScript = (
38
- context: Context,
38
+ context: ComponentContext,
39
39
  deployConfig: DeployConfigCloudRun,
40
40
  ): string[] => {
41
41
  if (!deployConfig.cloudSql) {
@@ -1,8 +1,10 @@
1
1
  import { GCLOUD_DEPLOY_CREDENTIALS_KEY } from "..";
2
2
  import { getSecretVarNameForContext } from "../../../context";
3
- import type { Context } from "../../../types";
3
+ import type { ComponentContext } from "../../../types";
4
4
 
5
- export const gcloudServiceAccountLoginCommands = (context: Context) => [
5
+ export const gcloudServiceAccountLoginCommands = (
6
+ context: ComponentContext,
7
+ ) => [
6
8
  `gcloud auth activate-service-account --key-file=<(echo "$${getSecretVarNameForContext(
7
9
  context,
8
10
  GCLOUD_DEPLOY_CREDENTIALS_KEY,
@@ -1,3 +1,3 @@
1
- import type { Context } from "../../../types/context";
2
- export const getServiceName = (context: Context) =>
1
+ import type { ComponentContext } from "../../../types/context";
2
+ export const getServiceName = (context: ComponentContext) =>
3
3
  context.environment.fullName.toLowerCase();
@@ -1,6 +1,6 @@
1
1
  import { getYarnInstall } from "../../build/node/yarn";
2
2
  import { getRunnerImage } from "../../runner";
3
- import type { Context } from "../../types/context";
3
+ import type { ComponentContext } from "../../types/context";
4
4
  import type { CatladderJob } from "../../types/jobs";
5
5
  import { createDeployementJobs } from "../base";
6
6
  import {
@@ -9,23 +9,25 @@ import {
9
9
  } from "../sbom";
10
10
  import { isOfDeployType } from "../types";
11
11
 
12
- export const createCustomDeployJobs = (context: Context): CatladderJob[] => {
13
- const deployConfig = context.componentConfig.deploy;
14
- if (deployConfig === false) {
15
- return [];
16
- }
12
+ export const createCustomDeployJobs = (
13
+ context: ComponentContext,
14
+ ): CatladderJob[] => {
15
+ const deployConfig = context.deploy?.config;
16
+
17
17
  if (!isOfDeployType(deployConfig, "custom")) {
18
18
  // should not happen
19
19
  throw new Error("deploy config is not custom");
20
20
  }
21
21
  // FIXME: custom deploy currently assumes yarn-based project
22
- const yarnInstall = getYarnInstall(context, { noCustomPostInstall: true });
22
+ const yarnInstall = getYarnInstall(context.build, {
23
+ noCustomPostInstall: true,
24
+ });
23
25
  return createDeployementJobs(context, {
24
26
  deploy: {
25
27
  image: deployConfig.jobImage ?? getRunnerImage("jobs-default"),
26
28
  cache: deployConfig.jobCache ?? [],
27
29
  script: [
28
- `cd ${context.componentConfig.dir}`,
30
+ `cd ${context.build.dir}`,
29
31
  ...(deployConfig.requiresYarnInstall ? yarnInstall : []),
30
32
  ...deployConfig.script,
31
33
  ...getDependencyTrackUploadScript(context),
@@ -1,15 +1,14 @@
1
1
  import { getDockerJobBaseProps, gitlabDockerLogin } from "../../build/docker";
2
2
 
3
- import type { Context } from "../../types/context";
3
+ import type { ComponentContext } from "../../types/context";
4
4
  import type { CatladderJob } from "../../types/jobs";
5
5
  import { createDeployementJobs } from "../base";
6
6
  import { isOfDeployType } from "../types";
7
7
 
8
- export const createDockerTagDeployJobs = (context: Context): CatladderJob[] => {
9
- const deployConfig = context.componentConfig.deploy;
10
- if (deployConfig === false) {
11
- return [];
12
- }
8
+ export const createDockerTagDeployJobs = (
9
+ context: ComponentContext,
10
+ ): CatladderJob[] => {
11
+ const deployConfig = context.deploy?.config;
13
12
  if (!isOfDeployType(deployConfig, "dockerTag")) {
14
13
  // should not happen
15
14
  throw new Error("deploy config is not dockerTag");
@@ -17,7 +16,7 @@ export const createDockerTagDeployJobs = (context: Context): CatladderJob[] => {
17
16
  const tag = deployConfig.tag;
18
17
  return createDeployementJobs(context, {
19
18
  deploy: {
20
- ...getDockerJobBaseProps(context),
19
+ ...getDockerJobBaseProps(),
21
20
  script: [
22
21
  ...gitlabDockerLogin(context),
23
22
  `docker pull $DOCKER_IMAGE:$DOCKER_IMAGE_TAG`,
@@ -1,6 +1,6 @@
1
1
  import type { SecretEnvVar } from "..";
2
2
  import type { BashExpression } from "../bash/BashExpression";
3
- import type { Context } from "../types/context";
3
+ import type { ComponentContext } from "../types/context";
4
4
  import type { EnvironmentContext } from "../types/environmentContext";
5
5
  import type { CatladderJob } from "../types/jobs";
6
6
  import type { PartialDeep } from "../types/utils";
@@ -15,7 +15,7 @@ export * from "./types";
15
15
  export * from "./utils";
16
16
 
17
17
  export type DeployTypeDefinition<T extends DeployConfigType> = {
18
- jobs: (context: Context) => CatladderJob[];
18
+ jobs: (context: ComponentContext) => CatladderJob[];
19
19
  defaults: (
20
20
  envContext: EnvironmentContext<any, T>,
21
21
  ) => PartialDeep<DeployConfigGeneric<T>>;