@catladder/pipeline 1.153.0 → 1.154.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/artifacts/createBuildJobArtifact.d.ts +3 -0
  2. package/dist/build/artifacts/createBuildJobArtifact.js +97 -0
  3. package/dist/build/base/createAppBuildJob.d.ts +3 -3
  4. package/dist/build/base/createAppBuildJob.js +9 -15
  5. package/dist/build/base/index.d.ts +6 -2
  6. package/dist/build/base/index.js +14 -5
  7. package/dist/build/base/writeDotEnv.js +2 -1
  8. package/dist/build/custom/__tests__/testJob.test.js +1 -1
  9. package/dist/build/custom/buildJob.js +3 -10
  10. package/dist/build/docker.js +3 -3
  11. package/dist/build/index.d.ts +13 -6
  12. package/dist/build/index.js +29 -7
  13. package/dist/build/node/buildJob.d.ts +7 -2
  14. package/dist/build/node/buildJob.js +40 -33
  15. package/dist/build/node/cache.d.ts +2 -2
  16. package/dist/build/node/cache.js +8 -4
  17. package/dist/build/node/index.d.ts +2 -2
  18. package/dist/build/node/meteor.js +3 -6
  19. package/dist/build/node/testJob.d.ts +3 -2
  20. package/dist/build/node/testJob.js +9 -4
  21. package/dist/build/node/yarn.js +1 -1
  22. package/dist/build/rails/build.d.ts +1 -1
  23. package/dist/build/rails/build.js +7 -2
  24. package/dist/build/rails/test.d.ts +1 -1
  25. package/dist/build/rails/test.js +5 -0
  26. package/dist/build/sbom.js +3 -2
  27. package/dist/build/types.d.ts +48 -4
  28. package/dist/build/types.js +7 -1
  29. package/dist/bundles/catladder-gitlab/index.js +2 -2
  30. package/dist/constants.js +1 -1
  31. package/dist/context/createAllComponentsContext.d.ts +12 -0
  32. package/dist/context/createAllComponentsContext.js +159 -0
  33. package/dist/context/createComponentContext.d.ts +1 -5
  34. package/dist/context/createComponentContext.js +82 -20
  35. package/dist/context/createWorkspaceContext.d.ts +16 -0
  36. package/dist/context/createWorkspaceContext.js +173 -0
  37. package/dist/context/getBuildInfoVariables.d.ts +1 -1
  38. package/dist/context/getEnvironmentContext.d.ts +1 -1
  39. package/dist/context/getEnvironmentVariables.d.ts +2 -2
  40. package/dist/context/getEnvironmentVariables.js +5 -4
  41. package/dist/context/getLabels.js +5 -5
  42. package/dist/deploy/base/deploy.d.ts +1 -1
  43. package/dist/deploy/base/deploy.js +18 -5
  44. package/dist/deploy/cloudRun/artifactsRegistry.js +2 -2
  45. package/dist/deploy/cloudRun/createJobs/common.d.ts +4 -4
  46. package/dist/deploy/cloudRun/index.d.ts +2 -2
  47. package/dist/deploy/custom/index.d.ts +2 -2
  48. package/dist/deploy/dockerTag/index.d.ts +2 -2
  49. package/dist/deploy/index.d.ts +7 -7
  50. package/dist/deploy/kubernetes/additionalSecretKeys.d.ts +3 -1
  51. package/dist/deploy/kubernetes/cloudSql/index.js +1 -1
  52. package/dist/deploy/kubernetes/deployJob.js +2 -2
  53. package/dist/deploy/kubernetes/index.d.ts +2 -2
  54. package/dist/deploy/sbom.d.ts +1 -1
  55. package/dist/deploy/sbom.js +4 -3
  56. package/dist/deploy/types/index.d.ts +3 -3
  57. package/dist/pipeline/createAllJobs.d.ts +12 -10
  58. package/dist/pipeline/createAllJobs.js +94 -51
  59. package/dist/pipeline/createJobsForComponent.js +2 -3
  60. package/dist/pipeline/createJobsForWorkspace.d.ts +3 -0
  61. package/dist/pipeline/createJobsForWorkspace.js +12 -0
  62. package/dist/pipeline/createMainPipeline.js +26 -6
  63. package/dist/pipeline/gitlab/createGitlabJobs.d.ts +3 -16
  64. package/dist/pipeline/gitlab/createGitlabJobs.js +191 -73
  65. package/dist/pipeline/packageManager.d.ts +3 -2
  66. package/dist/pipeline/packageManager.js +43 -15
  67. package/dist/tsconfig.tsbuildinfo +1 -1
  68. package/dist/types/config.d.ts +5 -4
  69. package/dist/types/context.d.ts +80 -12
  70. package/dist/types/context.js +10 -1
  71. package/dist/types/environmentContext.d.ts +5 -6
  72. package/dist/types/jobs.d.ts +5 -0
  73. package/examples/__snapshots__/cloud-run-memory-limit.ts.snap +8 -8
  74. package/examples/__snapshots__/cloud-run-meteor-with-worker.ts.snap +8 -0
  75. package/examples/__snapshots__/cloud-run-no-cpu-throttling.ts.snap +8 -8
  76. package/examples/__snapshots__/cloud-run-no-service.ts.snap +8 -8
  77. package/examples/__snapshots__/cloud-run-non-public.ts.snap +8 -8
  78. package/examples/__snapshots__/cloud-run-post-stop-job.ts.snap +8 -8
  79. package/examples/__snapshots__/cloud-run-service-gen2.ts.snap +8 -8
  80. package/examples/__snapshots__/cloud-run-service-increase-timout.ts.snap +8 -8
  81. package/examples/__snapshots__/cloud-run-service-with-volumes.ts.snap +8 -8
  82. package/examples/__snapshots__/cloud-run-storybook.ts.snap +4 -8
  83. package/examples/__snapshots__/cloud-run-with-ngnix.ts.snap +4 -8
  84. package/examples/__snapshots__/cloud-run-with-sql-reuse-db.ts.snap +16 -16
  85. package/examples/__snapshots__/cloud-run-with-sql.ts.snap +589 -1097
  86. package/examples/__snapshots__/cloud-run-with-worker.ts.snap +8 -8
  87. package/examples/__snapshots__/custom-build-job-with-tests.ts.snap +4 -0
  88. package/examples/__snapshots__/custom-build-job.ts.snap +4 -0
  89. package/examples/__snapshots__/custom-deploy.ts.snap +8 -8
  90. package/examples/__snapshots__/custom-envs.ts.snap +18 -12
  91. package/examples/__snapshots__/custom-sbom-java.ts.snap +4 -0
  92. package/examples/__snapshots__/kubernetes-application-customization.ts.snap +8 -8
  93. package/examples/__snapshots__/kubernetes-with-cloud-sql-legacy.ts.snap +8 -8
  94. package/examples/__snapshots__/kubernetes-with-cloud-sql.ts.snap +8 -8
  95. package/examples/__snapshots__/kubernetes-with-jobs.ts.snap +16 -16
  96. package/examples/__snapshots__/kubernetes-with-mongodb.ts.snap +8 -8
  97. package/examples/__snapshots__/local-dot-env.ts.snap +8 -8
  98. package/examples/__snapshots__/meteor-kubernetes.ts.snap +8 -0
  99. package/examples/__snapshots__/multiline-var.ts.snap +16 -16
  100. package/examples/__snapshots__/native-app.ts.snap +24 -16
  101. package/examples/__snapshots__/node-build-with-custom-image.ts.snap +8 -8
  102. package/examples/__snapshots__/node-build-with-docker-additions.ts.snap +8 -8
  103. package/examples/__snapshots__/wait-for-other-deploy.ts.snap +16 -16
  104. package/examples/cloud-run-with-sql.ts +9 -2
  105. package/package.json +1 -1
  106. package/src/build/artifacts/createBuildJobArtifact.ts +61 -0
  107. package/src/build/base/createAppBuildJob.ts +26 -22
  108. package/src/build/base/index.ts +31 -4
  109. package/src/build/base/writeDotEnv.ts +6 -2
  110. package/src/build/custom/__tests__/testJob.test.ts +4 -4
  111. package/src/build/custom/buildJob.ts +2 -13
  112. package/src/build/docker.ts +6 -8
  113. package/src/build/index.ts +39 -7
  114. package/src/build/node/buildJob.ts +68 -56
  115. package/src/build/node/cache.ts +17 -8
  116. package/src/build/node/index.ts +4 -2
  117. package/src/build/node/meteor.ts +3 -9
  118. package/src/build/node/testJob.ts +21 -7
  119. package/src/build/node/yarn.ts +2 -2
  120. package/src/build/rails/build.ts +14 -4
  121. package/src/build/rails/test.ts +9 -1
  122. package/src/build/sbom.ts +7 -2
  123. package/src/build/types.ts +68 -4
  124. package/src/context/createAllComponentsContext.ts +31 -0
  125. package/src/context/createComponentContext.ts +59 -20
  126. package/src/context/createWorkspaceContext.ts +56 -0
  127. package/src/context/getBuildInfoVariables.ts +2 -1
  128. package/src/context/getEnvironmentContext.ts +2 -2
  129. package/src/context/getEnvironmentVariables.ts +12 -7
  130. package/src/context/getLabels.ts +3 -3
  131. package/src/deploy/base/deploy.ts +33 -7
  132. package/src/deploy/cloudRun/artifactsRegistry.ts +3 -4
  133. package/src/deploy/cloudRun/createJobs/common.ts +4 -4
  134. package/src/deploy/cloudRun/index.ts +68 -67
  135. package/src/deploy/custom/index.ts +2 -2
  136. package/src/deploy/dockerTag/index.ts +8 -7
  137. package/src/deploy/index.ts +11 -9
  138. package/src/deploy/kubernetes/additionalSecretKeys.ts +3 -1
  139. package/src/deploy/kubernetes/cloudSql/index.ts +1 -1
  140. package/src/deploy/kubernetes/deployJob.ts +2 -2
  141. package/src/deploy/kubernetes/index.ts +42 -41
  142. package/src/deploy/sbom.ts +9 -4
  143. package/src/pipeline/createAllJobs.ts +56 -55
  144. package/src/pipeline/createChildPipeline.ts +1 -0
  145. package/src/pipeline/createJobsForComponent.ts +5 -4
  146. package/src/pipeline/createJobsForWorkspace.ts +12 -0
  147. package/src/pipeline/createMainPipeline.ts +38 -23
  148. package/src/pipeline/gitlab/createGitlabJobs.ts +283 -119
  149. package/src/pipeline/packageManager.ts +25 -9
  150. package/src/types/config.ts +4 -1
  151. package/src/types/context.ts +108 -12
  152. package/src/types/environmentContext.ts +6 -7
  153. package/src/types/jobs.ts +3 -1
