@catladder/pipeline 1.146.2 → 1.148.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 (94) hide show
  1. package/dist/build/base/createAppBuildJob.js +6 -6
  2. package/dist/build/base/writeBuildInfo.js +1 -1
  3. package/dist/build/base/writeDotEnv.js +1 -1
  4. package/dist/build/custom/__tests__/testJob.test.js +11 -14
  5. package/dist/build/custom/buildJob.js +5 -5
  6. package/dist/build/custom/testJob.js +5 -5
  7. package/dist/build/docker.d.ts +26 -9
  8. package/dist/build/docker.js +41 -20
  9. package/dist/build/node/buildJob.js +8 -8
  10. package/dist/build/node/cache.js +1 -1
  11. package/dist/build/node/meteor.js +6 -6
  12. package/dist/build/node/testJob.js +11 -11
  13. package/dist/build/rails/build.js +3 -3
  14. package/dist/build/rails/test.js +4 -4
  15. package/dist/build/sbom.js +2 -2
  16. package/dist/build/types.d.ts +34 -26
  17. package/dist/bundles/catladder-gitlab/index.js +2 -2
  18. package/dist/constants.js +1 -1
  19. package/dist/context/getLabels.js +1 -1
  20. package/dist/context/index.js +34 -12
  21. package/dist/deploy/base/deploy.js +9 -8
  22. package/dist/deploy/cloudRun/artifactsRegistry.d.ts +1 -5
  23. package/dist/deploy/cloudRun/artifactsRegistry.js +8 -9
  24. package/dist/deploy/cloudRun/cloudRunRevisions.js +4 -5
  25. package/dist/deploy/cloudRun/createJobs/cloudRunServices.js +1 -1
  26. package/dist/deploy/cloudRun/createJobs/common.d.ts +4 -4
  27. package/dist/deploy/cloudRun/createJobs/common.js +2 -1
  28. package/dist/deploy/cloudRun/createJobs/index.js +2 -4
  29. package/dist/deploy/custom/deployJob.js +7 -10
  30. package/dist/deploy/dockerTag/deployJob.js +3 -5
  31. package/dist/deploy/kubernetes/cloudSql/index.js +11 -9
  32. package/dist/deploy/kubernetes/deployJob.js +4 -7
  33. package/dist/deploy/kubernetes/kubeEnv.js +2 -1
  34. package/dist/deploy/kubernetes/kubeValues.js +10 -10
  35. package/dist/deploy/kubernetes/mongodb.js +11 -11
  36. package/dist/deploy/sbom.js +1 -1
  37. package/dist/deploy/types/index.d.ts +1 -1
  38. package/dist/deploy/types/index.js +1 -1
  39. package/dist/deploy/utils.js +2 -1
  40. package/dist/pipeline/createJobsForComponent.js +5 -5
  41. package/dist/pipeline/generatePipelineFiles.js +40 -9
  42. package/dist/pipeline/gitlab/createGitlabJobs.js +2 -9
  43. package/dist/pipeline/gitlab/sortGitLabJobDefProps.d.ts +7 -0
  44. package/dist/pipeline/gitlab/sortGitLabJobDefProps.js +27 -0
  45. package/dist/tsconfig.tsbuildinfo +1 -1
  46. package/dist/types/config.d.ts +1 -1
  47. package/dist/types/context.d.ts +13 -1
  48. package/dist/utils/removeUndefined.d.ts +1 -0
  49. package/dist/utils/removeUndefined.js +36 -0
  50. package/examples/__snapshots__/cloud-run-storybook.ts.snap +1687 -0
  51. package/examples/__snapshots__/cloud-run-with-ngnix.ts.snap +1971 -0
  52. package/examples/cloud-run-storybook.ts +24 -0
  53. package/examples/cloud-run-with-ngnix.ts +24 -0
  54. package/package.json +1 -1
  55. package/src/build/base/createAppBuildJob.ts +7 -7
  56. package/src/build/base/writeBuildInfo.ts +1 -1
  57. package/src/build/base/writeDotEnv.ts +1 -1
  58. package/src/build/custom/__tests__/testJob.test.ts +5 -8
  59. package/src/build/custom/buildJob.ts +6 -9
  60. package/src/build/custom/testJob.ts +5 -5
  61. package/src/build/docker.ts +68 -24
  62. package/src/build/node/buildJob.ts +12 -12
  63. package/src/build/node/cache.ts +1 -1
  64. package/src/build/node/meteor.ts +11 -17
  65. package/src/build/node/testJob.ts +14 -14
  66. package/src/build/rails/build.ts +3 -3
  67. package/src/build/rails/test.ts +4 -4
  68. package/src/build/sbom.ts +3 -3
  69. package/src/build/types.ts +53 -38
  70. package/src/context/getLabels.ts +1 -1
  71. package/src/context/index.ts +21 -5
  72. package/src/deploy/base/deploy.ts +8 -14
  73. package/src/deploy/cloudRun/artifactsRegistry.ts +5 -10
  74. package/src/deploy/cloudRun/cloudRunRevisions.ts +3 -5
  75. package/src/deploy/cloudRun/createJobs/cloudRunServices.ts +1 -1
  76. package/src/deploy/cloudRun/createJobs/common.ts +5 -5
  77. package/src/deploy/cloudRun/createJobs/index.ts +1 -4
  78. package/src/deploy/custom/deployJob.ts +4 -6
  79. package/src/deploy/dockerTag/deployJob.ts +2 -5
  80. package/src/deploy/kubernetes/cloudSql/index.ts +7 -4
  81. package/src/deploy/kubernetes/deployJob.ts +1 -4
  82. package/src/deploy/kubernetes/kubeEnv.ts +1 -1
  83. package/src/deploy/kubernetes/kubeValues.ts +3 -3
  84. package/src/deploy/kubernetes/mongodb.ts +6 -6
  85. package/src/deploy/sbom.ts +1 -2
  86. package/src/deploy/types/index.ts +2 -2
  87. package/src/deploy/utils.ts +1 -1
  88. package/src/pipeline/createJobsForComponent.ts +6 -10
  89. package/src/pipeline/generatePipelineFiles.ts +21 -8
  90. package/src/pipeline/gitlab/createGitlabJobs.ts +2 -7
  91. package/src/pipeline/gitlab/sortGitLabJobDefProps.ts +59 -0
  92. package/src/types/config.ts +3 -1
  93. package/src/types/context.ts +16 -1
  94. package/src/utils/removeUndefined.ts +4 -0
