@catladder/pipeline 1.165.0 → 1.166.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 (71) hide show
  1. package/dist/build/base/createAppBuildJob.d.ts +3 -1
  2. package/dist/build/base/createAppBuildJob.js +6 -4
  3. package/dist/build/base/createBuildJobDefinition.d.ts +7 -0
  4. package/dist/build/base/createBuildJobDefinition.js +58 -0
  5. package/dist/build/cache/createJobCache.d.ts +6 -0
  6. package/dist/build/cache/createJobCache.js +109 -0
  7. package/dist/build/cache/getAllCacheConfigsFromConfig.d.ts +3 -0
  8. package/dist/build/cache/getAllCacheConfigsFromConfig.js +66 -0
  9. package/dist/build/cache/transformLegacyJobCache.d.ts +3 -0
  10. package/dist/build/cache/transformLegacyJobCache.js +29 -0
  11. package/dist/build/custom/buildJob.js +2 -45
  12. package/dist/build/custom/testJob.d.ts +1 -1
  13. package/dist/build/custom/testJob.js +12 -11
  14. package/dist/build/docker.d.ts +4 -3
  15. package/dist/build/docker.js +5 -2
  16. package/dist/build/node/buildJob.js +5 -17
  17. package/dist/build/node/cache.d.ts +6 -6
  18. package/dist/build/node/cache.js +8 -9
  19. package/dist/build/node/meteor.js +2 -3
  20. package/dist/build/node/testJob.js +6 -5
  21. package/dist/build/node/yarn.js +1 -2
  22. package/dist/build/rails/test.js +3 -3
  23. package/dist/build/sbom.js +1 -1
  24. package/dist/build/types.d.ts +43 -4
  25. package/dist/bundles/catladder-gitlab/index.js +2 -2
  26. package/dist/constants.js +1 -1
  27. package/dist/tsconfig.tsbuildinfo +1 -1
  28. package/dist/types/gitlab-types.d.ts +2 -2
  29. package/dist/types/index.d.ts +1 -0
  30. package/dist/types/index.js +1 -0
  31. package/dist/types/jobDefinition.d.ts +5 -0
  32. package/dist/types/jobDefinition.js +5 -0
  33. package/dist/types/jobs.d.ts +3 -2
  34. package/dist/utils/index.d.ts +2 -1
  35. package/dist/utils/index.js +7 -2
  36. package/examples/__snapshots__/cloud-run-meteor-with-worker.test.ts.snap +4 -4
  37. package/examples/__snapshots__/cloud-run-with-sql.test.ts.snap +817 -1717
  38. package/examples/__snapshots__/custom-build-job-with-tests.test.ts.snap +0 -4
  39. package/examples/__snapshots__/custom-build-job.test.ts.snap +0 -4
  40. package/examples/__snapshots__/custom-sbom-java.test.ts.snap +0 -4
  41. package/examples/__snapshots__/meteor-kubernetes.test.ts.snap +4 -4
  42. package/examples/__snapshots__/native-app.test.ts.snap +24 -20
  43. package/examples/__snapshots__/workspace-api-www-custom-cache.test.ts.snap +2374 -0
  44. package/examples/__snapshots__/workspace-api-www.test.ts.snap +2354 -0
  45. package/examples/cloud-run-with-sql.ts +1 -23
  46. package/examples/workspace-api-www-custom-cache.test.ts +11 -0
  47. package/examples/workspace-api-www-custom-cache.ts +51 -0
  48. package/examples/workspace-api-www.test.ts +11 -0
  49. package/examples/workspace-api-www.ts +45 -0
  50. package/package.json +1 -1
  51. package/src/build/base/createAppBuildJob.ts +6 -4
  52. package/src/build/base/createBuildJobDefinition.ts +38 -0
  53. package/src/build/cache/createJobCache.ts +85 -0
  54. package/src/build/cache/getAllCacheConfigsFromConfig.ts +33 -0
  55. package/src/build/cache/transformLegacyJobCache.ts +14 -0
  56. package/src/build/custom/buildJob.ts +2 -14
  57. package/src/build/custom/testJob.ts +7 -6
  58. package/src/build/docker.ts +5 -3
  59. package/src/build/node/buildJob.ts +6 -29
  60. package/src/build/node/cache.ts +20 -21
  61. package/src/build/node/meteor.ts +7 -8
  62. package/src/build/node/testJob.ts +7 -6
  63. package/src/build/node/yarn.ts +1 -1
  64. package/src/build/rails/test.ts +4 -4
  65. package/src/build/sbom.ts +2 -2
  66. package/src/build/types.ts +54 -4
  67. package/src/types/gitlab-types.ts +2 -2
  68. package/src/types/index.ts +1 -0
  69. package/src/types/jobDefinition.ts +9 -0
  70. package/src/types/jobs.ts +5 -8
  71. package/src/utils/index.ts +4 -1
