@catladder/pipeline 1.146.2 → 1.148.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/build/base/createAppBuildJob.js +6 -6
- package/dist/build/base/writeBuildInfo.js +1 -1
- package/dist/build/base/writeDotEnv.js +1 -1
- package/dist/build/custom/__tests__/testJob.test.js +11 -14
- package/dist/build/custom/buildJob.js +5 -5
- package/dist/build/custom/testJob.js +5 -5
- package/dist/build/docker.d.ts +26 -9
- package/dist/build/docker.js +41 -20
- package/dist/build/node/buildJob.js +8 -8
- package/dist/build/node/cache.js +1 -1
- package/dist/build/node/meteor.js +6 -6
- package/dist/build/node/testJob.js +11 -11
- package/dist/build/rails/build.js +3 -3
- package/dist/build/rails/test.js +4 -4
- package/dist/build/sbom.js +2 -2
- package/dist/build/types.d.ts +34 -26
- package/dist/bundles/catladder-gitlab/index.js +2 -2
- package/dist/constants.js +1 -1
- package/dist/context/getLabels.js +1 -1
- package/dist/context/index.js +34 -12
- package/dist/deploy/base/deploy.js +9 -8
- package/dist/deploy/cloudRun/artifactsRegistry.d.ts +1 -5
- package/dist/deploy/cloudRun/artifactsRegistry.js +8 -9
- package/dist/deploy/cloudRun/cloudRunRevisions.js +4 -5
- package/dist/deploy/cloudRun/createJobs/cloudRunServices.js +1 -1
- package/dist/deploy/cloudRun/createJobs/common.d.ts +4 -4
- package/dist/deploy/cloudRun/createJobs/common.js +2 -1
- package/dist/deploy/cloudRun/createJobs/index.js +2 -4
- package/dist/deploy/custom/deployJob.js +7 -10
- package/dist/deploy/dockerTag/deployJob.js +3 -5
- package/dist/deploy/kubernetes/cloudSql/index.js +11 -9
- package/dist/deploy/kubernetes/deployJob.js +4 -7
- package/dist/deploy/kubernetes/kubeEnv.js +2 -1
- package/dist/deploy/kubernetes/kubeValues.js +10 -10
- package/dist/deploy/kubernetes/mongodb.js +11 -11
- package/dist/deploy/sbom.js +1 -1
- package/dist/deploy/types/index.d.ts +1 -1
- package/dist/deploy/types/index.js +1 -1
- package/dist/deploy/utils.js +2 -1
- package/dist/pipeline/createJobsForComponent.js +5 -5
- package/dist/pipeline/generatePipelineFiles.js +40 -9
- package/dist/pipeline/gitlab/createGitlabJobs.js +2 -9
- package/dist/pipeline/gitlab/sortGitLabJobDefProps.d.ts +7 -0
- package/dist/pipeline/gitlab/sortGitLabJobDefProps.js +27 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/types/config.d.ts +1 -1
- package/dist/types/context.d.ts +13 -1
- package/dist/utils/removeUndefined.d.ts +1 -0
- package/dist/utils/removeUndefined.js +36 -0
- package/examples/__snapshots__/cloud-run-storybook.ts.snap +1687 -0
- package/examples/__snapshots__/cloud-run-with-ngnix.ts.snap +1971 -0
- package/examples/cloud-run-storybook.ts +24 -0
- package/examples/cloud-run-with-ngnix.ts +24 -0
- package/package.json +1 -1
- package/src/build/base/createAppBuildJob.ts +7 -7
- package/src/build/base/writeBuildInfo.ts +1 -1
- package/src/build/base/writeDotEnv.ts +1 -1
- package/src/build/custom/__tests__/testJob.test.ts +5 -8
- package/src/build/custom/buildJob.ts +6 -9
- package/src/build/custom/testJob.ts +5 -5
- package/src/build/docker.ts +68 -24
- package/src/build/node/buildJob.ts +12 -12
- package/src/build/node/cache.ts +1 -1
- package/src/build/node/meteor.ts +11 -17
- package/src/build/node/testJob.ts +14 -14
- package/src/build/rails/build.ts +3 -3
- package/src/build/rails/test.ts +4 -4
- package/src/build/sbom.ts +3 -3
- package/src/build/types.ts +53 -38
- package/src/context/getLabels.ts +1 -1
- package/src/context/index.ts +21 -5
- package/src/deploy/base/deploy.ts +8 -14
- package/src/deploy/cloudRun/artifactsRegistry.ts +5 -10
- package/src/deploy/cloudRun/cloudRunRevisions.ts +3 -5
- package/src/deploy/cloudRun/createJobs/cloudRunServices.ts +1 -1
- package/src/deploy/cloudRun/createJobs/common.ts +5 -5
- package/src/deploy/cloudRun/createJobs/index.ts +1 -4
- package/src/deploy/custom/deployJob.ts +4 -6
- package/src/deploy/dockerTag/deployJob.ts +2 -5
- package/src/deploy/kubernetes/cloudSql/index.ts +7 -4
- package/src/deploy/kubernetes/deployJob.ts +1 -4
- package/src/deploy/kubernetes/kubeEnv.ts +1 -1
- package/src/deploy/kubernetes/kubeValues.ts +3 -3
- package/src/deploy/kubernetes/mongodb.ts +6 -6
- package/src/deploy/sbom.ts +1 -2
- package/src/deploy/types/index.ts +2 -2
- package/src/deploy/utils.ts +1 -1
- package/src/pipeline/createJobsForComponent.ts +6 -10
- package/src/pipeline/generatePipelineFiles.ts +21 -8
- package/src/pipeline/gitlab/createGitlabJobs.ts +2 -7
- package/src/pipeline/gitlab/sortGitLabJobDefProps.ts +59 -0
- package/src/types/config.ts +3 -1
- package/src/types/context.ts +16 -1
- package/src/utils/removeUndefined.ts +4 -0
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { Config } from "../src";
|
|
2
|
+
import { createAllPipelines } from "./__utils__/helpers";
|
|
3
|
+
|
|
4
|
+
const config: Config = {
|
|
5
|
+
appName: "test-app",
|
|
6
|
+
customerName: "pan",
|
|
7
|
+
components: {
|
|
8
|
+
api: {
|
|
9
|
+
dir: "app",
|
|
10
|
+
build: {
|
|
11
|
+
type: "storybook",
|
|
12
|
+
},
|
|
13
|
+
deploy: {
|
|
14
|
+
type: "google-cloudrun",
|
|
15
|
+
projectId: "asdf",
|
|
16
|
+
region: "asia-east1",
|
|
17
|
+
},
|
|
18
|
+
},
|
|
19
|
+
},
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
it("matches snapshot", async () => {
|
|
23
|
+
expect(await createAllPipelines(config)).toMatchSnapshot();
|
|
24
|
+
});
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { Config } from "../src";
|
|
2
|
+
import { createAllPipelines } from "./__utils__/helpers";
|
|
3
|
+
|
|
4
|
+
const config: Config = {
|
|
5
|
+
appName: "test-app",
|
|
6
|
+
customerName: "pan",
|
|
7
|
+
components: {
|
|
8
|
+
api: {
|
|
9
|
+
dir: "app",
|
|
10
|
+
build: {
|
|
11
|
+
type: "node-static",
|
|
12
|
+
},
|
|
13
|
+
deploy: {
|
|
14
|
+
type: "google-cloudrun",
|
|
15
|
+
projectId: "asdf",
|
|
16
|
+
region: "asia-east1",
|
|
17
|
+
},
|
|
18
|
+
},
|
|
19
|
+
},
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
it("matches snapshot", async () => {
|
|
23
|
+
expect(await createAllPipelines(config)).toMatchSnapshot();
|
|
24
|
+
});
|
package/package.json
CHANGED
|
@@ -29,12 +29,12 @@ export const createAppBuildJob = (
|
|
|
29
29
|
...(variables ?? {}),
|
|
30
30
|
...context.environment.envVars,
|
|
31
31
|
...context.environment.jobOnlyVars.build.envVars,
|
|
32
|
-
...(context.
|
|
32
|
+
...(context.build.config.extraVars ?? {}),
|
|
33
33
|
},
|
|
34
34
|
runnerVariables: {
|
|
35
35
|
...RUNNER_BUILD_RESOURCE_VARIABLES,
|
|
36
36
|
...(runnerVariables ?? {}),
|
|
37
|
-
...(context.
|
|
37
|
+
...(context.build.config.runnerVariables ?? {}),
|
|
38
38
|
},
|
|
39
39
|
|
|
40
40
|
script: [
|
|
@@ -42,15 +42,15 @@ export const createAppBuildJob = (
|
|
|
42
42
|
? writeDotEnv(context)
|
|
43
43
|
: []),
|
|
44
44
|
...writeBuildInfo(context),
|
|
45
|
-
...ensureNodeVersion(context.
|
|
46
|
-
`cd ${context.
|
|
45
|
+
...ensureNodeVersion(context.build), // in pure node repos, we might want to have the nvmrc file in top-level
|
|
46
|
+
`cd ${context.build.dir}`,
|
|
47
47
|
...(ensureArray(script) ?? []),
|
|
48
48
|
],
|
|
49
49
|
artifacts: {
|
|
50
|
-
paths: [join(context.
|
|
50
|
+
paths: [join(context.build.dir, "__build_info.json")],
|
|
51
51
|
reports: {
|
|
52
|
-
junit: context.
|
|
53
|
-
|
|
52
|
+
junit: context.build.config.artifactsReports?.junit?.map((p) =>
|
|
53
|
+
join(context.build.dir, p),
|
|
54
54
|
),
|
|
55
55
|
},
|
|
56
56
|
},
|
|
@@ -2,6 +2,6 @@ import type { ComponentContext } from "../../types";
|
|
|
2
2
|
|
|
3
3
|
export const writeBuildInfo = (context: ComponentContext) => {
|
|
4
4
|
return [
|
|
5
|
-
`echo '{"id":"${context.environment.envVars.BUILD_INFO_BUILD_ID}","time":"${context.environment.envVars.BUILD_INFO_BUILD_TIME}"}' > ${context.
|
|
5
|
+
`echo '{"id":"${context.environment.envVars.BUILD_INFO_BUILD_ID}","time":"${context.environment.envVars.BUILD_INFO_BUILD_TIME}"}' > ${context.build.dir}/__build_info.json`,
|
|
6
6
|
];
|
|
7
7
|
};
|
|
@@ -2,11 +2,6 @@ import type { ComponentContext } from "../../..";
|
|
|
2
2
|
import { createCustomTestJobs } from "../testJob";
|
|
3
3
|
|
|
4
4
|
describe("createCustomTestJobs", () => {
|
|
5
|
-
const componentConfig: ComponentContext["componentConfig"] = {
|
|
6
|
-
dir: ".",
|
|
7
|
-
build: { type: "custom", docker: { type: "custom" }, jobImage: "" },
|
|
8
|
-
deploy: {},
|
|
9
|
-
} as ComponentContext["componentConfig"];
|
|
10
5
|
const baseContext: ComponentContext = {
|
|
11
6
|
componentName: "testComponent",
|
|
12
7
|
environment: {
|
|
@@ -14,15 +9,17 @@ describe("createCustomTestJobs", () => {
|
|
|
14
9
|
build: {},
|
|
15
10
|
},
|
|
16
11
|
},
|
|
17
|
-
|
|
12
|
+
build: {
|
|
13
|
+
config: { type: "custom", docker: { type: "custom" }, jobImage: "" },
|
|
14
|
+
},
|
|
18
15
|
} as ComponentContext;
|
|
19
16
|
|
|
20
17
|
it("throws error when not build type custom", () => {
|
|
21
|
-
|
|
18
|
+
baseContext.build.config.type = "node";
|
|
22
19
|
expect(() => createCustomTestJobs(baseContext)).toThrowError(
|
|
23
20
|
"deploy config is not custom",
|
|
24
21
|
);
|
|
25
|
-
|
|
22
|
+
baseContext.build.config.type = "custom";
|
|
26
23
|
});
|
|
27
24
|
|
|
28
25
|
it("returns empty array if no audit, lint, and test definition", () => {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { join } from "path";
|
|
2
2
|
import type { ComponentContext } from "../../types/context";
|
|
3
3
|
import { ensureArray } from "../../utils";
|
|
4
|
-
import {
|
|
4
|
+
import { getDockerBuildScriptWithBuiltInDockerFile } from "../docker";
|
|
5
5
|
import { isOfBuildType } from "../types";
|
|
6
6
|
|
|
7
7
|
import type { CatladderJob } from "../../types/jobs";
|
|
@@ -16,7 +16,7 @@ const RUNNER_BUILD_VARIABLES = {
|
|
|
16
16
|
export const createCustomBuildJobs = (
|
|
17
17
|
context: ComponentContext,
|
|
18
18
|
): CatladderJob[] => {
|
|
19
|
-
const buildConfig = context.
|
|
19
|
+
const buildConfig = context.build.config;
|
|
20
20
|
|
|
21
21
|
if (!isOfBuildType(buildConfig, "custom")) {
|
|
22
22
|
throw new Error("deploy config is not custom");
|
|
@@ -33,10 +33,10 @@ export const createCustomBuildJobs = (
|
|
|
33
33
|
script: [...(ensureArray(buildConfig.buildCommand) ?? [])],
|
|
34
34
|
artifacts: {
|
|
35
35
|
paths: [
|
|
36
|
-
join(context.
|
|
37
|
-
join(context.
|
|
36
|
+
join(context.build.dir, "__build_info.json"),
|
|
37
|
+
join(context.build.dir, "dist"),
|
|
38
38
|
...(buildConfig.artifactsPaths?.map((path) =>
|
|
39
|
-
join(context.
|
|
39
|
+
join(context.build.dir, path),
|
|
40
40
|
) ?? []),
|
|
41
41
|
],
|
|
42
42
|
expire_in: "1 day",
|
|
@@ -44,10 +44,7 @@ export const createCustomBuildJobs = (
|
|
|
44
44
|
}
|
|
45
45
|
: undefined,
|
|
46
46
|
dockerBuild: {
|
|
47
|
-
script:
|
|
48
|
-
context,
|
|
49
|
-
buildConfig.docker?.type === "nginx" ? "ensureNginxDockerfile" : "",
|
|
50
|
-
),
|
|
47
|
+
script: getDockerBuildScriptWithBuiltInDockerFile(context),
|
|
51
48
|
|
|
52
49
|
variables: {},
|
|
53
50
|
},
|
|
@@ -20,7 +20,7 @@ export const createCustomTestJobs = (
|
|
|
20
20
|
return [];
|
|
21
21
|
}
|
|
22
22
|
|
|
23
|
-
const buildConfig = context.
|
|
23
|
+
const buildConfig = context.build.config;
|
|
24
24
|
|
|
25
25
|
if (!isOfBuildType(buildConfig, "custom")) {
|
|
26
26
|
throw new Error("deploy config is not custom");
|
|
@@ -28,7 +28,7 @@ export const createCustomTestJobs = (
|
|
|
28
28
|
|
|
29
29
|
const base: Omit<CatladderJob, "script" | "name"> = {
|
|
30
30
|
variables: {
|
|
31
|
-
APP_PATH: context.
|
|
31
|
+
APP_PATH: context.build.dir,
|
|
32
32
|
...context.environment.jobOnlyVars.build.envVars,
|
|
33
33
|
...(buildConfig.extraVars ?? {}),
|
|
34
34
|
},
|
|
@@ -48,7 +48,7 @@ export const createCustomTestJobs = (
|
|
|
48
48
|
script: [...(ensureArray(buildConfig.audit?.command) ?? [])],
|
|
49
49
|
allow_failure: true,
|
|
50
50
|
...createArtifactsConfig(
|
|
51
|
-
context.
|
|
51
|
+
context.build.dir,
|
|
52
52
|
buildConfig.audit?.artifactsReports,
|
|
53
53
|
buildConfig.audit?.artifacts,
|
|
54
54
|
),
|
|
@@ -63,7 +63,7 @@ export const createCustomTestJobs = (
|
|
|
63
63
|
image: buildConfig.lint?.jobImage ?? buildConfig.jobImage,
|
|
64
64
|
script: [...(ensureArray(buildConfig.lint?.command) ?? [])],
|
|
65
65
|
...createArtifactsConfig(
|
|
66
|
-
context.
|
|
66
|
+
context.build.dir,
|
|
67
67
|
buildConfig.lint?.artifactsReports,
|
|
68
68
|
buildConfig.lint?.artifacts,
|
|
69
69
|
),
|
|
@@ -77,7 +77,7 @@ export const createCustomTestJobs = (
|
|
|
77
77
|
image: buildConfig.test?.jobImage ?? buildConfig.jobImage,
|
|
78
78
|
script: [...(ensureArray(buildConfig.test?.command) ?? [])],
|
|
79
79
|
...createArtifactsConfig(
|
|
80
|
-
context.
|
|
80
|
+
context.build.dir,
|
|
81
81
|
buildConfig.test?.artifactsReports,
|
|
82
82
|
buildConfig.test?.artifacts,
|
|
83
83
|
),
|
package/src/build/docker.ts
CHANGED
|
@@ -1,17 +1,18 @@
|
|
|
1
|
-
import { merge } from "lodash";
|
|
2
|
-
import { isOfDeployType } from "../deploy";
|
|
3
|
-
import { getRunnerImage } from "../runner";
|
|
4
|
-
import type { ComponentContext } from "../types";
|
|
5
|
-
import type { CatladderJob } from "../types/jobs";
|
|
6
1
|
import { existsSync } from "fs";
|
|
2
|
+
import { merge } from "lodash";
|
|
7
3
|
import path from "path";
|
|
8
|
-
import {
|
|
4
|
+
import type { BuildConfig, BuildConfigDocker } from ".";
|
|
5
|
+
import { isOfDeployType } from "../deploy";
|
|
9
6
|
import {
|
|
10
7
|
getArtifactsRegistryBuildCacheImage,
|
|
11
8
|
getArtifactsRegistryHost,
|
|
12
9
|
getArtifactsRegistryImageName,
|
|
13
10
|
} from "../deploy/cloudRun/artifactsRegistry";
|
|
14
11
|
import { gcloudServiceAccountLoginCommands } from "../deploy/cloudRun/utils/gcloudServiceAccountLoginCommands";
|
|
12
|
+
import { getRunnerImage } from "../runner";
|
|
13
|
+
import type { ComponentContext } from "../types";
|
|
14
|
+
import type { CatladderJob } from "../types/jobs";
|
|
15
|
+
import { collapseableSection } from "../utils/gitlab";
|
|
15
16
|
|
|
16
17
|
const DOCKER_BUILD_RUNNER_REQUESTS = {
|
|
17
18
|
KUBERNETES_CPU_REQUEST: "0.5",
|
|
@@ -20,8 +21,9 @@ const DOCKER_BUILD_RUNNER_REQUESTS = {
|
|
|
20
21
|
};
|
|
21
22
|
|
|
22
23
|
export const getDockerImageVariables = (context: ComponentContext) => {
|
|
24
|
+
const deployConfig = context.deploy?.config;
|
|
23
25
|
return {
|
|
24
|
-
...(isOfDeployType(
|
|
26
|
+
...(isOfDeployType(deployConfig, "google-cloudrun")
|
|
25
27
|
? {
|
|
26
28
|
DOCKER_REGISTRY: getArtifactsRegistryHost(context),
|
|
27
29
|
DOCKER_IMAGE: getArtifactsRegistryImageName(context),
|
|
@@ -46,11 +48,19 @@ export const getDockerImageVariables = (context: ComponentContext) => {
|
|
|
46
48
|
/**
|
|
47
49
|
* Weather the context requires a docker build
|
|
48
50
|
*/
|
|
49
|
-
export const requiresDockerBuild = ({
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
51
|
+
export const requiresDockerBuild = (context: ComponentContext): boolean => {
|
|
52
|
+
const deployConfig = context.deploy?.config;
|
|
53
|
+
|
|
54
|
+
return (
|
|
55
|
+
isOfDeployType(
|
|
56
|
+
deployConfig,
|
|
57
|
+
"kubernetes",
|
|
58
|
+
"google-cloudrun",
|
|
59
|
+
"dockerTag",
|
|
60
|
+
) ||
|
|
61
|
+
(isOfDeployType(deployConfig, "custom") && deployConfig.requiresDocker)
|
|
62
|
+
);
|
|
63
|
+
};
|
|
54
64
|
|
|
55
65
|
// those need to be runner variables
|
|
56
66
|
const getDockerBuildRunnerVariables = () => ({
|
|
@@ -60,13 +70,25 @@ const getDockerBuildRunnerVariables = () => ({
|
|
|
60
70
|
DOCKER_BUILDKIT: "1", // see https://docs.docker.com/develop/develop-images/build_enhancements/
|
|
61
71
|
});
|
|
62
72
|
|
|
63
|
-
|
|
73
|
+
const getDockerAdditions = (build: BuildConfig) => {
|
|
74
|
+
if (!("docker" in build)) return {};
|
|
75
|
+
if (!build.docker) return {};
|
|
76
|
+
|
|
64
77
|
return {
|
|
65
78
|
DOCKERFILE_ADDITIONS:
|
|
66
|
-
|
|
79
|
+
"additionsBegin" in build.docker
|
|
80
|
+
? build.docker.additionsBegin?.join("\n")
|
|
81
|
+
: undefined,
|
|
67
82
|
DOCKERFILE_ADDITIONS_END:
|
|
68
|
-
|
|
69
|
-
|
|
83
|
+
"additionsEnd" in build.docker
|
|
84
|
+
? build.docker.additionsEnd?.join("\n")
|
|
85
|
+
: undefined,
|
|
86
|
+
};
|
|
87
|
+
};
|
|
88
|
+
export const getDockerBuildVariables = (context: ComponentContext) => {
|
|
89
|
+
return {
|
|
90
|
+
...getDockerAdditions(context.build.config),
|
|
91
|
+
APP_DIR: context.build.dir,
|
|
70
92
|
DOCKER_DIR: ".", // relative to componentdir
|
|
71
93
|
|
|
72
94
|
...getDockerImageVariables(context),
|
|
@@ -75,9 +97,7 @@ export const getDockerBuildVariables = (context: ComponentContext) => {
|
|
|
75
97
|
|
|
76
98
|
export const DOCKER_BUILD_JOB_NAME = "🔨 docker";
|
|
77
99
|
|
|
78
|
-
export const getDockerJobBaseProps = (
|
|
79
|
-
context: ComponentContext,
|
|
80
|
-
): Pick<
|
|
100
|
+
export const getDockerJobBaseProps = (): Pick<
|
|
81
101
|
CatladderJob,
|
|
82
102
|
"image" | "services" | "variables" | "runnerVariables"
|
|
83
103
|
> => {
|
|
@@ -104,7 +124,7 @@ export const createDockerBuildJobBase = (
|
|
|
104
124
|
name: DOCKER_BUILD_JOB_NAME,
|
|
105
125
|
envMode: "jobPerEnv",
|
|
106
126
|
stage: "build",
|
|
107
|
-
...getDockerJobBaseProps(
|
|
127
|
+
...getDockerJobBaseProps(),
|
|
108
128
|
script: script || [],
|
|
109
129
|
},
|
|
110
130
|
{
|
|
@@ -119,7 +139,7 @@ export const createDockerBuildJobBase = (
|
|
|
119
139
|
};
|
|
120
140
|
|
|
121
141
|
export const gitlabDockerLogin = (context: ComponentContext) =>
|
|
122
|
-
isOfDeployType(context.
|
|
142
|
+
context.deploy && isOfDeployType(context.deploy.config, "google-cloudrun")
|
|
123
143
|
? [
|
|
124
144
|
...gcloudServiceAccountLoginCommands(context),
|
|
125
145
|
`gcloud auth configure-docker ${getArtifactsRegistryHost(context)}`,
|
|
@@ -128,12 +148,36 @@ export const gitlabDockerLogin = (context: ComponentContext) =>
|
|
|
128
148
|
"docker login --username gitlab-ci-token --password $CI_JOB_TOKEN $CI_REGISTRY",
|
|
129
149
|
];
|
|
130
150
|
|
|
151
|
+
const BUILT_IN_ENSURE_DOCKERFILE_SCRIPTS = {
|
|
152
|
+
meteor: "ensureMeteorDockerfile",
|
|
153
|
+
node: "ensureNodeDockerfile",
|
|
154
|
+
nginx: "ensureNginxDockerfile",
|
|
155
|
+
custom: null,
|
|
156
|
+
} satisfies {
|
|
157
|
+
[type in BuildConfigDocker["type"]]: string | null;
|
|
158
|
+
};
|
|
159
|
+
|
|
160
|
+
export const getDockerBuildScriptWithBuiltInDockerFile = (
|
|
161
|
+
context: ComponentContext,
|
|
162
|
+
defaultType?: BuildConfigDocker["type"],
|
|
163
|
+
) => {
|
|
164
|
+
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
|
|
169
|
+
: defaultType;
|
|
170
|
+
return getDockerBuildDefaultScript(
|
|
171
|
+
context,
|
|
172
|
+
type ? BUILT_IN_ENSURE_DOCKERFILE_SCRIPTS[type] : null,
|
|
173
|
+
);
|
|
174
|
+
};
|
|
131
175
|
export const getDockerBuildDefaultScript = (
|
|
132
176
|
context: ComponentContext,
|
|
133
|
-
ensureDockerFileScript?: string,
|
|
177
|
+
ensureDockerFileScript?: string | null,
|
|
134
178
|
) =>
|
|
135
179
|
[
|
|
136
|
-
ensureDockerFileScript,
|
|
180
|
+
ensureDockerFileScript ?? undefined,
|
|
137
181
|
...collapseableSection(
|
|
138
182
|
"docker-login",
|
|
139
183
|
"Docker Login",
|
|
@@ -155,4 +199,4 @@ export const getDockerBuildDefaultScript = (
|
|
|
155
199
|
].filter(Boolean);
|
|
156
200
|
|
|
157
201
|
export const hasDockerfile = (context: ComponentContext) =>
|
|
158
|
-
existsSync(path.join(context.
|
|
202
|
+
existsSync(path.join(context.build.dir, "Dockerfile"));
|
|
@@ -4,7 +4,7 @@ import type { ComponentContext } from "../../types/context";
|
|
|
4
4
|
import type { CatladderJob } from "../../types/jobs";
|
|
5
5
|
import { ensureArray } from "../../utils";
|
|
6
6
|
import { createBuildJobs } from "../base";
|
|
7
|
-
import {
|
|
7
|
+
import { getDockerBuildScriptWithBuiltInDockerFile } from "../docker";
|
|
8
8
|
import { isOfBuildType } from "../types";
|
|
9
9
|
import { getNextCache, getNodeCache, getYarnCache } from "./cache";
|
|
10
10
|
import { NODE_RUNNER_BUILD_VARIABLES } from "./constants";
|
|
@@ -13,14 +13,14 @@ import { getDockerAppCopyAndBuildScript, getYarnInstall } from "./yarn";
|
|
|
13
13
|
export const createNodeBuildJobs = (
|
|
14
14
|
context: ComponentContext,
|
|
15
15
|
): CatladderJob[] => {
|
|
16
|
-
const buildConfig = context.
|
|
16
|
+
const buildConfig = context.build.config;
|
|
17
17
|
|
|
18
18
|
if (!isOfBuildType(buildConfig, "node", "node-static", "storybook")) {
|
|
19
19
|
throw new Error("deploy config is not node, node-static or storybook");
|
|
20
20
|
}
|
|
21
21
|
|
|
22
22
|
const defaultImage = getRunnerImage("jobs-default");
|
|
23
|
-
const yarnInstall = getYarnInstall(context.
|
|
23
|
+
const yarnInstall = getYarnInstall(context.build);
|
|
24
24
|
|
|
25
25
|
return createBuildJobs(context, {
|
|
26
26
|
appBuild:
|
|
@@ -30,7 +30,7 @@ export const createNodeBuildJobs = (
|
|
|
30
30
|
runnerVariables: NODE_RUNNER_BUILD_VARIABLES,
|
|
31
31
|
cache: [
|
|
32
32
|
...(ensureArray(buildConfig.jobCache) ?? []),
|
|
33
|
-
...getNodeCache(context.
|
|
33
|
+
...getNodeCache(context.build),
|
|
34
34
|
...getNextCache(context),
|
|
35
35
|
],
|
|
36
36
|
script: [
|
|
@@ -39,9 +39,9 @@ export const createNodeBuildJobs = (
|
|
|
39
39
|
],
|
|
40
40
|
artifacts: {
|
|
41
41
|
paths: [
|
|
42
|
-
context.
|
|
42
|
+
context.build.dir,
|
|
43
43
|
// also copy workspace dependencies in monorepo if packages are shared and they create build artifacts
|
|
44
|
-
...(context.
|
|
44
|
+
...(context.build.packageManagerInfo
|
|
45
45
|
?.currentWorkspaceDependencies ?? []),
|
|
46
46
|
].flatMap((dir) => [
|
|
47
47
|
join(dir, "__build_info.json"),
|
|
@@ -59,20 +59,20 @@ export const createNodeBuildJobs = (
|
|
|
59
59
|
: undefined,
|
|
60
60
|
|
|
61
61
|
dockerBuild: {
|
|
62
|
-
script:
|
|
62
|
+
script: getDockerBuildScriptWithBuiltInDockerFile(
|
|
63
63
|
context,
|
|
64
64
|
buildConfig.type === "node-static" || buildConfig.type === "storybook"
|
|
65
|
-
? "
|
|
66
|
-
: "
|
|
65
|
+
? "nginx"
|
|
66
|
+
: "node",
|
|
67
67
|
),
|
|
68
|
-
cache: [...getYarnCache(context.
|
|
68
|
+
cache: [...getYarnCache(context.build, "pull")],
|
|
69
69
|
variables: {
|
|
70
70
|
// only required for non static
|
|
71
71
|
DOCKER_COPY_AND_INSTALL_APP: getDockerAppCopyAndBuildScript(
|
|
72
|
-
context.
|
|
72
|
+
context.build,
|
|
73
73
|
),
|
|
74
74
|
DOCKER_COPY_WORKSPACE_FILES:
|
|
75
|
-
context.
|
|
75
|
+
context.build.packageManagerInfo?.pathsToCopyInDocker
|
|
76
76
|
.map((dir) => `COPY --chown=node:node ${dir} /app/${dir}`)
|
|
77
77
|
?.join("\n"),
|
|
78
78
|
},
|
package/src/build/node/cache.ts
CHANGED
|
@@ -68,6 +68,6 @@ export const getNextCache = (context: ComponentContext): GitlabJobCache[] => [
|
|
|
68
68
|
{
|
|
69
69
|
key: context.componentName + "-next-cache",
|
|
70
70
|
policy: "pull-push",
|
|
71
|
-
paths: [context.
|
|
71
|
+
paths: [context.build.dir + "/.next/cache/"],
|
|
72
72
|
},
|
|
73
73
|
];
|
package/src/build/node/meteor.ts
CHANGED
|
@@ -6,7 +6,7 @@ import type { ComponentContext } from "../../types/context";
|
|
|
6
6
|
import type { CatladderJob } from "../../types/jobs";
|
|
7
7
|
|
|
8
8
|
import { createBuildJobs } from "../base";
|
|
9
|
-
import {
|
|
9
|
+
import { getDockerBuildScriptWithBuiltInDockerFile } from "../docker";
|
|
10
10
|
import { isOfBuildType } from "../types";
|
|
11
11
|
import { getNodeCache } from "./cache";
|
|
12
12
|
import { getYarnInstall } from "./yarn";
|
|
@@ -16,35 +16,29 @@ const getMeteorCache = (context: ComponentContext): GitlabJobCache[] => [
|
|
|
16
16
|
key: context.componentName + "meteor-build-cache",
|
|
17
17
|
policy: "pull-push",
|
|
18
18
|
paths: [
|
|
19
|
-
join(
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
),
|
|
23
|
-
join(context.componentConfig.dir, ".meteor/local/plugin-cache"),
|
|
24
|
-
join(context.componentConfig.dir, ".meteor/local/isopacks"),
|
|
25
|
-
join(context.componentConfig.dir, ".meteor/local/bundler-cache/scanner"),
|
|
19
|
+
join(context.build.dir, ".meteor/local/resolver-result-cache.json"),
|
|
20
|
+
join(context.build.dir, ".meteor/local/plugin-cache"),
|
|
21
|
+
join(context.build.dir, ".meteor/local/isopacks"),
|
|
22
|
+
join(context.build.dir, ".meteor/local/bundler-cache/scanner"),
|
|
26
23
|
],
|
|
27
24
|
},
|
|
28
25
|
];
|
|
29
26
|
export const createMeteorBuildJobs = (
|
|
30
27
|
context: ComponentContext,
|
|
31
28
|
): CatladderJob[] => {
|
|
32
|
-
const buildConfig = context.
|
|
29
|
+
const buildConfig = context.build.config;
|
|
33
30
|
|
|
34
31
|
if (!isOfBuildType(buildConfig, "meteor")) {
|
|
35
32
|
throw new Error("deploy config is not meteor");
|
|
36
33
|
}
|
|
37
34
|
|
|
38
|
-
const yarnInstall = getYarnInstall(context.
|
|
35
|
+
const yarnInstall = getYarnInstall(context.build);
|
|
39
36
|
|
|
40
37
|
return createBuildJobs(context, {
|
|
41
38
|
appBuild:
|
|
42
39
|
buildConfig.buildCommand !== null
|
|
43
40
|
? {
|
|
44
|
-
cache: [
|
|
45
|
-
...getNodeCache(context.buildContext),
|
|
46
|
-
...getMeteorCache(context),
|
|
47
|
-
],
|
|
41
|
+
cache: [...getNodeCache(context.build), ...getMeteorCache(context)],
|
|
48
42
|
image: getRunnerImage("jobs-meteor"),
|
|
49
43
|
variables: {
|
|
50
44
|
METEOR_DISABLE_OPTIMISTIC_CACHING: "1", // see https://forums.meteor.com/t/veeery-long-building-time-inside-docker-container/58673/17?u=macrozone
|
|
@@ -62,14 +56,14 @@ export const createMeteorBuildJobs = (
|
|
|
62
56
|
],
|
|
63
57
|
artifacts: {
|
|
64
58
|
paths: [
|
|
65
|
-
context.
|
|
66
|
-
context.
|
|
59
|
+
context.build.dir + "/__build_info.json",
|
|
60
|
+
context.build.dir + "/dist",
|
|
67
61
|
],
|
|
68
62
|
},
|
|
69
63
|
}
|
|
70
64
|
: undefined,
|
|
71
65
|
dockerBuild: {
|
|
72
|
-
script:
|
|
66
|
+
script: getDockerBuildScriptWithBuiltInDockerFile(context, "meteor"),
|
|
73
67
|
variables: {
|
|
74
68
|
METEOR_INSTALL_SCRIPTS: buildConfig.installScripts ? "true" : "",
|
|
75
69
|
},
|
|
@@ -16,12 +16,12 @@ export const createNodeTestJobs = (
|
|
|
16
16
|
return [];
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
-
const buildConfig = context.
|
|
19
|
+
const buildConfig = context.build.config;
|
|
20
20
|
|
|
21
21
|
const defaultImage = getRunnerImage("jobs-default");
|
|
22
22
|
const base: Omit<CatladderJob, "script" | "name"> = {
|
|
23
23
|
variables: {
|
|
24
|
-
APP_PATH: context.
|
|
24
|
+
APP_PATH: context.build.dir,
|
|
25
25
|
...context.environment.jobOnlyVars.build.envVars,
|
|
26
26
|
...(buildConfig.extraVars ?? {}),
|
|
27
27
|
},
|
|
@@ -30,7 +30,7 @@ export const createNodeTestJobs = (
|
|
|
30
30
|
needs: [],
|
|
31
31
|
envMode: "none",
|
|
32
32
|
};
|
|
33
|
-
const yarnInstall = getYarnInstall(context.
|
|
33
|
+
const yarnInstall = getYarnInstall(context.build);
|
|
34
34
|
const auditJob: CatladderJob | null =
|
|
35
35
|
buildConfig.audit !== false
|
|
36
36
|
? {
|
|
@@ -39,16 +39,16 @@ export const createNodeTestJobs = (
|
|
|
39
39
|
image: buildConfig.audit?.jobImage ?? defaultImage,
|
|
40
40
|
cache: undefined, // audit does not need yarn install and no cache
|
|
41
41
|
script: [
|
|
42
|
-
`cd ${context.
|
|
42
|
+
`cd ${context.build.dir}`,
|
|
43
43
|
...(ensureArray(buildConfig.audit?.command) ?? [
|
|
44
|
-
context.
|
|
44
|
+
context.build.packageManagerInfo?.isClassic
|
|
45
45
|
? "yarn audit"
|
|
46
46
|
: "yarn npm audit --environment production", // yarn 2
|
|
47
47
|
]),
|
|
48
48
|
],
|
|
49
49
|
allow_failure: true,
|
|
50
50
|
...createArtifactsConfig(
|
|
51
|
-
context.
|
|
51
|
+
context.build.dir,
|
|
52
52
|
buildConfig.audit?.artifactsReports,
|
|
53
53
|
buildConfig.audit?.artifacts,
|
|
54
54
|
),
|
|
@@ -61,15 +61,15 @@ export const createNodeTestJobs = (
|
|
|
61
61
|
name: "👮 lint",
|
|
62
62
|
...base,
|
|
63
63
|
image: buildConfig.lint?.jobImage ?? defaultImage,
|
|
64
|
-
cache: getNodeCache(context.
|
|
64
|
+
cache: getNodeCache(context.build),
|
|
65
65
|
script: [
|
|
66
|
-
...ensureNodeVersion(context.
|
|
67
|
-
`cd ${context.
|
|
66
|
+
...ensureNodeVersion(context.build),
|
|
67
|
+
`cd ${context.build.dir}`,
|
|
68
68
|
...yarnInstall,
|
|
69
69
|
...(ensureArray(buildConfig.lint?.command) ?? ["yarn lint"]),
|
|
70
70
|
],
|
|
71
71
|
...createArtifactsConfig(
|
|
72
|
-
context.
|
|
72
|
+
context.build.dir,
|
|
73
73
|
buildConfig.lint?.artifactsReports,
|
|
74
74
|
buildConfig.lint?.artifacts,
|
|
75
75
|
),
|
|
@@ -83,15 +83,15 @@ export const createNodeTestJobs = (
|
|
|
83
83
|
...base,
|
|
84
84
|
image:
|
|
85
85
|
buildConfig.test?.jobImage ?? getRunnerImage("jobs-testing-chrome"),
|
|
86
|
-
cache: getNodeCache(context.
|
|
86
|
+
cache: getNodeCache(context.build),
|
|
87
87
|
script: [
|
|
88
|
-
...ensureNodeVersion(context.
|
|
89
|
-
`cd ${context.
|
|
88
|
+
...ensureNodeVersion(context.build),
|
|
89
|
+
`cd ${context.build.dir}`,
|
|
90
90
|
...yarnInstall,
|
|
91
91
|
...(ensureArray(buildConfig.test?.command) ?? ["yarn test"]),
|
|
92
92
|
],
|
|
93
93
|
...createArtifactsConfig(
|
|
94
|
-
context.
|
|
94
|
+
context.build.dir,
|
|
95
95
|
buildConfig.test?.artifactsReports,
|
|
96
96
|
buildConfig.test?.artifacts,
|
|
97
97
|
),
|
package/src/build/rails/build.ts
CHANGED
|
@@ -11,7 +11,7 @@ import { isOfBuildType } from "../types";
|
|
|
11
11
|
export const createRailsBuildJobs = (
|
|
12
12
|
context: ComponentContext,
|
|
13
13
|
): CatladderJob[] => {
|
|
14
|
-
const buildConfig = context.
|
|
14
|
+
const buildConfig = context.build.config;
|
|
15
15
|
if (!isOfBuildType(buildConfig, "rails")) {
|
|
16
16
|
// should not happen
|
|
17
17
|
throw new Error("build type is not rails");
|
|
@@ -37,12 +37,12 @@ export const createRailsBuildJobs = (
|
|
|
37
37
|
dockerBuild: {
|
|
38
38
|
variables: {
|
|
39
39
|
...context.environment.jobOnlyVars.build.envVars,
|
|
40
|
-
...context.
|
|
40
|
+
...context.build.config.extraVars,
|
|
41
41
|
},
|
|
42
42
|
// custom script
|
|
43
43
|
script: [
|
|
44
44
|
...gitlabDockerLogin(context),
|
|
45
|
-
`cd ${context.
|
|
45
|
+
`cd ${context.build.dir}`,
|
|
46
46
|
`docker pull $DOCKER_CACHE_IMAGE || true`,
|
|
47
47
|
`wget --output-document=- https://github.com/buildpacks/pack/releases/download/v${cnbConf?.packVersion}/pack-v${cnbConf?.packVersion}-linux.tgz | tar -zx --directory /usr/local/bin pack`,
|
|
48
48
|
`chmod +x /usr/local/bin/pack`,
|