@catladder/pipeline 1.165.1 → 1.166.1
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.
- package/dist/build/base/createAppBuildJob.d.ts +3 -1
- package/dist/build/base/createAppBuildJob.js +6 -4
- package/dist/build/base/createBuildJobDefinition.d.ts +7 -0
- package/dist/build/base/createBuildJobDefinition.js +58 -0
- package/dist/build/cache/createJobCache.d.ts +6 -0
- package/dist/build/cache/createJobCache.js +109 -0
- package/dist/build/cache/getAllCacheConfigsFromConfig.d.ts +3 -0
- package/dist/build/cache/getAllCacheConfigsFromConfig.js +66 -0
- package/dist/build/cache/transformLegacyJobCache.d.ts +3 -0
- package/dist/build/cache/transformLegacyJobCache.js +29 -0
- package/dist/build/custom/buildJob.js +2 -45
- package/dist/build/custom/testJob.d.ts +1 -1
- package/dist/build/custom/testJob.js +12 -11
- package/dist/build/docker.d.ts +4 -3
- package/dist/build/docker.js +5 -2
- package/dist/build/node/buildJob.js +5 -17
- package/dist/build/node/cache.d.ts +6 -6
- package/dist/build/node/cache.js +9 -9
- package/dist/build/node/meteor.js +2 -3
- package/dist/build/node/testJob.js +6 -5
- package/dist/build/node/yarn.js +1 -2
- package/dist/build/rails/test.js +3 -3
- package/dist/build/sbom.js +1 -1
- package/dist/build/types.d.ts +43 -4
- package/dist/bundles/catladder-gitlab/index.js +2 -2
- package/dist/constants.js +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/types/gitlab-types.d.ts +2 -2
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.js +1 -0
- package/dist/types/jobDefinition.d.ts +5 -0
- package/dist/types/jobDefinition.js +5 -0
- package/dist/types/jobs.d.ts +3 -2
- package/dist/utils/index.d.ts +2 -1
- package/dist/utils/index.js +7 -2
- package/examples/__snapshots__/cloud-run-with-sql.test.ts.snap +817 -1717
- package/examples/__snapshots__/custom-build-job-with-tests.test.ts.snap +0 -4
- package/examples/__snapshots__/custom-build-job.test.ts.snap +0 -4
- package/examples/__snapshots__/custom-sbom-java.test.ts.snap +0 -4
- package/examples/__snapshots__/native-app.test.ts.snap +24 -20
- package/examples/__snapshots__/workspace-api-www-custom-cache.test.ts.snap +2374 -0
- package/examples/__snapshots__/workspace-api-www.test.ts.snap +2354 -0
- package/examples/cloud-run-with-sql.ts +1 -23
- package/examples/workspace-api-www-custom-cache.test.ts +11 -0
- package/examples/workspace-api-www-custom-cache.ts +51 -0
- package/examples/workspace-api-www.test.ts +11 -0
- package/examples/workspace-api-www.ts +45 -0
- package/package.json +1 -1
- package/src/build/base/createAppBuildJob.ts +6 -4
- package/src/build/base/createBuildJobDefinition.ts +38 -0
- package/src/build/cache/createJobCache.ts +85 -0
- package/src/build/cache/getAllCacheConfigsFromConfig.ts +33 -0
- package/src/build/cache/transformLegacyJobCache.ts +14 -0
- package/src/build/custom/buildJob.ts +2 -14
- package/src/build/custom/testJob.ts +7 -6
- package/src/build/docker.ts +5 -3
- package/src/build/node/buildJob.ts +6 -29
- package/src/build/node/cache.ts +21 -21
- package/src/build/node/meteor.ts +7 -8
- package/src/build/node/testJob.ts +7 -6
- package/src/build/node/yarn.ts +1 -1
- package/src/build/rails/test.ts +4 -4
- package/src/build/sbom.ts +2 -2
- package/src/build/types.ts +54 -4
- package/src/types/gitlab-types.ts +2 -2
- package/src/types/index.ts +1 -0
- package/src/types/jobDefinition.ts +9 -0
- package/src/types/jobs.ts +5 -8
- 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
|
-
|
|
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
|
@@ -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 =
|
|
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
|
-
...
|
|
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
|
|
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: [...
|
|
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: [...
|
|
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: [...
|
|
79
|
+
script: [...ensureArray(buildConfig.test?.command)],
|
|
79
80
|
...createArtifactsConfig(
|
|
80
81
|
context.build.dir,
|
|
81
82
|
buildConfig.test?.artifactsReports,
|
package/src/build/docker.ts
CHANGED
|
@@ -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 =
|
|
122
|
+
export type DockerBuildJobDefinition = JobDefintion;
|
|
122
123
|
export const createDockerBuildJobBase = (
|
|
123
124
|
context: ComponentContext,
|
|
124
|
-
{ script, ...def }:
|
|
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 {
|
|
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
|
-
|
|
59
|
-
|
|
60
|
-
|
|
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 = (
|
package/src/build/node/cache.ts
CHANGED
|
@@ -1,35 +1,32 @@
|
|
|
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 {
|
|
6
|
+
import type { CacheConfig } from "../types";
|
|
6
7
|
|
|
7
8
|
export const getYarnCache = (
|
|
8
9
|
context: Context,
|
|
9
10
|
policy = "pull-push",
|
|
10
|
-
):
|
|
11
|
+
): CacheConfig[] => {
|
|
11
12
|
const componentIsInWorkspace =
|
|
12
13
|
context.type === "component" &&
|
|
13
14
|
context.packageManagerInfo.componentIsInWorkspace;
|
|
14
15
|
return [
|
|
15
|
-
|
|
16
|
-
?
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
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
|
+
pathMode: componentIsInWorkspace ? "absolute" : "relative",
|
|
19
|
+
key: "yarn",
|
|
20
|
+
policy,
|
|
21
|
+
paths: [".yarn"],
|
|
22
|
+
},
|
|
26
23
|
];
|
|
27
24
|
};
|
|
28
25
|
|
|
29
26
|
export const getNodeModulesCache = (
|
|
30
27
|
context: Context,
|
|
31
28
|
policy = "pull-push",
|
|
32
|
-
):
|
|
29
|
+
): CacheConfig[] => {
|
|
33
30
|
const componentIsInWorkspace =
|
|
34
31
|
context.type === "component" &&
|
|
35
32
|
context.packageManagerInfo.componentIsInWorkspace;
|
|
@@ -38,6 +35,9 @@ export const getNodeModulesCache = (
|
|
|
38
35
|
// It would slow down all pipelines whenever one adds a new dependency as it will need to download all node_modules again.
|
|
39
36
|
return [
|
|
40
37
|
{
|
|
38
|
+
scope: "global",
|
|
39
|
+
pathMode: "absolute",
|
|
40
|
+
|
|
41
41
|
// if component is in a shared workspace, use workspace cache. use individual cache else
|
|
42
42
|
key: componentIsInWorkspace
|
|
43
43
|
? "node-modules-workspace"
|
|
@@ -59,7 +59,7 @@ export const getNodeModulesCache = (
|
|
|
59
59
|
export const getNodeCache = (
|
|
60
60
|
context: Context,
|
|
61
61
|
policy = "pull-push",
|
|
62
|
-
):
|
|
62
|
+
): CacheConfig[] => {
|
|
63
63
|
return [
|
|
64
64
|
...getYarnCache(context, policy),
|
|
65
65
|
...getNodeModulesCache(context, policy),
|
|
@@ -67,15 +67,15 @@ export const getNodeCache = (
|
|
|
67
67
|
];
|
|
68
68
|
};
|
|
69
69
|
|
|
70
|
-
export const getNextCache = (context: Context):
|
|
71
|
-
const key = context.name + "-next-cache";
|
|
70
|
+
export const getNextCache = (context: Context): CacheConfig[] => {
|
|
72
71
|
const paths = context.build
|
|
73
72
|
.getComponentDirs("direct")
|
|
74
73
|
.map((c) => join(c, ".next/cache"));
|
|
75
74
|
|
|
76
75
|
return [
|
|
77
76
|
{
|
|
78
|
-
|
|
77
|
+
pathMode: "absolute",
|
|
78
|
+
key: "next-cache",
|
|
79
79
|
policy: "pull-push",
|
|
80
80
|
paths,
|
|
81
81
|
},
|
|
@@ -84,13 +84,13 @@ export const getNextCache = (context: Context): GitlabJobCache[] => {
|
|
|
84
84
|
|
|
85
85
|
export const getWorkspaceDefaultCaches = (
|
|
86
86
|
context: WorkspaceContext,
|
|
87
|
-
):
|
|
87
|
+
): CacheConfig[] => {
|
|
88
88
|
return [
|
|
89
89
|
{
|
|
90
90
|
// turbo repo
|
|
91
|
-
key:
|
|
91
|
+
key: "turbo",
|
|
92
92
|
policy: "pull-push",
|
|
93
|
-
paths: [
|
|
93
|
+
paths: [".turbo"],
|
|
94
94
|
},
|
|
95
95
|
];
|
|
96
96
|
};
|