@@ -11,7 +11,7 @@ export const createRailsTestJobs = (
11
11
  return [];
12
12
  }
13
13
 
14
- const buildConfig = context.componentConfig.build;
14
+ const buildConfig = context.build.config;
15
15
 
16
16
  const base: Omit<CatladderJob, "script" | "name"> = {
17
17
  variables: {
@@ -45,7 +45,7 @@ export const createRailsTestJobs = (
45
45
  image:
46
46
  buildConfig.audit?.jobImage ?? buildConfig.jobImage ?? defaultImage,
47
47
  script: [
48
- `cd ${context.componentConfig.dir}`,
48
+ `cd ${context.build.dir}`,
49
49
  ...(ensureArray(buildConfig.audit?.command) ?? [
50
50
  "gem install bundler-audit",
51
51
  "bundle audit check",
@@ -65,7 +65,7 @@ export const createRailsTestJobs = (
65
65
  image:
66
66
  buildConfig.lint?.jobImage ?? buildConfig.jobImage ?? defaultImage,
67
67
  script: [
68
- `cd ${context.componentConfig.dir}`,
68
+ `cd ${context.build.dir}`,
69
69
  ...bundlerInstall,
70
70
  ...(ensureArray(buildConfig.lint?.command) ?? [
71
71
  "bundle exec rubocop",
@@ -83,7 +83,7 @@ export const createRailsTestJobs = (
83
83
  image:
84
84
  buildConfig.test?.jobImage ?? buildConfig.jobImage ?? defaultImage,
85
85
  script: [
86
- `cd ${context.componentConfig.dir}`,
86
+ `cd ${context.build.dir}`,
87
87
  ...bundlerInstall,
88
88
  ...(ensureArray(buildConfig.test?.command) ?? [
89
89
  "bundle exec rspec",
package/src/build/sbom.ts CHANGED
@@ -6,14 +6,14 @@ export const SBOM_BUILD_JOB_NAME = "🧾 sbom";
6
6
  export const SBOM_FILE = "__sbom.json";
7
7
 
8
8
  export const createSbomBuildJob = (context: ComponentContext): CatladderJob => {
9
- const buildConfig = context.componentConfig.build;
9
+ const buildConfig = context.build.config;
10
10
 
11
11
  const defaultImage = "aquasec/trivy:0.38.3";
12
12
  const defaultScript = [
13
13
  `trivy fs --quiet --format cyclonedx --output "${SBOM_FILE}" ${
14
- context.buildContext.packageManagerInfo?.componentIsInWorkspace
14
+ context.build.packageManagerInfo?.componentIsInWorkspace
15
15
  ? "."
16
- : context.buildContext.dir
16
+ : context.build.dir
17
17
  }`,
18
18
  ];
19
19
 
@@ -58,28 +58,6 @@ export type BuildConfigBase = {
58
58
  */
59
59
  buildCommand?: string | string[] | null;
60
60
 
61
- /**
62
- * customize docker build
63
- */
64
- docker?: {
65
- /**
66
- * Custom Dockerfile lines integrated in the generated Dockerfile before the standard build steps.
67
- *
68
- * - [runner-images/docker-build/scripts/ensureNodeDockerfile](https://git.panter.ch/catladder/catladder/-/tree/main/runner-images/docker-build/scripts/ensureNodeDockerfile)
69
- * - [runner-images/docker-build/scripts/ensureNginxDockerfile](https://git.panter.ch/catladder/catladder/-/tree/main/runner-images/docker-build/scripts/ensureNginxDockerfile)
70
- * - [runner-images/docker-build/scripts/ensureMeteorDockerfile](https://git.panter.ch/catladder/catladder/-/tree/main/runner-images/docker-build/scripts/ensureMeteorDockerfile)
71
- */
72
- additionsBegin?: string[];
73
- /**
74
- * Custom Dockerfile lines integrated in the generated Dockerfile after the standard build steps.
75
- *
76
- * - [runner-images/docker-build/scripts/ensureNodeDockerfile](https://git.panter.ch/catladder/catladder/-/tree/main/runner-images/docker-build/scripts/ensureNodeDockerfile)
77
- * - [runner-images/docker-build/scripts/ensureNginxDockerfile](https://git.panter.ch/catladder/catladder/-/tree/main/runner-images/docker-build/scripts/ensureNginxDockerfile)
78
- * - [runner-images/docker-build/scripts/ensureMeteorDockerfile](https://git.panter.ch/catladder/catladder/-/tree/main/runner-images/docker-build/scripts/ensureMeteorDockerfile)
79
- */
80
- additionsEnd?: string[];
81
- };
82
-
83
61
  /**
84
62
  * customize lint, set false to disable
85
63
  */
@@ -132,11 +110,13 @@ export type BuildConfigNodeBase = BuildConfigBase & {
132
110
 
133
111
  export type BuildConfigNode = {
134
112
  type: "node";
113
+ docker?: Omit<BuildConfigDockerBuiltInNode, "type"> | BuildConfigDocker;
135
114
  } & BuildConfigNodeBase;
136
115
 
137
116
  export type BuildConfigNodeStatic = BuildConfigNodeBase & {
138
117
  type: "node-static";
139
118
  startCommand?: never;
119
+ docker?: Omit<BuildConfigDockerBuiltInNgninx, "type"> | BuildConfigDocker;
140
120
  };
141
121
 
142
122
  export type BuildConfigMeteor = BuildConfigNodeBase & {
@@ -146,23 +126,58 @@ export type BuildConfigMeteor = BuildConfigNodeBase & {
146
126
  * This is only required if you have custom scripts in your image
147
127
  */
148
128
  installScripts?: boolean;
129
+ docker?: Omit<BuildConfigDockerBuiltInMeteor, "type"> | BuildConfigDocker;
149
130
  };
150
131
 
151
- export type BuildConfigCustomDocker = BuildConfigBase["docker"] &
152
- (
153
- | {
154
- /**
155
- * use the built-in nginx image for simple static apps
156
- */
157
- type: "nginx";
158
- }
159
- | {
160
- /**
161
- * custom docker build, expect that a Dockerfile in your directory
162
- */
163
- type: "custom";
164
- }
165
- );
132
+ type BuildConfigDockerWithAdditions = {
133
+ /**
134
+ * Custom Dockerfile lines integrated in the generated Dockerfile before the standard build steps.
135
+ *
136
+ */
137
+ additionsBegin?: string[];
138
+ /**
139
+ * Custom Dockerfile lines integrated in the generated Dockerfile after the standard build steps.
140
+ *
141
+ */
142
+ additionsEnd?: string[];
143
+ };
144
+
145
+ type BuildConfigDockerBuiltInNode = {
146
+ type: "node";
147
+ } & BuildConfigDockerWithAdditions;
148
+
149
+ type BuildConfigDockerBuiltInMeteor = {
150
+ type: "meteor";
151
+ } & BuildConfigDockerWithAdditions;
152
+
153
+ type BuildConfigDockerBuiltInNgninx = {
154
+ /**
155
+ * use the built-in nginx image for simple static apps
156
+ */
157
+ type: "nginx";
158
+ } & BuildConfigDockerWithAdditions;
159
+ type BuildConfigDockerBuiltIn =
160
+ | BuildConfigDockerBuiltInNgninx
161
+ | BuildConfigDockerBuiltInNode
162
+ | BuildConfigDockerBuiltInMeteor;
163
+
164
+ type BuildConfigDockerCustom = {
165
+ /**
166
+ * custom docker build, expect that a Dockerfile in your directory
167
+ */
168
+ type: "custom";
169
+ };
170
+
171
+ export type BuildConfigDocker =
172
+ | BuildConfigDockerBuiltIn
173
+ | BuildConfigDockerCustom;
174
+
175
+ /**
176
+ * @deprecated this type is no longer used. Use {@link BuildConfigDocker} instead.
177
+ */
178
+ export type BuildConfigCustomDocker =
179
+ | BuildConfigDockerCustom
180
+ | BuildConfigDockerBuiltInNgninx;
166
181
 
167
182
  export type BuildConfigCustom = Omit<
168
183
  BuildConfigBase,
@@ -175,7 +190,7 @@ export type BuildConfigCustom = Omit<
175
190
  */
176
191
  jobServices?: Services;
177
192
 
178
- docker: BuildConfigCustomDocker;
193
+ docker: BuildConfigDocker;
179
194
 
180
195
  /**
181
196
  * custom lint, disabled when not set
@@ -14,7 +14,7 @@ export const getLabels = (context: ComponentContext) => {
14
14
  "app-name": sanitize(context.fullConfig.appName),
15
15
  "env-type": sanitize(context.environment.envType),
16
16
  "env-name": sanitize(context.environment.shortName),
17
- "build-type": sanitize(context.componentConfig.build?.type),
17
+ "build-type": sanitize(context.build.config?.type),
18
18
  ...(context.fullConfig.meta?.labels ?? {}),
19
19
  };
20
20
  return labels;
@@ -1,3 +1,4 @@
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";
@@ -56,20 +57,35 @@ export const createComponentContext = 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,
62
- buildContext: {
63
- dir: componentConfig.dir,
65
+
66
+ build: {
67
+ dir: dir,
64
68
  packageManagerInfo: ctx.packageManagerInfo,
65
- config: componentConfig.build,
69
+ config: build,
66
70
  },
71
+ deploy: deploy
72
+ ? {
73
+ config: deploy,
74
+ }
75
+ : null,
67
76
  componentName: ctx.componentName,
68
- environment: await getEnvironment(ctx),
77
+ environment,
69
78
  packageManagerInfo: ctx.packageManagerInfo,
70
79
  pipelineType: ctx.pipelineType,
71
80
  trigger: ctx.trigger,
72
81
  };
82
+ const resolvedCustomJobs = isFunction(customJobs)
83
+ ? customJobs(context)
84
+ : customJobs;
85
+ return {
86
+ ...context,
87
+ customJobs: resolvedCustomJobs,
88
+ };
73
89
  };
74
90
 
75
91
  /**
@@ -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
  };
@@ -5,18 +5,16 @@ 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
- }: ComponentContext) => {
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
16
  export const getArtifactsRegistryDockerUrl = (context: ComponentContext) => {
19
- const deployConfig = context.componentConfig.deploy;
17
+ const deployConfig = context.deploy?.config;
20
18
 
21
19
  if (!isOfDeployType(deployConfig, "google-cloudrun")) {
22
20
  // should not happen
@@ -102,10 +100,7 @@ export const getDeleteUnusedImagesCommands = (
102
100
  context: ComponentContext,
103
101
  keep = 0,
104
102
  ) => {
105
- const deployConfig = context.componentConfig.deploy;
106
- if (deployConfig === false) {
107
- return [];
108
- }
103
+ const deployConfig = context.deploy?.config;
109
104
  if (!isOfDeployType(deployConfig, "google-cloudrun")) {
110
105
  // should not happen
111
106
  throw new Error("deploy config is wrong");
@@ -12,7 +12,8 @@ const getListRevisionsCommand = (
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
@@ -37,10 +38,7 @@ export const getDeleteUnusedRevisionsCommands = (
37
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");
@@ -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
@@ -1,4 +1,4 @@
1
- import type { ComponentContext } from "../../../types/context";
1
+ import type { Context } from "../../../types/context";
2
2
 
3
3
  import { isOfDeployType } from "../../types";
4
4
  import type { DeployConfigCloudRun } from "../../types/googleCloudRun";
@@ -29,8 +29,8 @@ export const makeLabelString = (obj: Record<string, unknown>) =>
29
29
  .map(([key, value]) => `${key}=${value}`)
30
30
  .join(",");
31
31
 
32
- export const getCloudRunDeployConfig = (context: ComponentContext) => {
33
- const deployConfig = context.componentConfig.deploy;
32
+ export const getCloudRunDeployConfig = (context: Context) => {
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");
@@ -38,7 +38,7 @@ export const getCloudRunDeployConfig = (context: ComponentContext) => {
38
38
  return deployConfig;
39
39
  };
40
40
 
41
- export function getCommonCloudRunArgs(context: ComponentContext) {
41
+ export function getCommonCloudRunArgs(context: Context) {
42
42
  const deployConfig = getCloudRunDeployConfig(context);
43
43
  return {
44
44
  project: deployConfig.projectId,
@@ -46,7 +46,7 @@ export function getCommonCloudRunArgs(context: ComponentContext) {
46
46
  };
47
47
  }
48
48
 
49
- export function getCommonDeployArgs(context: ComponentContext) {
49
+ export function getCommonDeployArgs(context: Context) {
50
50
  const commonArgs = getCommonCloudRunArgs(context);
51
51
  const deployConfig = getCloudRunDeployConfig(context);
52
52
  return {
@@ -12,10 +12,7 @@ import { getCloudRunStopScripts } from "./getCloudRunStopScripts";
12
12
  export const createGoogleCloudRunDeployJobs = (
13
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");
@@ -12,16 +12,14 @@ import { isOfDeployType } from "../types";
12
12
  export const createCustomDeployJobs = (
13
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;
16
+
19
17
  if (!isOfDeployType(deployConfig, "custom")) {
20
18
  // should not happen
21
19
  throw new Error("deploy config is not custom");
22
20
  }
23
21
  // FIXME: custom deploy currently assumes yarn-based project
24
- const yarnInstall = getYarnInstall(context.buildContext, {
22
+ const yarnInstall = getYarnInstall(context.build, {
25
23
  noCustomPostInstall: true,
26
24
  });
27
25
  return createDeployementJobs(context, {
@@ -29,7 +27,7 @@ export const createCustomDeployJobs = (
29
27
  image: deployConfig.jobImage ?? getRunnerImage("jobs-default"),
30
28
  cache: deployConfig.jobCache ?? [],
31
29
  script: [
32
- `cd ${context.componentConfig.dir}`,
30
+ `cd ${context.build.dir}`,
33
31
  ...(deployConfig.requiresYarnInstall ? yarnInstall : []),
34
32
  ...deployConfig.script,
35
33
  ...getDependencyTrackUploadScript(context),
@@ -8,10 +8,7 @@ import { isOfDeployType } from "../types";
8
8
  export const createDockerTagDeployJobs = (
9
9
  context: ComponentContext,
10
10
  ): CatladderJob[] => {
11
- const deployConfig = context.componentConfig.deploy;
12
- if (deployConfig === false) {
13
- return [];
14
- }
11
+ const deployConfig = context.deploy?.config;
15
12
  if (!isOfDeployType(deployConfig, "dockerTag")) {
16
13
  // should not happen
17
14
  throw new Error("deploy config is not dockerTag");
@@ -19,7 +16,7 @@ export const createDockerTagDeployJobs = (
19
16
  const tag = deployConfig.tag;
20
17
  return createDeployementJobs(context, {
21
18
  deploy: {
22
- ...getDockerJobBaseProps(context),
19
+ ...getDockerJobBaseProps(),
23
20
  script: [
24
21
  ...gitlabDockerLogin(context),
25
22
  `docker pull $DOCKER_IMAGE:$DOCKER_IMAGE_TAG`,
@@ -5,8 +5,10 @@ import { getFullDbName } from "../../cloudSql/utils";
5
5
  import { isOfDeployType } from "../../types";
6
6
 
7
7
  export const hasKubernetesCloudSQL = (context: ComponentContext) => {
8
- if (isOfDeployType(context.componentConfig.deploy, "kubernetes")) {
9
- return context.componentConfig.deploy.values?.cloudsql?.enabled;
8
+ const deployConfig = context.deploy?.config;
9
+
10
+ if (isOfDeployType(deployConfig, "kubernetes")) {
11
+ return deployConfig.values?.cloudsql?.enabled;
10
12
  }
11
13
  return false;
12
14
  };
@@ -24,11 +26,12 @@ export const createKubernetesCloudsqlBaseValues = (
24
26
  ): {
25
27
  cloudsql: CloudSqlValues;
26
28
  } => {
27
- if (!isOfDeployType(context.componentConfig.deploy, "kubernetes")) {
29
+ const deployConfig = context.deploy?.config;
30
+ if (!isOfDeployType(deployConfig, "kubernetes")) {
28
31
  throw new Error("cannot get cloud sql config");
29
32
  }
30
33
 
31
- const config = context.componentConfig.deploy.values?.cloudsql;
34
+ const config = deployConfig.values?.cloudsql;
32
35
 
33
36
  if (!config) {
34
37
  throw new Error("cannot get cloud sql config");
@@ -17,10 +17,7 @@ const ALL_VALUES_FILE = "__all_values.yml";
17
17
  export const createKubernetesDeployJobs = (
18
18
  context: ComponentContext,
19
19
  ): CatladderJob[] => {
20
- const deployConfig = context.componentConfig.deploy;
21
- if (deployConfig === false) {
22
- return [];
23
- }
20
+ const deployConfig = context.deploy?.config;
24
21
  if (!isOfDeployType(deployConfig, "kubernetes")) {
25
22
  // should not happen
26
23
  throw new Error("deploy config is not kubernetes");
@@ -15,7 +15,7 @@ const shouldGoIntoSecrets = (key: string, value: string | undefined) => {
15
15
  * we evalulate the actual values later, but want to store the secrets in kubernetes secrets
16
16
  */
17
17
  export const createKubeEnv = (context: ComponentContext) => {
18
- if (!isOfDeployType(context.componentConfig.deploy, "kubernetes")) {
18
+ if (!isOfDeployType(context.deploy?.config, "kubernetes")) {
19
19
  // should not happen
20
20
  throw new Error("deploy config is not kubernetes");
21
21
  }
@@ -28,7 +28,7 @@ const createAppConfig = (
28
28
  return mergeWithMergingArrays(
29
29
  {
30
30
  host: context.environment.host,
31
- command: command ?? context.componentConfig.build.startCommand,
31
+ command: command ?? context.build.config.startCommand,
32
32
  livenessProbe: {
33
33
  httpGet: {
34
34
  path: healthRoute ?? "__health",
@@ -57,8 +57,8 @@ const removeFalsy = <T>(record?: Record<string, false | T>) => {
57
57
  };
58
58
 
59
59
  export const createKubeValues = (context: ComponentContext) => {
60
- const deployConfig = context.componentConfig.deploy;
61
- if (deployConfig === false) {
60
+ const deployConfig = context.deploy?.config;
61
+ if (!deployConfig) {
62
62
  return [];
63
63
  }
64
64
  if (!isOfDeployType(deployConfig, "kubernetes")) {
@@ -23,10 +23,10 @@ const getMongodbReplicasetHost = (context: ComponentContext, index: number) => {
23
23
  );
24
24
  };
25
25
  const createMongodbUrl = (context: ComponentContext, dbName: string) => {
26
- if (!isOfDeployType(context.componentConfig.deploy, "kubernetes")) {
26
+ if (!isOfDeployType(context.deploy?.config, "kubernetes")) {
27
27
  throw new Error("can only createMongodbUrl on supported deploys");
28
28
  }
29
- const mongodbConfig = context.componentConfig.deploy.values?.mongodb;
29
+ const mongodbConfig = context.deploy?.config.values?.mongodb;
30
30
 
31
31
  let queryParams: string | undefined = undefined;
32
32
 
@@ -47,10 +47,10 @@ const createMongodbUrl = (context: ComponentContext, dbName: string) => {
47
47
  }`;
48
48
  };
49
49
  const createMongoBackupDefaultConfig = (context: ComponentContext) => {
50
- if (!isOfDeployType(context.componentConfig.deploy, "kubernetes")) {
50
+ if (!isOfDeployType(context.deploy?.config, "kubernetes")) {
51
51
  throw new Error("can only create mongodb base config on supported deploys");
52
52
  }
53
- const mongodbConfig = context.componentConfig.deploy.values?.mongodb;
53
+ const mongodbConfig = context.deploy?.config.values?.mongodb;
54
54
  const fullAppName = context.environment.envVars.KUBE_APP_NAME;
55
55
  const backupEnabled = ["prod", "stage"].includes(context.environment.envType);
56
56
 
@@ -84,10 +84,10 @@ const createMongoBackupDefaultConfig = (context: ComponentContext) => {
84
84
  };
85
85
  };
86
86
  export const createMongodbBaseConfig = (context: ComponentContext) => {
87
- if (!isOfDeployType(context.componentConfig.deploy, "kubernetes")) {
87
+ if (!isOfDeployType(context.deploy?.config, "kubernetes")) {
88
88
  throw new Error("can only create mongodb base config on supported deploys");
89
89
  }
90
- const mongodbConfig = context.componentConfig.deploy.values?.mongodb;
90
+ const mongodbConfig = context.deploy?.config.values?.mongodb;
91
91
 
92
92
  return {
93
93
  mongodb: {
@@ -2,8 +2,7 @@ import type { ComponentContext } from "../types/context";
2
2
  import { SBOM_FILE } from "../build/sbom";
3
3
 
4
4
  export const sbomDeactivated = (context: ComponentContext) =>
5
- context.componentConfig.build.type === "custom" &&
6
- context.componentConfig.build.sbom === false;
5
+ context.build.config.type === "custom" && context.build.config.sbom === false;
7
6
 
8
7
  export const getDependencyTrackUploadScript = (
9
8
  context: ComponentContext,
@@ -21,8 +21,8 @@ export type DeployConfigGeneric<T extends DeployConfigType> = Extract<
21
21
  >;
22
22
 
23
23
  export const isOfDeployType = <T extends Array<DeployConfigType>>(
24
- t: DeployConfig | false,
24
+ t: DeployConfig | false | null | undefined,
25
25
  ...types: T
26
26
  ): t is Extract<DeployConfig, { type: T[number] }> => {
27
- return t && types.includes(t.type);
27
+ return t && types.includes(t.type) ? true : false;
28
28
  };
@@ -18,7 +18,7 @@ export const getKubernetesNamespace = (
18
18
  };
19
19
 
20
20
  export const contextIsStoppable = (context: ComponentContext) => {
21
- const deployConfig = context.componentConfig.deploy;
21
+ const deployConfig = context.deploy?.config;
22
22
  if (isOfDeployType(deployConfig, "kubernetes")) {
23
23
  return true;
24
24
  }
@@ -23,21 +23,17 @@ const injectDefaultVarsInCustomJobs = (
23
23
  ...job,
24
24
  }));
25
25
  const getCustomJobs = (context: ComponentContext) => {
26
- if (!context.componentConfig.customJobs) {
26
+ if (!context.customJobs) {
27
27
  return [];
28
28
  }
29
- const rawJobs = isFunction(context.componentConfig.customJobs)
30
- ? context.componentConfig.customJobs(context)
31
- : context.componentConfig.customJobs;
29
+ const rawJobs = context.customJobs;
32
30
  return injectDefaultVarsInCustomJobs(context, rawJobs);
33
31
  };
34
32
  const createRawJobs = (context: Context): CatladderJob[] => {
35
- const buildJobs =
36
- BUILD_TYPES[context.componentConfig.build.type].jobs(context);
37
- const deployJobs =
38
- context.componentConfig.deploy !== false
39
- ? DEPLOY_TYPES[context.componentConfig.deploy.type].jobs(context)
40
- : [];
33
+ const buildJobs = BUILD_TYPES[context.build.config.type].jobs(context);
34
+ const deployJobs = context.deploy?.config
35
+ ? DEPLOY_TYPES[context.deploy?.config.type].jobs(context)
36
+ : [];
41
37
 
42
38
  const customJobs = getCustomJobs(context);
43
39
  return [...buildJobs, ...deployJobs, ...customJobs];