@catladder/pipeline 1.99.0 → 1.100.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.
- package/dist/build/custom/testJob.js +26 -12
- package/dist/build/node/buildJob.js +1 -7
- package/dist/build/node/yarn.d.ts +2 -5
- package/dist/build/node/yarn.js +27 -15
- package/dist/build/types.d.ts +25 -9
- package/dist/bundles/catladder-gitlab/index.js +1 -1
- package/dist/constants.js +1 -1
- package/dist/pipeline/packageManager.js +4 -4
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/examples/__snapshots__/cloud-run-memory-limit.ts.snap +24 -12
- package/examples/__snapshots__/cloud-run-no-cpu-throttling.ts.snap +24 -12
- package/examples/__snapshots__/cloud-run-non-public.ts.snap +24 -12
- package/examples/__snapshots__/cloud-run-with-sql-reuse-db.ts.snap +48 -24
- package/examples/__snapshots__/cloud-run-with-sql.ts.snap +48 -24
- package/examples/__snapshots__/custom-build-job-with-tests.ts.snap +50 -0
- package/examples/__snapshots__/custom-deploy.ts.snap +24 -12
- package/examples/__snapshots__/kubernetes-application-customization.ts.snap +24 -12
- package/examples/__snapshots__/kubernetes-with-cloud-sql-legacy.ts.snap +24 -12
- package/examples/__snapshots__/kubernetes-with-cloud-sql.ts.snap +24 -12
- package/examples/__snapshots__/kubernetes-with-jobs.ts.snap +48 -24
- package/examples/__snapshots__/kubernetes-with-mongodb.ts.snap +24 -12
- package/examples/custom-build-job-with-tests.ts +9 -0
- package/package.json +1 -1
- package/src/build/custom/testJob.ts +36 -0
- package/src/build/node/buildJob.ts +3 -8
- package/src/build/node/yarn.ts +38 -25
- package/src/build/types.ts +26 -9
- package/src/pipeline/packageManager.ts +7 -6
|
@@ -1,7 +1,10 @@
|
|
|
1
|
+
import { join } from "path";
|
|
1
2
|
import type { Context } from "../../types/context";
|
|
2
3
|
import type { CatladderJob } from "../../types/jobs";
|
|
3
4
|
import { ensureArray, notNil } from "../../utils";
|
|
4
5
|
import { isOfBuildType } from "../types";
|
|
6
|
+
import type { BuildConfigArtifactsReports } from "../types";
|
|
7
|
+
import type { Artifacts } from "../../types";
|
|
5
8
|
|
|
6
9
|
const RUNNER_CUSTOM_TEST_VARIABLES = {
|
|
7
10
|
KUBERNETES_CPU_REQUEST: "0.5",
|
|
@@ -42,6 +45,10 @@ export const createCustomTestJobs = (context: Context): CatladderJob[] => {
|
|
|
42
45
|
cache: undefined,
|
|
43
46
|
script: [...(ensureArray(buildConfig.audit?.command) ?? [])],
|
|
44
47
|
allow_failure: true,
|
|
48
|
+
...createArtifactsConfig(
|
|
49
|
+
context.componentConfig.dir,
|
|
50
|
+
buildConfig.audit?.artifactsReports
|
|
51
|
+
),
|
|
45
52
|
}
|
|
46
53
|
: null;
|
|
47
54
|
|
|
@@ -52,6 +59,10 @@ export const createCustomTestJobs = (context: Context): CatladderJob[] => {
|
|
|
52
59
|
...base,
|
|
53
60
|
image: buildConfig.lint?.jobImage ?? buildConfig.jobImage,
|
|
54
61
|
script: [...(ensureArray(buildConfig.lint?.command) ?? [])],
|
|
62
|
+
...createArtifactsConfig(
|
|
63
|
+
context.componentConfig.dir,
|
|
64
|
+
buildConfig.lint?.artifactsReports
|
|
65
|
+
),
|
|
55
66
|
}
|
|
56
67
|
: null;
|
|
57
68
|
const testJob: CatladderJob | null = buildConfig.test
|
|
@@ -61,7 +72,32 @@ export const createCustomTestJobs = (context: Context): CatladderJob[] => {
|
|
|
61
72
|
...base,
|
|
62
73
|
image: buildConfig.test?.jobImage ?? buildConfig.jobImage,
|
|
63
74
|
script: [...(ensureArray(buildConfig.test?.command) ?? [])],
|
|
75
|
+
...createArtifactsConfig(
|
|
76
|
+
context.componentConfig.dir,
|
|
77
|
+
buildConfig.test?.artifactsReports
|
|
78
|
+
),
|
|
64
79
|
}
|
|
65
80
|
: null;
|
|
66
81
|
return [auditJob, lintJob, testJob].filter(notNil);
|
|
67
82
|
};
|
|
83
|
+
|
|
84
|
+
type OptionalArtifacts =
|
|
85
|
+
| {
|
|
86
|
+
artifacts: Artifacts;
|
|
87
|
+
}
|
|
88
|
+
| undefined;
|
|
89
|
+
|
|
90
|
+
const createArtifactsConfig = (
|
|
91
|
+
rootPath: string,
|
|
92
|
+
artifactsReports?: BuildConfigArtifactsReports
|
|
93
|
+
): OptionalArtifacts =>
|
|
94
|
+
artifactsReports
|
|
95
|
+
? {
|
|
96
|
+
artifacts: {
|
|
97
|
+
paths: [],
|
|
98
|
+
reports: {
|
|
99
|
+
junit: artifactsReports?.junit?.map((p) => join(rootPath, p)) ?? [],
|
|
100
|
+
},
|
|
101
|
+
},
|
|
102
|
+
}
|
|
103
|
+
: undefined;
|
|
@@ -7,7 +7,7 @@ import { join } from "path";
|
|
|
7
7
|
import { isOfBuildType } from "../types";
|
|
8
8
|
import { getNextCache, getNodeCache, getYarnCache } from "./cache";
|
|
9
9
|
import { NODE_RUNNER_BUILD_VARIABLES } from "./constants";
|
|
10
|
-
import {
|
|
10
|
+
import { getDockerAppCopyAndBuildScript, getYarnInstall } from "./yarn";
|
|
11
11
|
import type { CatladderJob } from "../../types/jobs";
|
|
12
12
|
|
|
13
13
|
export const createNodeBuildJobs = (context: Context): CatladderJob[] => {
|
|
@@ -55,13 +55,8 @@ export const createNodeBuildJobs = (context: Context): CatladderJob[] => {
|
|
|
55
55
|
cache: [...getYarnCache(context, "pull")],
|
|
56
56
|
variables: {
|
|
57
57
|
// only required for non static
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
}),
|
|
61
|
-
YARN_INSTALL_WITHOUT_SCRIPTS: getYarnInstallCommand(context, {
|
|
62
|
-
prodOnly: true,
|
|
63
|
-
noScripts: true,
|
|
64
|
-
}),
|
|
58
|
+
DOCKER_COPY_AND_INSTALL_APP:
|
|
59
|
+
getDockerAppCopyAndBuildScript(context),
|
|
65
60
|
DOCKER_COPY_WORKSPACE_FILES:
|
|
66
61
|
context.packageManagerInfo?.pathsToCopyInDocker
|
|
67
62
|
.map((dir) => `COPY --chown=node:node ${dir} /app/${dir}`)
|
package/src/build/node/yarn.ts
CHANGED
|
@@ -1,33 +1,16 @@
|
|
|
1
1
|
import type { Context } from "../../types";
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
) => {
|
|
3
|
+
const YARN_INSTALL_CLASSIC = `yarn install --frozen-lockfile`;
|
|
4
|
+
|
|
5
|
+
// FIXME: check why and when rebuild is needed
|
|
6
|
+
const YARN_BERRY_PROD_REBUILD = `yarn workspaces focus --production && yarn rebuild`;
|
|
7
|
+
|
|
8
|
+
const getYarnInstallCommand = (context: Context) => {
|
|
10
9
|
if (context.packageManagerInfo?.isClassic) {
|
|
11
|
-
return
|
|
12
|
-
options?.prodOnly ? "--production" : ""
|
|
13
|
-
} ${options?.noScripts ? "--ignore-scripts" : ""}`;
|
|
10
|
+
return YARN_INSTALL_CLASSIC;
|
|
14
11
|
}
|
|
15
|
-
// is modern
|
|
16
12
|
|
|
17
|
-
|
|
18
|
-
// trying to import those fail on this version
|
|
19
|
-
const doesNotShipWithBuiltInPlugins = ["2", "3"].some((v) =>
|
|
20
|
-
context.packageManagerInfo?.version.startsWith(v)
|
|
21
|
-
);
|
|
22
|
-
return options?.prodOnly
|
|
23
|
-
? `${options?.noScripts ? "YARN_ENABLE_SCRIPTS=false " : ""}${
|
|
24
|
-
doesNotShipWithBuiltInPlugins
|
|
25
|
-
? "yarn plugin import workspace-tools && "
|
|
26
|
-
: " "
|
|
27
|
-
}yarn workspaces focus --production && yarn rebuild` // needs yarn plugin import workspace-tools
|
|
28
|
-
: `${
|
|
29
|
-
options?.noScripts ? "YARN_ENABLE_SCRIPTS=false " : ""
|
|
30
|
-
}yarn install --immutable`;
|
|
13
|
+
return `yarn install --immutable`;
|
|
31
14
|
};
|
|
32
15
|
|
|
33
16
|
export const ensureNodeVersion = (context: Context) => [
|
|
@@ -38,3 +21,33 @@ export const getYarnInstall = (context: Context) => [
|
|
|
38
21
|
...ensureNodeVersion(context),
|
|
39
22
|
getYarnInstallCommand(context),
|
|
40
23
|
];
|
|
24
|
+
|
|
25
|
+
const DOCKER_COPY_FILES = `COPY --chown=node:node $APP_DIR .`;
|
|
26
|
+
|
|
27
|
+
export const getDockerAppCopyAndBuildScript = (context: Context) => {
|
|
28
|
+
if (context.packageManagerInfo?.isClassic) {
|
|
29
|
+
return `
|
|
30
|
+
RUN ${YARN_INSTALL_CLASSIC} --production --ignore-scripts
|
|
31
|
+
${DOCKER_COPY_FILES}
|
|
32
|
+
RUN ${YARN_INSTALL_CLASSIC} --production
|
|
33
|
+
`.trim();
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// yarn >= 4 ships with build in plugins, see https://github.com/yarnpkg/berry/pull/4253
|
|
37
|
+
// trying to import those fail on this version
|
|
38
|
+
const doesNotShipWithBuiltInPlugins = ["2", "3"].some((v) =>
|
|
39
|
+
context.packageManagerInfo?.version.startsWith(v)
|
|
40
|
+
);
|
|
41
|
+
const maybeAddWorkspaceToolsCommand = doesNotShipWithBuiltInPlugins
|
|
42
|
+
? "RUN yarn plugin import workspace-tools"
|
|
43
|
+
: "";
|
|
44
|
+
|
|
45
|
+
// copy first everything and then install
|
|
46
|
+
// rebuild first does not work as it will run postinstall and that might require files in the app
|
|
47
|
+
return `
|
|
48
|
+
${DOCKER_COPY_FILES}
|
|
49
|
+
${maybeAddWorkspaceToolsCommand}
|
|
50
|
+
RUN ${YARN_BERRY_PROD_REBUILD}
|
|
51
|
+
|
|
52
|
+
`.trim();
|
|
53
|
+
};
|
package/src/build/types.ts
CHANGED
|
@@ -2,6 +2,16 @@ import type { GitlabJobImage, GitlabJobService } from "../types";
|
|
|
2
2
|
|
|
3
3
|
import type { CatladderJob } from "../types/jobs";
|
|
4
4
|
|
|
5
|
+
export type BuildConfigArtifactsReports = {
|
|
6
|
+
/**
|
|
7
|
+
* The junit report collects JUnit report format XML files.
|
|
8
|
+
* The collected Unit test reports upload to GitLab as an artifact.
|
|
9
|
+
* Paths are prefixed with component's root folder.
|
|
10
|
+
* eg. `["dist/test-results/TEST-*.xml", "dist/rspec.xml", ...]`
|
|
11
|
+
*/
|
|
12
|
+
junit?: string[];
|
|
13
|
+
};
|
|
14
|
+
|
|
5
15
|
export type BuildConfigBase = {
|
|
6
16
|
/**
|
|
7
17
|
* command to run on the image to start the app (e.g. yarn start)
|
|
@@ -64,15 +74,7 @@ export type BuildConfigBase = {
|
|
|
64
74
|
* additional CI/CD artifacts reports,
|
|
65
75
|
* use to display information in merge requests, pipeline views and security dashboards.
|
|
66
76
|
*/
|
|
67
|
-
artifactsReports?:
|
|
68
|
-
/**
|
|
69
|
-
* The junit report collects JUnit report format XML files.
|
|
70
|
-
* The collected Unit test reports upload to GitLab as an artifact.
|
|
71
|
-
* Paths are prefixed with component's root folder.
|
|
72
|
-
* eg. `["dist/test-results/TEST-*.xml", "dist/rspec.xml", ...]`
|
|
73
|
-
*/
|
|
74
|
-
junit?: string[];
|
|
75
|
-
};
|
|
77
|
+
artifactsReports?: BuildConfigArtifactsReports;
|
|
76
78
|
};
|
|
77
79
|
|
|
78
80
|
export type BuildConfigNodeBase = BuildConfigBase;
|
|
@@ -132,6 +134,11 @@ export type BuildConfigCustom = Omit<
|
|
|
132
134
|
lint?: {
|
|
133
135
|
command?: string | string[];
|
|
134
136
|
jobImage?: GitlabJobImage;
|
|
137
|
+
/**
|
|
138
|
+
* additional CI/CD artifacts reports,
|
|
139
|
+
* use to display information in merge requests, pipeline views and security dashboards.
|
|
140
|
+
*/
|
|
141
|
+
artifactsReports?: BuildConfigArtifactsReports;
|
|
135
142
|
};
|
|
136
143
|
|
|
137
144
|
/**
|
|
@@ -140,6 +147,11 @@ export type BuildConfigCustom = Omit<
|
|
|
140
147
|
test?: {
|
|
141
148
|
command?: string | string[];
|
|
142
149
|
jobImage?: GitlabJobImage;
|
|
150
|
+
/**
|
|
151
|
+
* additional CI/CD artifacts reports,
|
|
152
|
+
* use to display information in merge requests, pipeline views and security dashboards.
|
|
153
|
+
*/
|
|
154
|
+
artifactsReports?: BuildConfigArtifactsReports;
|
|
143
155
|
};
|
|
144
156
|
|
|
145
157
|
/**
|
|
@@ -148,6 +160,11 @@ export type BuildConfigCustom = Omit<
|
|
|
148
160
|
audit?: {
|
|
149
161
|
command?: string | string[];
|
|
150
162
|
jobImage?: GitlabJobImage;
|
|
163
|
+
/**
|
|
164
|
+
* additional CI/CD artifacts reports,
|
|
165
|
+
* use to display information in merge requests, pipeline views and security dashboards.
|
|
166
|
+
*/
|
|
167
|
+
artifactsReports?: BuildConfigArtifactsReports;
|
|
151
168
|
};
|
|
152
169
|
|
|
153
170
|
/**
|
|
@@ -29,11 +29,12 @@ export const getPackageManagerInfo = async (
|
|
|
29
29
|
? join(workspaceRoot, "yarn.lock")
|
|
30
30
|
: join(component.dir, "yarn.lock");
|
|
31
31
|
const configFiles = [".yarnrc", ".yarnrc.yml", ".npmrc", ".yarn"]; // ".yarn" is yarn 2 folder
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
32
|
+
// copy all those configFiles from workspace root and/or component folder
|
|
33
|
+
|
|
34
|
+
const configFilePaths = [
|
|
35
|
+
...configFiles,
|
|
36
|
+
...configFiles.map((f) => join(component.dir, f)),
|
|
37
|
+
].filter((f) => existsSync(f));
|
|
37
38
|
|
|
38
39
|
// get all folders that this workspace depend on
|
|
39
40
|
// we will later copy them into the docker build
|
|
@@ -50,7 +51,7 @@ export const getPackageManagerInfo = async (
|
|
|
50
51
|
packageJson,
|
|
51
52
|
...(workspacePackageJson ? [workspacePackageJson] : []),
|
|
52
53
|
lockFile,
|
|
53
|
-
...
|
|
54
|
+
...configFilePaths,
|
|
54
55
|
...workspaceDependencies,
|
|
55
56
|
];
|
|
56
57
|
return {
|