@@ -3,17 +3,12 @@ import type { Config } from "../src";
3
3
  const config: Config = {
4
4
  appName: "test-app",
5
5
  customerName: "pan",
6
- builds: {
7
- myWorkspace: {
8
- type: "node",
9
- },
10
- },
11
6
  components: {
12
7
  api: {
13
8
  dotEnv: true,
14
9
  dir: "api",
15
10
  build: {
16
- from: "myWorkspace",
11
+ type: "node",
17
12
  },
18
13
  deploy: {
19
14
  type: "google-cloudrun",
@@ -44,23 +39,6 @@ const config: Config = {
44
39
  },
45
40
  },
46
41
  },
47
- www: {
48
- dotEnv: true,
49
- dir: "www",
50
- build: {
51
- from: "myWorkspace",
52
- },
53
- deploy: {
54
- type: "google-cloudrun",
55
- projectId: "google-project-id",
56
- region: "europe-west6",
57
- },
58
- vars: {
59
- public: {
60
- API_URL: "${api:ROOT_URL}/graphql",
61
- },
62
- },
63
- },
64
42
  },
65
43
  };
66
44
 
@@ -0,0 +1,11 @@
1
+ import { createYamlLocalPipeline } from "./__utils__/helpers";
2
+ import config from "./workspace-api-www-custom-cache";
3
+
4
+ /**
5
+ * This test is auto-generated.
6
+ * Modifications will be overwritten on every `yarn test` run!
7
+ */
8
+
9
+ it("matches snapshot for workspace-api-www-custom-cache local pipeline YAML", async () => {
10
+ expect(await createYamlLocalPipeline(config)).toMatchSnapshot();
11
+ });
@@ -0,0 +1,51 @@
1
+ import type { Config, DeployConfig } from "../src";
2
+
3
+ const DEPLOY_CONFIG: DeployConfig = {
4
+ type: "google-cloudrun",
5
+ projectId: "google-project-id",
6
+ region: "europe-west6",
7
+ };
8
+ const config: Config = {
9
+ appName: "test-app",
10
+ customerName: "pan",
11
+ builds: {
12
+ myWorkspace: {
13
+ type: "node",
14
+ cache: {
15
+ paths: [".my-cache"],
16
+ },
17
+ },
18
+ },
19
+ components: {
20
+ api: {
21
+ dotEnv: true,
22
+ dir: "api",
23
+ build: {
24
+ from: "myWorkspace",
25
+ cache: {
26
+ paths: [".component-custom-cache"],
27
+ },
28
+ },
29
+ deploy: DEPLOY_CONFIG,
30
+ },
31
+ www: {
32
+ dotEnv: true,
33
+ dir: "www",
34
+ build: {
35
+ from: "myWorkspace",
36
+ },
37
+ deploy: DEPLOY_CONFIG,
38
+ vars: {
39
+ public: {
40
+ API_URL: "${api:ROOT_URL}/graphql",
41
+ },
42
+ },
43
+ },
44
+ },
45
+ };
46
+
47
+ export default config;
48
+
49
+ export const information = {
50
+ title: "Workspace API and WWW",
51
+ };
@@ -0,0 +1,11 @@
1
+ import { createYamlLocalPipeline } from "./__utils__/helpers";
2
+ import config from "./workspace-api-www";
3
+
4
+ /**
5
+ * This test is auto-generated.
6
+ * Modifications will be overwritten on every `yarn test` run!
7
+ */
8
+
9
+ it("matches snapshot for workspace-api-www local pipeline YAML", async () => {
10
+ expect(await createYamlLocalPipeline(config)).toMatchSnapshot();
11
+ });
@@ -0,0 +1,45 @@
1
+ import type { Config, DeployConfig } from "../src";
2
+
3
+ const DEPLOY_CONFIG: DeployConfig = {
4
+ type: "google-cloudrun",
5
+ projectId: "google-project-id",
6
+ region: "europe-west6",
7
+ };
8
+ const config: Config = {
9
+ appName: "test-app",
10
+ customerName: "pan",
11
+ builds: {
12
+ myWorkspace: {
13
+ type: "node",
14
+ },
15
+ },
16
+ components: {
17
+ api: {
18
+ dotEnv: true,
19
+ dir: "api",
20
+ build: {
21
+ from: "myWorkspace",
22
+ },
23
+ deploy: DEPLOY_CONFIG,
24
+ },
25
+ www: {
26
+ dotEnv: true,
27
+ dir: "www",
28
+ build: {
29
+ from: "myWorkspace",
30
+ },
31
+ deploy: DEPLOY_CONFIG,
32
+ vars: {
33
+ public: {
34
+ API_URL: "${api:ROOT_URL}/graphql",
35
+ },
36
+ },
37
+ },
38
+ },
39
+ };
40
+
41
+ export default config;
42
+
43
+ export const information = {
44
+ title: "Workspace API and WWW",
45
+ };
package/package.json CHANGED
@@ -53,7 +53,7 @@
53
53
  }