@@ -1,9 +1,13 @@
1
1
  import { merge } from "lodash";
2
- import { join } from "path";
3
- import type { ComponentContext } from "../..";
2
+ import type {
3
+ BuildContextStandalone,
4
+ ComponentContext,
5
+ WorkspaceContext,
6
+ } from "../..";
4
7
  import { getRunnerImage } from "../..";
5
8
  import type { CatladderJob } from "../../types/jobs";
6
9
  import { ensureArray } from "../../utils";
10
+ import { createBuildJobArtifacts } from "../artifacts/createBuildJobArtifact";
7
11
  import { ensureNodeVersion } from "../node/yarn";
8
12
  import {
9
13
  APP_BUILD_JOB_NAME,
@@ -15,9 +19,9 @@ import {
15
19
  writeDotEnv,
16
20
  } from "./writeDotEnv";
17
21
 
18
- export type AppBuildJobDefinition = Partial<CatladderJob>;
22
+ export type AppBuildJobDefinition = Partial<Omit<CatladderJob, "artifacts">>;
19
23
  export const createAppBuildJob = (
20
- context: ComponentContext,
24
+ context: ComponentContext<BuildContextStandalone> | WorkspaceContext,
21
25
  { script, variables, runnerVariables, ...def }: AppBuildJobDefinition,
22
26
  ): CatladderJob => {
23
27
  return merge(
@@ -30,9 +34,13 @@ export const createAppBuildJob = (
30
34
  cache: [],
31
35
  variables: {
32
36
  ...(variables ?? {}),
33
- ...context.environment.envVars,
34
- ...context.environment.jobOnlyVars.build.envVars,
35
- ...(context.build.config.extraVars ?? {}),
37
+ ...(context.type === "component"
38
+ ? {
39
+ ...context.environment.envVars,
40
+ ...context.environment.jobOnlyVars.build.envVars,
41
+ ...(context.build.config.extraVars ?? {}),
42
+ }
43
+ : {}),
36
44
  },
37
45
  runnerVariables: {
38
46
  ...RUNNER_BUILD_RESOURCE_VARIABLES,
@@ -41,25 +49,21 @@ export const createAppBuildJob = (
41
49
  },
42
50
 
43
51
  script: [
44
- ...(componentContextNeedsBuildTimeDotEnv(context)
45
- ? writeDotEnv(context)
46
- : []),
47
- ...writeBuildInfo(context),
52
+ ...(context.type === "component"
53
+ ? componentContextNeedsBuildTimeDotEnv(context)
54
+ ? writeDotEnv(context)
55
+ : []
56
+ : context.type === "workspace"
57
+ ? context.components
58
+ .filter((c) => componentContextNeedsBuildTimeDotEnv(c))
59
+ .flatMap((c) => writeDotEnv(c))
60
+ : []),
61
+ ...(context.type === "component" ? writeBuildInfo(context) : []),
48
62
  ...ensureNodeVersion(context), // in pure node repos, we might want to have the nvmrc file in top-level
49
63
  `cd ${context.build.dir}`,
50
64
  ...(ensureArray(script) ?? []),
51
65
  ],
52
- artifacts: {
53
- paths: [join(context.build.dir, "__build_info.json")],
54
- ...(componentContextNeedsBuildTimeDotEnv(context)
55
- ? { exclude: [join(context.build.dir, ".env")] }
56
- : {}),
57
- reports: {
58
- junit: context.build.config.artifactsReports?.junit?.map((p) =>
59
- join(context.build.dir, p),
60
- ),
61
- },
62
- },
66
+ artifacts: createBuildJobArtifacts(context),
63
67
  },
64
68
  def,
65
69
  );
@@ -1,5 +1,10 @@
1
1
  import { sbomDeactivated } from "../../deploy/sbom";
2
- import type { ComponentContext } from "../../types/context";
2
+ import type { WorkspaceContext } from "../../types/context";
3
+ import {
4
+ componentContextHasWorkspaceBuild,
5
+ componentContextIsStandaloneBuild,
6
+ type ComponentContext,
7
+ } from "../../types/context";
3
8
  import type { CatladderJob } from "../../types/jobs";
4
9
  import type { DockerBuildJobDefinition } from "../docker";
5
10
  import { createDockerBuildJobBase, requiresDockerBuild } from "../docker";
@@ -8,7 +13,7 @@ import { APP_BUILD_JOB_NAME } from "./constants";
8
13
  import type { AppBuildJobDefinition } from "./createAppBuildJob";
9
14
  import { createAppBuildJob } from "./createAppBuildJob";
10
15
 
11
- export const createBuildJobs = (
16
+ export const createComponentBuildJobs = (
12
17
  context: ComponentContext,
13
18
  definitions: {
14
19
  appBuild?: AppBuildJobDefinition;
@@ -16,7 +21,7 @@ export const createBuildJobs = (
16
21
  },
17
22
  ): CatladderJob[] => {
18
23
  return [
19
- ...(definitions.appBuild
24
+ ...(definitions.appBuild && componentContextIsStandaloneBuild(context)
20
25
  ? [createAppBuildJob(context, definitions.appBuild)]
21
26
  : []),
22
27
  ...(requiresDockerBuild(context)
@@ -25,7 +30,18 @@ export const createBuildJobs = (
25
30
  ...definitions.dockerBuild,
26
31
  needs: [
27
32
  ...(definitions.dockerBuild.needs ?? []),
28
- ...(definitions.appBuild ? [APP_BUILD_JOB_NAME] : []),
33
+ ...(definitions.appBuild &&
34
+ componentContextIsStandaloneBuild(context)
35
+ ? [APP_BUILD_JOB_NAME]
36
+ : componentContextHasWorkspaceBuild(context)
37
+ ? [
38
+ {
39
+ job: APP_BUILD_JOB_NAME,
40
+ artifacts: true,
41
+ workspaceName: context.build.workspaceName,
42
+ },
43
+ ]
44
+ : []),
29
45
  ],
30
46
  }),
31
47
  ]
@@ -33,3 +49,14 @@ export const createBuildJobs = (
33
49
  ...(sbomDeactivated(context) ? [] : [createSbomBuildJob(context)]),
34
50
  ];
35
51
  };
52
+
53
+ export const createWorkspaceBuildJobs = (
54
+ context: WorkspaceContext,
55
+ definitions: {
56
+ appBuild?: AppBuildJobDefinition;
57
+ },
58
+ ): CatladderJob[] => {
59
+ return definitions.appBuild
60
+ ? [createAppBuildJob(context, definitions.appBuild)]
61
+ : [];
62
+ };
@@ -1,5 +1,6 @@
1
1
  import { isNil } from "lodash";
2
2
  import type { ComponentContext } from "../../types";
3
+ import { collapseableSection } from "../../utils/gitlab";
3
4
 
4
5
  /**
5
6
  * writes a .env file in the components folder
@@ -18,11 +19,14 @@ export const writeDotEnv = (context: ComponentContext) => {
18
19
  )
19
20
  .join("\n");
20
21
 
21
- return [
22
+ return collapseableSection(
23
+ "write-dotenv-" + context.name,
24
+ "write dot env",
25
+ )([
22
26
  `cat <<EOF > ${context.build.dir}/.env
23
27
  ${keyValueString}
24
28
  EOF`,
25
- ];
29
+ ]);
26
30
  };
27
31
 
28
32
  export const componentContextNeedsBuildTimeDotEnv = (
@@ -1,9 +1,9 @@
1
- import type { ComponentContext } from "../../..";
1
+ import type { BuildContextStandalone, ComponentContext } from "../../..";
2
2
  import { createCustomTestJobs } from "../testJob";
3
3
 
4
4
  describe("createCustomTestJobs", () => {
5
- const baseContext: ComponentContext = {
6
- componentName: "testComponent",
5
+ const baseContext: ComponentContext<BuildContextStandalone> = {
6
+ name: "testComponent",
7
7
  environment: {
8
8
  jobOnlyVars: {
9
9
  build: {},
@@ -12,7 +12,7 @@ describe("createCustomTestJobs", () => {
12
12
  build: {
13
13
  config: { type: "custom", docker: { type: "custom" }, jobImage: "" },
14
14
  },
15
- } as ComponentContext;
15
+ } as ComponentContext<BuildContextStandalone>;
16
16
 
17
17
  it("throws error when not build type custom", () => {
18
18
  baseContext.build.config.type = "node";
@@ -1,11 +1,10 @@
1
- import { join } from "path";
2
1
  import type { ComponentContext } from "../../types/context";
3
2
  import { ensureArray } from "../../utils";
4
3
  import { getDockerBuildScriptWithBuiltInDockerFile } from "../docker";
5
4
  import { isOfBuildType } from "../types";
6
5
 
7
6
  import type { CatladderJob } from "../../types/jobs";
8
- import { createBuildJobs } from "../base";
7
+ import { createComponentBuildJobs } from "../base";
9
8
 
10
9
  const RUNNER_BUILD_VARIABLES = {
11
10
  KUBERNETES_CPU_REQUEST: "0.5",
@@ -22,7 +21,7 @@ export const createCustomBuildJobs = (
22
21
  throw new Error("deploy config is not custom");
23
22
  }
24
23
 
25
- return createBuildJobs(context, {
24
+ return createComponentBuildJobs(context, {
26
25
  appBuild:
27
26
  buildConfig.buildCommand !== null
28
27
  ? {
@@ -31,16 +30,6 @@ export const createCustomBuildJobs = (
31
30
  cache: buildConfig.jobCache,
32
31
  services: buildConfig.jobServices,
33
32
  script: [...(ensureArray(buildConfig.buildCommand) ?? [])],
34
- artifacts: {
35
- paths: [
36
- join(context.build.dir, "__build_info.json"),
37
- join(context.build.dir, "dist"),
38
- ...(buildConfig.artifactsPaths?.map((path) =>
39
- join(context.build.dir, path),
40
- ) ?? []),
41
- ],
42
- expire_in: "1 day",
43
- },
44
33
  }
45
34
  : undefined,
46
35
  dockerBuild: {
@@ -33,11 +33,9 @@ export const getDockerImageVariables = (context: ComponentContext) => {
33
33
  {
34
34
  DOCKER_REGISTRY: "$CI_REGISTRY",
35
35
 
36
- DOCKER_CACHE_IMAGE:
37
- "$CI_REGISTRY_IMAGE/caches/" + context.componentName,
36
+ DOCKER_CACHE_IMAGE: "$CI_REGISTRY_IMAGE/caches/" + context.name,
38
37
  // ONLY USED IN KUBERNETES
39
- DOCKER_IMAGE_NAME:
40
- context.environment.shortName + "/" + context.componentName,
38
+ DOCKER_IMAGE_NAME: context.env + "/" + context.name,
41
39
  DOCKER_IMAGE: "$CI_REGISTRY_IMAGE/$DOCKER_IMAGE_NAME",
42
40
  }),
43
41
 
@@ -162,10 +160,10 @@ export const getDockerBuildScriptWithBuiltInDockerFile = (
162
160
  defaultType?: BuildConfigDocker["type"],
163
161
  ) => {
164
162
  const type =
165
- "docker" in context.componentConfig.build &&
166
- context.componentConfig.build.docker &&
167
- "type" in context.componentConfig.build.docker
168
- ? context.componentConfig.build.docker?.type
163
+ "docker" in context.build.config &&
164
+ context.build.config.docker &&
165
+ "type" in context.build.config.docker
166
+ ? context.build.config.docker?.type
169
167
  : defaultType;
170
168
  return getDockerBuildDefaultScript(
171
169
  context,
@@ -1,20 +1,24 @@
1
- import type { ComponentContext } from "../types/context";
1
+ import type { ComponentContext, WorkspaceContext } from "../types/context";
2
2
  import type { EnvironmentContext } from "../types/environmentContext";
3
3
 
4
4
  import type { CatladderJob } from "../types/jobs";
5
5
  import { createCustomJobs } from "./custom";
6
- import { createNodeJobs, createStorybookJobs, createMeteorJobs } from "./node";
6
+ import { createMeteorJobs, createNodeJobs, createStorybookJobs } from "./node";
7
7
  import { createRailsJobs } from "./rails";
8
8
 
9
- import type { BuildConfig, BuildConfigType } from "./types";
10
- export * from "./types";
9
+ import type {
10
+ BuildConfig,
11
+ BuildConfigStandaloneType,
12
+ WorkspaceBuildConfig,
13
+ } from "./types";
11
14
  export * from "./node";
15
+ export * from "./types";
12
16
 
13
17
  export type BuildTypes = {
14
- [type in BuildConfigType]: {
18
+ [type in BuildConfigStandaloneType]: {
15
19
  jobs: (context: ComponentContext) => CatladderJob[];
16
20
  defaults: (
17
- envContext: EnvironmentContext<BuildConfigType, any>,
21
+ envContext: EnvironmentContext,
18
22
  ) => Partial<Extract<BuildConfig, { type: type }>>;
19
23
  };
20
24
  };
@@ -25,29 +29,35 @@ export const BUILD_TYPES: BuildTypes = {
25
29
  defaults: () => ({
26
30
  buildCommand: "yarn build",
27
31
  startCommand: "yarn start",
32
+ artifactsPaths: ["dist", ".next"],
28
33
  }),
29
34
  },
30
35
  "node-static": {
31
36
  jobs: createNodeJobs,
32
37
  defaults: () => ({
33
38
  buildCommand: "yarn build",
39
+ artifactsPaths: ["dist"],
34
40
  }),
35
41
  },
36
42
  storybook: {
37
43
  jobs: createStorybookJobs,
38
44
  defaults: () => ({
39
45
  buildCommand: ["yarn build-storybook --quiet -o ./dist"],
46
+ artifactsPaths: ["dist"],
40
47
  }),
41
48
  },
42
49
  meteor: {
43
50
  jobs: createMeteorJobs,
44
51
  defaults: () => ({
45
52
  startCommand: "node main.js",
53
+ artifactsPaths: ["dist"],
46
54
  }),
47
55
  },
48
56
  custom: {
49
57
  jobs: createCustomJobs,
50
- defaults: () => ({}),
58
+ defaults: () => ({
59
+ artifactsPaths: ["dist"],
60
+ }),
51
61
  },
52
62
  rails: {
53
63
  jobs: createRailsJobs,
@@ -60,3 +70,25 @@ export const BUILD_TYPES: BuildTypes = {
60
70
  }),
61
71
  },
62
72
  };
73
+
74
+ export type WorkspaceBuildTypes = {
75
+ [type in WorkspaceBuildConfig["type"]]: {
76
+ jobs: (context: WorkspaceContext) => CatladderJob[];
77
+ defaults: () => Partial<Extract<WorkspaceBuildConfig, { type: type }>>;
78
+ };
79
+ };
80
+
81
+ export const WORKSPACE_BUILD_TYPES: WorkspaceBuildTypes = {
82
+ node: {
83
+ jobs: createNodeJobs,
84
+ defaults: () => ({
85
+ buildCommand: "yarn build",
86
+ lint: {
87
+ command: "yarn lint",
88
+ },
89
+ test: {
90
+ command: "yarn test",
91
+ },
92
+ }),
93
+ },
94
+ };
@@ -1,79 +1,91 @@
1
- import { join } from "path";
2
1
  import { getRunnerImage } from "../../runner";
3
- import type { ComponentContext } from "../../types/context";
2
+ import type {
3
+ BuildContextStandalone,
4
+ WorkspaceContext,
5
+ } from "../../types/context";
6
+ import {
7
+ componentContextIsStandaloneBuild,
8
+ type ComponentContext,
9
+ } from "../../types/context";
4
10
  import type { CatladderJob } from "../../types/jobs";
5
11
  import { ensureArray } from "../../utils";
6
- import { createBuildJobs } from "../base";
12
+ import { createComponentBuildJobs, createWorkspaceBuildJobs } from "../base";
13
+ import type { AppBuildJobDefinition } from "../base/createAppBuildJob";
14
+ import type { DockerBuildJobDefinition } from "../docker";
7
15
  import { getDockerBuildScriptWithBuiltInDockerFile } from "../docker";
16
+ import type { BuildConfigDocker } from "../types";
8
17
  import { isOfBuildType } from "../types";
9
18
  import { getNextCache, getNodeCache, getYarnCache } from "./cache";
10
19
  import { NODE_RUNNER_BUILD_VARIABLES } from "./constants";
11
20
  import { getDockerAppCopyAndBuildScript, getYarnInstall } from "./yarn";
12
21
 
13
22
  export const createNodeBuildJobs = (
14
- context: ComponentContext,
23
+ context: ComponentContext | WorkspaceContext,
15
24
  ): CatladderJob[] => {
25
+ if (context.type === "workspace") {
26
+ return createWorkspaceBuildJobs(context, {
27
+ appBuild: createNodeBuildJobDefinition(context),
28
+ });
29
+ }
30
+ return createComponentBuildJobs(context, {
31
+ appBuild: componentContextIsStandaloneBuild(context)
32
+ ? createNodeBuildJobDefinition(context)
33
+ : undefined,
34
+
35
+ dockerBuild: createNodeDockerJobDefinition(context),
36
+ });
37
+ };
38
+
39
+ export const createNodeBuildJobDefinition = (
40
+ context: ComponentContext<BuildContextStandalone> | WorkspaceContext,
41
+ ): AppBuildJobDefinition | undefined => {
16
42
  const buildConfig = context.build.config;
17
43
 
18
44
  if (!isOfBuildType(buildConfig, "node", "node-static", "storybook")) {
19
45
  throw new Error("deploy config is not node, node-static or storybook");
20
46
  }
21
47
 
48
+ if (buildConfig.buildCommand === null) return undefined;
49
+
22
50
  const defaultImage = getRunnerImage("jobs-default");
23
51
  const yarnInstall = getYarnInstall(context);
24
52
 
25
- return createBuildJobs(context, {
26
- appBuild:
27
- buildConfig.buildCommand !== null
28
- ? {
29
- image: buildConfig.jobImage ?? defaultImage,
30
- runnerVariables: NODE_RUNNER_BUILD_VARIABLES,
31
- cache: [
32
- ...(ensureArray(buildConfig.jobCache) ?? []),
33
- ...getNodeCache(context),
34
- ...getNextCache(context),
35
- ],
36
- script: [
37
- ...yarnInstall,
38
- ...(ensureArray(buildConfig.buildCommand) ?? []),
39
- ],
40
- artifacts: {
41
- paths: [
42
- context.build.dir,
43
- // also copy workspace dependencies in monorepo if packages are shared and they create build artifacts
44
- ...(context.packageManagerInfo.currentWorkspaceDependencies ??
45
- []),
46
- ].flatMap((dir) => [
47
- join(dir, "__build_info.json"),
48
- join(dir, "dist"),
49
- join(dir, ".next"),
50
- ...(buildConfig.artifactsPaths?.map((path) =>
51
- join(dir, path),
52
- ) ?? []),
53
- ]),
54
- expire_in: "1 day",
55
- when: "always",
56
- },
57
- jobTags: buildConfig.jobTags,
58
- }
59
- : undefined,
53
+ return {
54
+ image: buildConfig.jobImage ?? defaultImage,
55
+ runnerVariables: NODE_RUNNER_BUILD_VARIABLES,
56
+ cache: [
57
+ ...(ensureArray(buildConfig.jobCache) ?? []),
58
+ ...getNodeCache(context),
59
+ ...getNextCache(context),
60
+ ],
61
+ script: [...yarnInstall, ...(ensureArray(buildConfig.buildCommand) ?? [])],
62
+ jobTags: buildConfig.jobTags,
63
+ };
64
+ };
60
65
 
61
- dockerBuild: {
62
- script: getDockerBuildScriptWithBuiltInDockerFile(
63
- context,
64
- buildConfig.type === "node-static" || buildConfig.type === "storybook"
65
- ? "nginx"
66
- : "node",
67
- ),
68
- cache: [...getYarnCache(context, "pull")],
69
- variables: {
70
- // only required for non static
71
- DOCKER_COPY_AND_INSTALL_APP: getDockerAppCopyAndBuildScript(context),
72
- DOCKER_COPY_WORKSPACE_FILES:
73
- context.packageManagerInfo.pathsToCopyInDocker
74
- .map((dir) => `COPY --chown=node:node ${dir} /app/${dir}`)
75
- ?.join("\n"),
76
- },
66
+ export const createNodeDockerJobDefinition = (
67
+ context: ComponentContext,
68
+ ): DockerBuildJobDefinition => {
69
+ // get the default docker built-in type based on the build type
70
+ const dockerDefaultBuiltIn: BuildConfigDocker["type"] =
71
+ context.build.buildType === "node-static" ||
72
+ context.build.buildType === "storybook"
73
+ ? "nginx"
74
+ : "node";
75
+
76
+ return {
77
+ script: getDockerBuildScriptWithBuiltInDockerFile(
78
+ context,
79
+ dockerDefaultBuiltIn,
80
+ ),
81
+ cache: [...getYarnCache(context, "pull")],
82
+ variables: {
83
+ // only required for non static
84
+ DOCKER_COPY_AND_INSTALL_APP: getDockerAppCopyAndBuildScript(context),
85
+ DOCKER_COPY_WORKSPACE_FILES:
86
+ context.packageManagerInfo?.pathsToCopyInDocker
87
+ .map((dir) => `COPY --chown=node:node ${dir} /app/${dir}`)
88
+ ?.join("\n"),
77
89
  },
78
- });
90
+ };
79
91
  };
@@ -1,7 +1,7 @@
1
1
  import { uniq } from "lodash";
2
2
  import { join } from "path";
3
3
  import slugify from "slugify";
4
- import type { ComponentContext, Context } from "../../types/context";
4
+ import type { Context } from "../../types/context";
5
5
  import type { GitlabJobCache } from "../../types/gitlab-types";
6
6
 
7
7
  export const getYarnCache = (
@@ -9,6 +9,7 @@ export const getYarnCache = (
9
9
  policy = "pull-push",
10
10
  ): GitlabJobCache[] => {
11
11
  const componentIsInWorkspace =
12
+ context.type === "component" &&
12
13
  context.packageManagerInfo.componentIsInWorkspace;
13
14
  return [
14
15
  componentIsInWorkspace
@@ -30,6 +31,7 @@ export const getNodeModulesCache = (
30
31
  policy = "pull-push",
31
32
  ): GitlabJobCache[] => {
32
33
  const componentIsInWorkspace =
34
+ context.type === "component" &&
33
35
  context.packageManagerInfo.componentIsInWorkspace;
34
36
 
35
37
  // We intentionally do not use the contents of yarn.lock as a cache key, as yarn install should always guarantee that the files are updated, but it can still use part of the cache if not all packages are up-to-date.
@@ -64,10 +66,17 @@ export const getNodeCache = (
64
66
  ];
65
67
  };
66
68
 
67
- export const getNextCache = (context: ComponentContext): GitlabJobCache[] => [
68
- {
69
- key: context.componentName + "-next-cache",
70
- policy: "pull-push",
71
- paths: [context.build.dir + "/.next/cache/"],
72
- },
73
- ];
69
+ export const getNextCache = (context: Context): GitlabJobCache[] => {
70
+ const key = context.name + "-next-cache";
71
+ const paths = context.build
72
+ .getComponentDirs("direct")
73
+ .map((c) => join(c, ".next/cache"));
74
+
75
+ return [
76
+ {
77
+ key,
78
+ policy: "pull-push",
79
+ paths,
80
+ },
81
+ ];
82
+ };
@@ -1,10 +1,12 @@
1
- import type { ComponentContext } from "../../types/context";
1
+ import type { ComponentContext, WorkspaceContext } from "../../types/context";
2
2
  import type { CatladderJob } from "../../types/jobs";
3
3
  import { createNodeBuildJobs } from "./buildJob";
4
4
  import { createMeteorBuildJobs } from "./meteor";
5
5
  import { createNodeTestJobs } from "./testJob";
6
6
 
7
- export const createNodeJobs = (context: ComponentContext): CatladderJob[] => {
7
+ export const createNodeJobs = (
8
+ context: ComponentContext | WorkspaceContext,
9
+ ): CatladderJob[] => {
8
10
  return [...createNodeTestJobs(context), ...createNodeBuildJobs(context)];
9
11
  };
10
12
 
@@ -5,7 +5,7 @@ import type { ComponentContext } from "../../types/context";
5
5
 
6
6
  import type { CatladderJob } from "../../types/jobs";
7
7
 
8
- import { createBuildJobs } from "../base";
8
+ import { createComponentBuildJobs } from "../base";
9
9
  import { getDockerBuildScriptWithBuiltInDockerFile } from "../docker";
10
10
  import { isOfBuildType } from "../types";
11
11
  import { getNodeCache } from "./cache";
@@ -13,7 +13,7 @@ import { getYarnInstall } from "./yarn";
13
13
 
14
14
  const getMeteorCache = (context: ComponentContext): GitlabJobCache[] => [
15
15
  {
16
- key: context.componentName + "meteor-build-cache",
16
+ key: context.name + "meteor-build-cache",
17
17
  policy: "pull-push",
18
18
  paths: [
19
19
  join(context.build.dir, ".meteor/local/resolver-result-cache.json"),
@@ -34,7 +34,7 @@ export const createMeteorBuildJobs = (
34
34
 
35
35
  const yarnInstall = getYarnInstall(context);
36
36
 
37
- return createBuildJobs(context, {
37
+ return createComponentBuildJobs(context, {
38
38
  appBuild:
39
39
  buildConfig.buildCommand !== null
40
40
  ? {
@@ -54,12 +54,6 @@ export const createMeteorBuildJobs = (
54
54
 
55
55
  "cp ./__build_info.json ./dist/bundle/programs/server",
56
56
  ],
57
- artifacts: {
58
- paths: [
59
- context.build.dir + "/__build_info.json",
60
- context.build.dir + "/dist",
61
- ],
62
- },
63
57
  }
64
58
  : undefined,
65
59
  dockerBuild: {
@@ -1,35 +1,49 @@
1
1
  import { getRunnerImage } from "../../runner";
2
- import type { ComponentContext } from "../../types/context";
2
+ import type { WorkspaceContext } from "../../types/context";
3
+ import {
4
+ componentContextIsStandaloneBuild,
5
+ type ComponentContext,
6
+ } from "../../types/context";
3
7
  import type { CatladderJob } from "../../types/jobs";
4
8
  import { ensureArray, notNil } from "../../utils";
9
+ import { createArtifactsConfig } from "../base/createArtifactsConfig";
5
10
  import { getNodeCache } from "./cache";
6
11
  import { NODE_RUNNER_BUILD_VARIABLES } from "./constants";
7
12
  import { ensureNodeVersion, getYarnInstall } from "./yarn";
8
- import { createArtifactsConfig } from "../base/createArtifactsConfig";
9
13
 
10
14
  export const createNodeTestJobs = (
11
- context: ComponentContext,
15
+ context: ComponentContext | WorkspaceContext,
12
16
  ): CatladderJob[] => {
13
17
  // don't run tests after release
14
18
  // TODO: this will be replaced by using rules
15
19
  if (context.trigger === "taggedRelease") {
16
20
  return [];
17
21
  }
18
-
19
- const buildConfig = context.build.config;
22
+ // if its not a standalone build, we don't need to run tests
23
+ if (
24
+ context.type === "component" &&
25
+ !componentContextIsStandaloneBuild(context)
26
+ ) {
27
+ return [];
28
+ }
20
29
 
21
30
  const defaultImage = getRunnerImage("jobs-default");
22
31
  const base: Omit<CatladderJob, "script" | "name"> = {
23
32
  variables: {
24
33
  APP_PATH: context.build.dir,
25
- ...context.environment.jobOnlyVars.build.envVars,
26
- ...(buildConfig.extraVars ?? {}),
34
+ ...(context.type === "component"
35
+ ? {
36
+ ...context.environment.jobOnlyVars.build.envVars,
37
+ ...(context.build.config.extraVars ?? {}),
38
+ }
39
+ : {}),
27
40
  },
28
41
  runnerVariables: NODE_RUNNER_BUILD_VARIABLES,
29
42
  stage: "test",
30
43
  needs: [],
31
44
  envMode: "none",
32
45
  };
46
+ const buildConfig = context.build.config;
33
47
  const yarnInstall = getYarnInstall(context);
34
48
  const auditJob: CatladderJob | null =
35
49
  buildConfig.audit !== false