54
54
  ],
55
55
  "license": "MIT",
56
- "version": "1.165.0",
56
+ "version": "1.166.0",
57
57
  "scripts": {
58
58
  "build:tsc": "yarn tsc",
59
59
  "build": "yarn build:compile && yarn build:inline-variables && yarn build:bundle",
@@ -5,9 +5,11 @@ import type {
5
5
  WorkspaceContext,
6
6
  } from "../..";
7
7
  import { getRunnerImage } from "../..";
8
+ import type { JobDefintion } from "../../types/jobDefinition";
8
9
  import type { CatladderJob } from "../../types/jobs";
9
10
  import { ensureArray } from "../../utils";
10
11
  import { createBuildJobArtifacts } from "../artifacts/createBuildJobArtifact";
12
+ import { createJobCacheFromCacheConfigs } from "../cache/createJobCache";
11
13
  import { ensureNodeVersion } from "../node/yarn";
12
14
  import {
13
15
  APP_BUILD_JOB_NAME,
@@ -19,10 +21,10 @@ import {
19
21
  writeDotEnv,
20
22
  } from "./writeDotEnv";
21
23
 
22
- export type AppBuildJobDefinition = Partial<Omit<CatladderJob, "artifacts">>;
24
+ export type AppBuildJobDefinition = JobDefintion;
23
25
  export const createAppBuildJob = (
24
26
  context: ComponentContext<BuildContextStandalone> | WorkspaceContext,
25
- { script, variables, runnerVariables, ...def }: AppBuildJobDefinition,
27
+ { script, variables, runnerVariables, cache, ...def }: AppBuildJobDefinition,
26
28
  ): CatladderJob => {
27
29
  return merge(
28
30
  {
@@ -31,7 +33,7 @@ export const createAppBuildJob = (
31
33
  stage: "build",
32
34
  image: getRunnerImage("jobs-default"),
33
35
  needs: [],
34
- cache: [],
36
+ cache: cache ? createJobCacheFromCacheConfigs(context, cache) : undefined,
35
37
  variables: {
36
38
  ...(variables ?? {}),
37
39
  ...(context.type === "component"
@@ -61,7 +63,7 @@ export const createAppBuildJob = (
61
63
  ...(context.type === "component" ? writeBuildInfo(context) : []),
62
64
  ...ensureNodeVersion(context), // in pure node repos, we might want to have the nvmrc file in top-level
63
65
  `cd ${context.build.dir}`,
64
- ...(ensureArray(script) ?? []),
66
+ ...ensureArray(script),
65
67
  ],
66
68
  artifacts: createBuildJobArtifacts(context),
67
69
  },
@@ -0,0 +1,38 @@
1
+ import type { BuildConfigStandalone, WorkspaceBuildConfig } from "..";
2
+ import { getRunnerImage } from "../../runner";
3
+ import type { Context } from "../../types";
4
+ import type { JobDefintion } from "../../types/jobDefinition";
5
+ import { ensureArray } from "../../utils";
6
+ import { getAllCacheConfigsFromConfig } from "../cache/getAllCacheConfigsFromConfig";
7
+ import { NODE_RUNNER_BUILD_VARIABLES } from "../node/constants";
8
+
9
+ export const createBuildJobDefinition = (
10
+ context: Context,
11
+ buildConfig: BuildConfigStandalone | WorkspaceBuildConfig,
12
+ customize: Pick<JobDefintion, "cache"> & {
13
+ prescript?: string[];
14
+ postscript?: string[];
15
+ } = {},
16
+ ): JobDefintion | undefined => {
17
+ if (buildConfig.buildCommand === null) return undefined;
18
+
19
+ const defaultImage = getRunnerImage("jobs-default");
20
+
21
+ return {
22
+ image: buildConfig.jobImage ?? defaultImage,
23
+ runnerVariables: NODE_RUNNER_BUILD_VARIABLES,
24
+ cache: [
25
+ ...(customize.cache ?? []),
26
+ ...getAllCacheConfigsFromConfig(context, buildConfig),
27
+ ],
28
+ services:
29
+ "jobServices" in buildConfig ? buildConfig.jobServices : undefined,
30
+ script: [
31
+ ...(customize.prescript ?? []),
32
+ ...ensureArray(buildConfig.buildCommand),
33
+ ...(customize.postscript ?? []),
34
+ ],
35
+
36
+ jobTags: buildConfig.jobTags,
37
+ };
38
+ };
@@ -0,0 +1,85 @@
1
+ import { join } from "path";
2
+ import type {
3
+ BuildConfigStandalone,
4
+ CacheConfig,
5
+ CacheConfigAdvanced,
6
+ CacheConfigSimple,
7
+ WorkspaceBuildConfig,
8
+ } from "..";
9
+ import type { Context } from "../../types";
10
+ import type { CatladderJobCache } from "../../types/jobs";
11
+ import { getAllCacheConfigsFromConfig } from "./getAllCacheConfigsFromConfig";
12
+
13
+ export const createJobCacheFromCacheConfigs = (
14
+ context: Context,
15
+ caches: CacheConfig[],
16
+ ): CatladderJobCache[] | undefined => {
17
+ if (caches.length === 0) return undefined;
18
+
19
+ const simpleCacheDefs = caches.filter(
20
+ (c): c is CacheConfigSimple => !("key" in c),
21
+ );
22
+ const advancedCacheDefs = caches.filter(
23
+ (c): c is CacheConfigAdvanced => "key" in c,
24
+ );
25
+ // simple caches are merged together into one. This is because e.g. gitlab has a limit of 4 caches, see https://gitlab.com/gitlab-org/gitlab/-/issues/421962
26
+ const simpleCaches =
27
+ simpleCacheDefs.length > 0
28
+ ? [
29
+ {
30
+ key: context.name + "-default",
31
+ policy: "pull-push",
32
+ paths: simpleCacheDefs.flatMap((c) =>
33
+ c.paths.map((p) => {
34
+ const baseDir =
35
+ c.pathMode === "absolute"
36
+ ? ""
37
+ : c.baseDir ?? context.build.dir;
38
+ return join(baseDir, p);
39
+ }),
40
+ ),
41
+ },
42
+ ]
43
+ : [];
44
+
45
+ const advancedCaches = advancedCacheDefs.map(
46
+ ({ key, paths, policy, scope, pathMode, buildDir, ...rest }) => {
47
+ const baseDir =
48
+ pathMode === "absolute" ? "" : buildDir ?? context.build.dir;
49
+ const transformedKey =
50
+ scope === "global"
51
+ ? key
52
+ : typeof key === "string"
53
+ ? (scope === "buildDir" // really edge case...
54
+ ? baseDir
55
+ : context.name) +
56
+ "-" +
57
+ key
58
+ : {
59
+ ...key,
60
+ files: key.files?.map((f) =>
61
+ pathMode === "absolute" ? f : join(baseDir, f),
62
+ ),
63
+ };
64
+ return {
65
+ key: transformedKey,
66
+ policy: policy ?? "pull-push",
67
+ paths:
68
+ pathMode === "absolute" ? paths : paths?.map((p) => join(baseDir, p)),
69
+ ...rest,
70
+ };
71
+ },
72
+ );
73
+ return [...advancedCaches, ...simpleCaches];
74
+ };
75
+
76
+ /** shortcut, used in some build types */
77
+ export const createJobCacheFromConfig = (
78
+ context: Context,
79
+ buildConfig: BuildConfigStandalone | WorkspaceBuildConfig,
80
+ ) => {
81
+ return createJobCacheFromCacheConfigs(
82
+ context,
83
+ getAllCacheConfigsFromConfig(context, buildConfig),
84
+ );
85
+ };
@@ -0,0 +1,33 @@
1
+ import type { Context } from "../../types";
2
+ import { ensureArray } from "../../utils/index";
3
+ import type {
4
+ BuildConfigStandalone,
5
+ CacheConfig,
6
+ WorkspaceBuildConfig,
7
+ } from "../types";
8
+ import { transformLegacyJobCache } from "./transformLegacyJobCache";
9
+
10
+ export const getAllCacheConfigsFromConfig = (
11
+ context: Context,
12
+ buildConfig: BuildConfigStandalone | WorkspaceBuildConfig,
13
+ ): CacheConfig[] => {
14
+ return [
15
+ ...("jobCache" in buildConfig
16
+ ? transformLegacyJobCache(buildConfig.jobCache)
17
+ : []),
18
+ ...ensureArray(buildConfig.cache).map((c) => ({
19
+ ...c,
20
+ context,
21
+ })),
22
+ ...(context.type === "workspace"
23
+ ? // also add cache configs of the components of that workspace
24
+ context.components.flatMap<CacheConfig>(
25
+ (componentContext) =>
26
+ ensureArray(componentContext.build.config.cache).map((c) => ({
27
+ ...c,
28
+ baseDir: componentContext.build.dir,
29
+ })) ?? [],
30
+ )
31
+ : []),
32
+ ];
33
+ };
@@ -0,0 +1,14 @@
1
+ import type { CacheConfigAdvanced } from "..";
2
+ import type { CatladderJobCache } from "../../types/jobs";
3
+ import { ensureArray } from "../../utils";
4
+
5
+ export function transformLegacyJobCache(
6
+ jobCache: CatladderJobCache | CatladderJobCache[] | undefined,
7
+ ): CacheConfigAdvanced[] {
8
+ return ensureArray(jobCache).map((cache) => ({
9
+ pathMode: "absolute",
10
+ ...cache,
11
+ key: cache.key ?? "default",
12
+ paths: cache.paths ?? [],
13
+ }));
14
+ }
@@ -1,16 +1,10 @@
1
1
  import type { ComponentContext } from "../../types/context";
2
- import { ensureArray } from "../../utils";
3
2
  import { getDockerBuildScriptWithBuiltInDockerFile } from "../docker";
4
3
  import { isOfBuildType } from "../types";
5
4
 
6
5
  import type { CatladderJob } from "../../types/jobs";
7
6
  import { createComponentBuildJobs } from "../base";
8
-
9
- const RUNNER_BUILD_VARIABLES = {
10
- KUBERNETES_CPU_REQUEST: "0.45",
11
- KUBERNETES_MEMORY_REQUEST: "1Gi",
12
- KUBERNETES_MEMORY_LIMIT: "4Gi",
13
- };
7
+ import { createBuildJobDefinition } from "../base/createBuildJobDefinition";
14
8
 
15
9
  export const createCustomBuildJobs = (
16
10
  context: ComponentContext,
@@ -24,13 +18,7 @@ export const createCustomBuildJobs = (
24
18
  return createComponentBuildJobs(context, {
25
19
  appBuild:
26
20
  buildConfig.buildCommand !== null
27
- ? {
28
- image: buildConfig.jobImage,
29
- runnerVariables: RUNNER_BUILD_VARIABLES,
30
- cache: buildConfig.jobCache,
31
- services: buildConfig.jobServices,
32
- script: [...(ensureArray(buildConfig.buildCommand) ?? [])],
33
- }
21
+ ? createBuildJobDefinition(context, buildConfig)
34
22
  : undefined,
35
23
  dockerBuild: {
36
24
  script: getDockerBuildScriptWithBuiltInDockerFile(context),
@@ -1,9 +1,10 @@
1
+ import type { Artifacts } from "../../types";
1
2
  import type { ComponentContext } from "../../types/context";
2
3
  import type { CatladderJob } from "../../types/jobs";
3
4
  import { ensureArray, notNil } from "../../utils";
4
- import { isOfBuildType } from "../types";
5
- import type { Artifacts } from "../../types";
6
5
  import { createArtifactsConfig } from "../base/createArtifactsConfig";
6
+ import { createJobCacheFromConfig } from "../cache/createJobCache";
7
+ import { isOfBuildType } from "../types";
7
8
 
8
9
  const RUNNER_CUSTOM_TEST_VARIABLES = {
9
10
  KUBERNETES_CPU_REQUEST: "0.45",
@@ -34,7 +35,7 @@ export const createCustomTestJobs = (
34
35
  },
35
36
  runnerVariables: RUNNER_CUSTOM_TEST_VARIABLES,
36
37
  services: buildConfig.jobServices,
37
- cache: buildConfig.jobCache,
38
+ cache: createJobCacheFromConfig(context, buildConfig),
38
39
  stage: "test",
39
40
  needs: [],
40
41
  envMode: "none",
@@ -45,7 +46,7 @@ export const createCustomTestJobs = (
45
46
  ...base,
46
47
  image: buildConfig.audit?.jobImage ?? buildConfig.jobImage,
47
48
  cache: undefined,
48
- script: [...(ensureArray(buildConfig.audit?.command) ?? [])],
49
+ script: [...ensureArray(buildConfig.audit?.command)],
49
50
  allow_failure: true,
50
51
  ...createArtifactsConfig(
51
52
  context.build.dir,
@@ -61,7 +62,7 @@ export const createCustomTestJobs = (
61
62
 
62
63
  ...base,
63
64
  image: buildConfig.lint?.jobImage ?? buildConfig.jobImage,
64
- script: [...(ensureArray(buildConfig.lint?.command) ?? [])],
65
+ script: [...ensureArray(buildConfig.lint?.command)],
65
66
  ...createArtifactsConfig(
66
67
  context.build.dir,
67
68
  buildConfig.lint?.artifactsReports,
@@ -75,7 +76,7 @@ export const createCustomTestJobs = (
75
76
 
76
77
  ...base,
77
78
  image: buildConfig.test?.jobImage ?? buildConfig.jobImage,
78
- script: [...(ensureArray(buildConfig.test?.command) ?? [])],
79
+ script: [...ensureArray(buildConfig.test?.command)],
79
80
  ...createArtifactsConfig(
80
81
  context.build.dir,
81
82
  buildConfig.test?.artifactsReports,
@@ -10,9 +10,10 @@ import {
10
10
  } from "../deploy/cloudRun/artifactsRegistry";
11
11
  import { gcloudServiceAccountLoginCommands } from "../deploy/cloudRun/utils/gcloudServiceAccountLoginCommands";
12
12
  import { getRunnerImage } from "../runner";
13
- import type { ComponentContext } from "../types";
13
+ import type { ComponentContext, JobDefintion } from "../types";
14
14
  import type { CatladderJob } from "../types/jobs";
15
15
  import { collapseableSection } from "../utils/gitlab";
16
+ import { createJobCacheFromCacheConfigs } from "./cache/createJobCache";
16
17
 
17
18
  const DOCKER_BUILD_RUNNER_REQUESTS = {
18
19
  KUBERNETES_CPU_REQUEST: "0.45",
@@ -118,16 +119,17 @@ export const getDockerJobBaseProps = (): Pick<
118
119
  };
119
120
  };
120
121
 
121
- export type DockerBuildJobDefinition = Partial<CatladderJob>;
122
+ export type DockerBuildJobDefinition = JobDefintion;
122
123
  export const createDockerBuildJobBase = (
123
124
  context: ComponentContext,
124
- { script, ...def }: Partial<CatladderJob>,
125
+ { script, cache, ...def }: JobDefintion,
125
126
  ): CatladderJob => {
126
127
  return merge(
127
128
  {
128
129
  name: DOCKER_BUILD_JOB_NAME,
129
130
  envMode: "jobPerEnv",
130
131
  stage: "build",
132
+ cache: cache ? createJobCacheFromCacheConfigs(context, cache) : undefined,
131
133
  ...getDockerJobBaseProps(),
132
134
  script: script || [],
133
135
  },
@@ -1,4 +1,3 @@
1
- import { getRunnerImage } from "../../runner";
2
1
  import type {
3
2
  BuildContextStandalone,
4
3
  WorkspaceContext,
@@ -8,20 +7,13 @@ import {
8
7
  type ComponentContext,
9
8
  } from "../../types/context";
10
9
  import type { CatladderJob } from "../../types/jobs";
11
- import { ensureArray } from "../../utils";
12
10
  import { createComponentBuildJobs, createWorkspaceBuildJobs } from "../base";
13
11
  import type { AppBuildJobDefinition } from "../base/createAppBuildJob";
12
+ import { createBuildJobDefinition } from "../base/createBuildJobDefinition";
14
13
  import type { DockerBuildJobDefinition } from "../docker";
15
14
  import { getDockerBuildScriptWithBuiltInDockerFile } from "../docker";
16
15
  import type { BuildConfigDocker } from "../types";
17
- import { isOfBuildType } from "../types";
18
- import {
19
- getNextCache,
20
- getNodeCache,
21
- getWorkspaceDefaultCaches,
22
- getYarnCache,
23
- } from "./cache";
24
- import { NODE_RUNNER_BUILD_VARIABLES } from "./constants";
16
+ import { getNextCache, getNodeCache, getYarnCache } from "./cache";
25
17
  import { getDockerAppCopyAndBuildScript, getYarnInstall } from "./yarn";
26
18
 
27
19
  export const createNodeBuildJobs = (
@@ -46,26 +38,11 @@ export const createNodeBuildJobDefinition = (
46
38
  ): AppBuildJobDefinition | undefined => {
47
39
  const buildConfig = context.build.config;
48
40
 
49
- if (!isOfBuildType(buildConfig, "node", "node-static", "storybook")) {
50
- throw new Error("deploy config is not node, node-static or storybook");
51
- }
52
-
53
- if (buildConfig.buildCommand === null) return undefined;
54
-
55
- const defaultImage = getRunnerImage("jobs-default");
56
41
  const yarnInstall = getYarnInstall(context);
57
-
58
- return {
59
- image: buildConfig.jobImage ?? defaultImage,
60
- runnerVariables: NODE_RUNNER_BUILD_VARIABLES,
61
- cache: [
62
- ...(ensureArray(buildConfig.jobCache) ?? []),
63
- ...getNodeCache(context),
64
- ...getNextCache(context),
65
- ],
66
- script: [...yarnInstall, ...(ensureArray(buildConfig.buildCommand) ?? [])],
67
- jobTags: buildConfig.jobTags,
68
- };
42
+ return createBuildJobDefinition(context, buildConfig, {
43
+ prescript: yarnInstall,
44
+ cache: [...getNodeCache(context), ...getNextCache(context)],
45
+ });
69
46
  };
70
47
 
71
48
  export const createNodeDockerJobDefinition = (
@@ -1,35 +1,31 @@
1
1
  import { uniq } from "lodash";
2
2
  import { join } from "path";
3
3
  import slugify from "slugify";
4
+
4
5
  import type { Context, WorkspaceContext } from "../../types/context";
5
- import type { GitlabJobCache } from "../../types/gitlab-types";
6
+ import type { CacheConfig } from "../types";
6
7
 
7
8
  export const getYarnCache = (
8
9
  context: Context,
9
10
  policy = "pull-push",
10
- ): GitlabJobCache[] => {
11
+ ): CacheConfig[] => {
11
12
  const componentIsInWorkspace =
12
13
  context.type === "component" &&
13
14
  context.packageManagerInfo.componentIsInWorkspace;
14
15
  return [
15
- componentIsInWorkspace
16
- ? {
17
- key: "yarn",
18
- policy,
19
- paths: [".yarn"],
20
- }
21
- : {
22
- key: slugify(context.build.dir) + "-yarn",
23
- policy,
24
- paths: [join(context.build.dir, ".yarn")],
25
- },
16
+ {
17
+ scope: componentIsInWorkspace ? "global" : "buildDir",
18
+ key: "yarn",
19
+ policy,
20
+ paths: [".yarn"],
21
+ },
26
22
  ];
27
23
  };
28
24
 
29
25
  export const getNodeModulesCache = (
30
26
  context: Context,
31
27
  policy = "pull-push",
32
- ): GitlabJobCache[] => {
28
+ ): CacheConfig[] => {
33
29
  const componentIsInWorkspace =
34
30
  context.type === "component" &&
35
31
  context.packageManagerInfo.componentIsInWorkspace;
@@ -38,6 +34,9 @@ export const getNodeModulesCache = (
38
34
  // It would slow down all pipelines whenever one adds a new dependency as it will need to download all node_modules again.
39
35
  return [
40
36
  {
37
+ scope: "global",
38
+ pathMode: "absolute",
39
+
41
40
  // if component is in a shared workspace, use workspace cache. use individual cache else
42
41
  key: componentIsInWorkspace
43
42
  ? "node-modules-workspace"
@@ -59,7 +58,7 @@ export const getNodeModulesCache = (
59
58
  export const getNodeCache = (
60
59
  context: Context,
61
60
  policy = "pull-push",
62
- ): GitlabJobCache[] => {
61
+ ): CacheConfig[] => {
63
62
  return [
64
63
  ...getYarnCache(context, policy),
65
64
  ...getNodeModulesCache(context, policy),
@@ -67,15 +66,15 @@ export const getNodeCache = (
67
66
  ];
68
67
  };
69
68
 
70
- export const getNextCache = (context: Context): GitlabJobCache[] => {
71
- const key = context.name + "-next-cache";
69
+ export const getNextCache = (context: Context): CacheConfig[] => {
72
70
  const paths = context.build
73
71
  .getComponentDirs("direct")
74
72
  .map((c) => join(c, ".next/cache"));
75
73
 
76
74
  return [
77
75
  {
78
- key,
76
+ pathMode: "absolute",
77
+ key: "next-cache",
79
78
  policy: "pull-push",
80
79
  paths,
81
80
  },
@@ -84,13 +83,13 @@ export const getNextCache = (context: Context): GitlabJobCache[] => {
84
83
 
85
84
  export const getWorkspaceDefaultCaches = (
86
85
  context: WorkspaceContext,
87
- ): GitlabJobCache[] => {
86
+ ): CacheConfig[] => {
88
87
  return [
89
88
  {
90
89
  // turbo repo
91
- key: context.name + "-turbo",
90
+ key: "turbo",
92
91
  policy: "pull-push",
93
- paths: [join(context.build.dir, ".turbo")],
92
+ paths: [".turbo"],
94
93
  },
95
94
  ];
96
95
  };