@catladder/pipeline 1.10.2 โ 1.13.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/constants.js +1 -1
- package/dist/build/base/createBuildJob.d.ts +4 -2
- package/dist/build/base/createBuildJob.js +13 -18
- package/dist/build/docker.d.ts +6 -3
- package/dist/build/docker.js +24 -9
- package/dist/build/index.d.ts +2 -2
- package/dist/build/node/buildJob.d.ts +2 -2
- package/dist/build/node/buildJob.js +26 -13
- package/dist/build/node/cache.d.ts +3 -1
- package/dist/build/node/cache.js +33 -5
- package/dist/build/node/constants.js +2 -2
- package/dist/build/node/index.d.ts +4 -4
- package/dist/build/node/meteor.d.ts +2 -2
- package/dist/build/node/meteor.js +4 -23
- package/dist/build/node/testJob.d.ts +2 -2
- package/dist/build/node/testJob.js +20 -29
- package/dist/build/node/yarn.d.ts +4 -0
- package/dist/build/node/yarn.js +10 -3
- package/dist/build/tests/storybook.test.js +10 -23
- package/dist/build/types.d.ts +6 -0
- package/dist/catladder-gitlab.js +33 -2
- package/dist/constants.js +1 -1
- package/dist/context/index.d.ts +2 -2
- package/dist/context/index.js +2 -2
- package/dist/deploy/base.d.ts +3 -4
- package/dist/deploy/base.js +27 -33
- package/dist/deploy/index.d.ts +2 -2
- package/dist/deploy/kubernetes/deployJob.d.ts +2 -2
- package/dist/deploy/kubernetes/deployJob.js +32 -38
- package/dist/pipeline/createChildPipeline.d.ts +2 -11
- package/dist/pipeline/createChildPipeline.js +24 -18
- package/dist/pipeline/createChildPipeline.test.js +3 -14
- package/dist/pipeline/createJobs.d.ts +2 -2
- package/dist/pipeline/createJobs.js +29 -23
- package/dist/pipeline/gitlab/makeGitlabJob.d.ts +8 -0
- package/dist/pipeline/gitlab/makeGitlabJob.js +45 -0
- package/dist/pipeline/packageManager.d.ts +2 -0
- package/dist/pipeline/{yarnInfo.js โ packageManager.js} +69 -8
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/types/context.d.ts +15 -6
- package/dist/types/gitlab-types.d.ts +10 -22
- package/dist/types/gitlab-types.js +1 -3
- package/dist/types/index.d.ts +2 -1
- package/dist/types/index.js +3 -1
- package/dist/types/jobs.d.ts +75 -0
- package/dist/types/jobs.js +5 -0
- package/dist/types/pipeline.d.ts +4 -0
- package/dist/types/pipeline.js +3 -0
- package/package.json +1 -1
- package/src/build/base/constants.ts +1 -1
- package/src/build/base/createBuildJob.ts +29 -31
- package/src/build/docker.ts +50 -45
- package/src/build/index.ts +3 -2
- package/src/build/node/buildJob.ts +35 -25
- package/src/build/node/cache.ts +30 -5
- package/src/build/node/constants.ts +2 -2
- package/src/build/node/index.ts +4 -4
- package/src/build/node/meteor.ts +10 -18
- package/src/build/node/testJob.ts +31 -40
- package/src/build/node/yarn.ts +20 -3
- package/src/build/tests/storybook.test.ts +4 -2
- package/src/build/types.ts +6 -0
- package/src/catladder-gitlab.ts +9 -5
- package/src/context/index.ts +8 -4
- package/src/deploy/base.ts +40 -45
- package/src/deploy/index.ts +2 -2
- package/src/deploy/kubernetes/deployJob.ts +43 -48
- package/src/pipeline/createChildPipeline.test.ts +2 -1
- package/src/pipeline/createChildPipeline.ts +23 -21
- package/src/pipeline/createJobs.ts +50 -41
- package/src/pipeline/gitlab/makeGitlabJob.ts +16 -0
- package/src/pipeline/packageManager.ts +99 -0
- package/src/types/context.ts +14 -3
- package/src/types/gitlab-types.ts +10 -30
- package/src/types/index.ts +1 -0
- package/src/types/jobs.ts +88 -0
- package/src/types/pipeline.ts +11 -0
- package/dist/pipeline/yarnInfo.d.ts +0 -2
- package/src/pipeline/yarnInfo.ts +0 -54
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { merge } from "lodash";
|
|
2
|
-
import { Context, getRunnerImage
|
|
3
|
-
import {
|
|
2
|
+
import { Context, getRunnerImage } from "../..";
|
|
3
|
+
import { CatladderJob } from "../../types/jobs";
|
|
4
4
|
import { ensureArray } from "../../utils";
|
|
5
5
|
import {
|
|
6
6
|
APP_BUILD_JOB_NAME,
|
|
@@ -10,34 +10,32 @@ import { getBuildInfo } from "./getBuildInfo";
|
|
|
10
10
|
|
|
11
11
|
export const createBuildJob = (
|
|
12
12
|
context: Context,
|
|
13
|
-
{ script, ...def }: Partial<
|
|
14
|
-
):
|
|
15
|
-
return
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
},
|
|
28
|
-
retry: BASE_RETRY,
|
|
29
|
-
interruptible: true,
|
|
30
|
-
stage: "build",
|
|
31
|
-
script: [
|
|
32
|
-
...getBuildInfo(context),
|
|
33
|
-
`cd ${context.componentConfig.dir}`,
|
|
34
|
-
...(ensureArray(script) ?? []),
|
|
35
|
-
],
|
|
36
|
-
artifacts: {
|
|
37
|
-
paths: [context.componentConfig.dir + "/__build_info.json"],
|
|
38
|
-
},
|
|
13
|
+
{ script, variables, ...def }: Partial<CatladderJob>
|
|
14
|
+
): CatladderJob => {
|
|
15
|
+
return merge(
|
|
16
|
+
{
|
|
17
|
+
name: APP_BUILD_JOB_NAME,
|
|
18
|
+
envMode: "jobPerEnv",
|
|
19
|
+
stage: "build",
|
|
20
|
+
image: getRunnerImage("jobs-default"),
|
|
21
|
+
needs: [],
|
|
22
|
+
cache: [],
|
|
23
|
+
variables: {
|
|
24
|
+
...RUNNER_BUILD_RESOURCE_VARIABLES,
|
|
25
|
+
...(variables ?? {}),
|
|
26
|
+
...context.environment.envVars,
|
|
27
|
+
...(context.componentConfig.build.extraVars ?? {}),
|
|
39
28
|
},
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
29
|
+
|
|
30
|
+
script: [
|
|
31
|
+
...getBuildInfo(context),
|
|
32
|
+
`cd ${context.componentConfig.dir}`,
|
|
33
|
+
...(ensureArray(script) ?? []),
|
|
34
|
+
],
|
|
35
|
+
artifacts: {
|
|
36
|
+
paths: [context.componentConfig.dir + "/__build_info.json"],
|
|
37
|
+
},
|
|
38
|
+
},
|
|
39
|
+
def
|
|
40
|
+
);
|
|
43
41
|
};
|
package/src/build/docker.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
import { merge } from "lodash";
|
|
1
2
|
import { getRunnerImage } from "../runner";
|
|
2
|
-
import {
|
|
3
|
+
import { Context } from "../types";
|
|
4
|
+
import { CatladderJob } from "../types/jobs";
|
|
3
5
|
|
|
4
6
|
const DOCKER_RUNNER_BUILD_VARIABLES = {
|
|
5
7
|
KUBERNETES_CPU_REQUEST: "0.5",
|
|
@@ -9,53 +11,56 @@ const DOCKER_RUNNER_BUILD_VARIABLES = {
|
|
|
9
11
|
};
|
|
10
12
|
|
|
11
13
|
export const DOCKER_BUILD_JOB_NAME = "๐จ docker";
|
|
14
|
+
|
|
12
15
|
export const createDockerBuildJob = (
|
|
13
16
|
context: Context,
|
|
14
|
-
{ script }:
|
|
15
|
-
):
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
name: "docker:20-dind", // see see https://gitlab.com/gitlab-org/gitlab-runner/-/issues/27300#note_466755332
|
|
23
|
-
command: ["--tls=false"],
|
|
24
|
-
},
|
|
25
|
-
],
|
|
26
|
-
variables: {
|
|
27
|
-
...DOCKER_RUNNER_BUILD_VARIABLES,
|
|
28
|
-
DOCKER_BUILDKIT: "1", // see https://docs.docker.com/develop/develop-images/build_enhancements/
|
|
29
|
-
DOCKERFILE_ADDITIONS:
|
|
30
|
-
context.componentConfig.build.docker?.additionsBegin?.join("\n"),
|
|
31
|
-
DOCKERFILE_ADDITIONS_END:
|
|
32
|
-
context.componentConfig.build.docker?.additionsEnd?.join("\n"),
|
|
33
|
-
APP_DIR: context.componentConfig.dir,
|
|
34
|
-
DOCKER_HOST: "tcp://0.0.0.0:2375",
|
|
35
|
-
DOCKER_TLS_CERTDIR: "",
|
|
36
|
-
DOCKER_DIR: ".", // relative to componentdir
|
|
37
|
-
IMAGE_TAG: "$CI_COMMIT_SHA",
|
|
38
|
-
DOCKER_DRIVER: "overlay2",
|
|
39
|
-
IMAGE_NAME:
|
|
40
|
-
"$CI_REGISTRY_IMAGE/" +
|
|
41
|
-
context.environment.shortName +
|
|
42
|
-
"/" +
|
|
43
|
-
context.componentName,
|
|
17
|
+
{ script, variables, ...def }: Partial<CatladderJob>
|
|
18
|
+
): CatladderJob => {
|
|
19
|
+
return merge(
|
|
20
|
+
{
|
|
21
|
+
name: DOCKER_BUILD_JOB_NAME,
|
|
22
|
+
envMode: "jobPerEnv",
|
|
23
|
+
stage: "build",
|
|
24
|
+
image: getRunnerImage("docker-build"),
|
|
44
25
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
26
|
+
services: [
|
|
27
|
+
{
|
|
28
|
+
name: "docker:20-dind", // see see https://gitlab.com/gitlab-org/gitlab-runner/-/issues/27300#note_466755332
|
|
29
|
+
command: ["--tls=false"],
|
|
30
|
+
},
|
|
31
|
+
],
|
|
32
|
+
variables: {
|
|
33
|
+
...DOCKER_RUNNER_BUILD_VARIABLES,
|
|
34
|
+
DOCKER_BUILDKIT: "1", // see https://docs.docker.com/develop/develop-images/build_enhancements/
|
|
35
|
+
DOCKERFILE_ADDITIONS:
|
|
36
|
+
context.componentConfig.build.docker?.additionsBegin?.join("\n"),
|
|
37
|
+
DOCKERFILE_ADDITIONS_END:
|
|
38
|
+
context.componentConfig.build.docker?.additionsEnd?.join("\n"),
|
|
39
|
+
APP_DIR: context.componentConfig.dir,
|
|
40
|
+
DOCKER_HOST: "tcp://0.0.0.0:2375",
|
|
41
|
+
DOCKER_TLS_CERTDIR: "",
|
|
42
|
+
DOCKER_DIR: ".", // relative to componentdir
|
|
43
|
+
IMAGE_TAG: "$CI_COMMIT_SHA",
|
|
44
|
+
DOCKER_DRIVER: "overlay2",
|
|
48
45
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
46
|
+
IMAGE_NAME:
|
|
47
|
+
"$CI_REGISTRY_IMAGE/" +
|
|
48
|
+
context.environment.shortName +
|
|
49
|
+
"/" +
|
|
50
|
+
context.componentName,
|
|
54
51
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
52
|
+
CACHE_IMAGE: "$CI_REGISTRY_IMAGE/caches/" + context.componentName,
|
|
53
|
+
...(variables ?? {}),
|
|
54
|
+
},
|
|
55
|
+
script: [
|
|
56
|
+
...(script || []),
|
|
57
|
+
"docker login --username gitlab-ci-token --password $CI_JOB_TOKEN $CI_REGISTRY",
|
|
58
|
+
"docker build --network host --cache-from $CACHE_IMAGE --tag $IMAGE_NAME:$IMAGE_TAG -f $APP_DIR/Dockerfile . --build-arg BUILDKIT_INLINE_CACHE=1", //BUILDKIT_INLINE_CACHE, see https://testdriven.io/blog/faster-ci-builds-with-docker-cache/
|
|
59
|
+
"docker push $IMAGE_NAME:$IMAGE_TAG",
|
|
60
|
+
"docker tag $IMAGE_NAME:$IMAGE_TAG $CACHE_IMAGE",
|
|
61
|
+
"docker push $CACHE_IMAGE",
|
|
62
|
+
],
|
|
63
|
+
},
|
|
64
|
+
def
|
|
65
|
+
);
|
|
61
66
|
};
|
package/src/build/index.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Context } from "../types/context";
|
|
2
|
-
|
|
2
|
+
|
|
3
|
+
import { CatladderJob } from "../types/jobs";
|
|
3
4
|
import { createNodeJobs, createStorybookJobs, createMeteorJobs } from "./node";
|
|
4
5
|
|
|
5
6
|
import { BuildConfig } from "./types";
|
|
@@ -8,7 +9,7 @@ export * from "./node";
|
|
|
8
9
|
|
|
9
10
|
export type BuildTypes = {
|
|
10
11
|
[type in BuildConfig["type"]]: {
|
|
11
|
-
jobs: (context: Context) =>
|
|
12
|
+
jobs: (context: Context) => CatladderJob[];
|
|
12
13
|
defaults: () => Partial<Extract<BuildConfig, { type: type }>>;
|
|
13
14
|
};
|
|
14
15
|
};
|
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
import { Context } from "../../types/context";
|
|
2
|
-
import { GitlabJob, GitlabJobs } from "../../types/gitlab-types";
|
|
3
2
|
import { ensureArray } from "../../utils";
|
|
4
3
|
import { APP_BUILD_JOB_NAME } from "../base/constants";
|
|
5
4
|
import { createBuildJob } from "../base/createBuildJob";
|
|
6
|
-
import { createDockerBuildJob
|
|
5
|
+
import { createDockerBuildJob } from "../docker";
|
|
6
|
+
import { join } from "path";
|
|
7
7
|
import { isOfBuildType } from "../types";
|
|
8
|
-
import { getNextCache, getNodeCache } from "./cache";
|
|
8
|
+
import { getNextCache, getNodeCache, getYarnCache } from "./cache";
|
|
9
9
|
import { NODE_RUNNER_BUILD_VARIABLES } from "./constants";
|
|
10
|
-
import { getYarnInstall } from "./yarn";
|
|
10
|
+
import { getYarnInstall, getYarnInstallCommand } from "./yarn";
|
|
11
|
+
import { CatladderJob } from "../../types/jobs";
|
|
11
12
|
|
|
12
|
-
export const createNodeBuildJobs = (context: Context):
|
|
13
|
+
export const createNodeBuildJobs = (context: Context): CatladderJob[] => {
|
|
13
14
|
const buildConfig = context.componentConfig.build;
|
|
14
15
|
|
|
15
16
|
if (!isOfBuildType(buildConfig, "node", "node-static", "storybook")) {
|
|
@@ -17,14 +18,11 @@ export const createNodeBuildJobs = (context: Context): GitlabJobs => {
|
|
|
17
18
|
}
|
|
18
19
|
|
|
19
20
|
const yarnInstall = getYarnInstall(context);
|
|
20
|
-
const appBuildJob:
|
|
21
|
+
const appBuildJob: CatladderJob | null =
|
|
21
22
|
buildConfig.buildCommand !== null
|
|
22
23
|
? createBuildJob(context, {
|
|
23
24
|
variables: {
|
|
24
25
|
...NODE_RUNNER_BUILD_VARIABLES,
|
|
25
|
-
// TODO:duplicate with `createBuildJob`, but problem is that it will override variables here
|
|
26
|
-
...context.environment.envVars,
|
|
27
|
-
...(context.componentConfig.build.extraVars ?? {}),
|
|
28
26
|
},
|
|
29
27
|
cache: [...getNodeCache(context), ...getNextCache(context)],
|
|
30
28
|
script: [
|
|
@@ -33,29 +31,41 @@ export const createNodeBuildJobs = (context: Context): GitlabJobs => {
|
|
|
33
31
|
],
|
|
34
32
|
artifacts: {
|
|
35
33
|
paths: [
|
|
36
|
-
context.componentConfig.dir
|
|
37
|
-
context.componentConfig.dir
|
|
38
|
-
context.componentConfig.dir
|
|
34
|
+
join(context.componentConfig.dir, "__build_info.json"),
|
|
35
|
+
join(context.componentConfig.dir, "dist"),
|
|
36
|
+
join(context.componentConfig.dir, ".next"),
|
|
37
|
+
...(buildConfig.artifactsPaths?.map((path) =>
|
|
38
|
+
join(context.componentConfig.dir, path)
|
|
39
|
+
) ?? []),
|
|
39
40
|
],
|
|
40
41
|
},
|
|
41
42
|
})
|
|
42
43
|
: null;
|
|
43
44
|
return [
|
|
44
45
|
...(appBuildJob ? [appBuildJob] : []),
|
|
45
|
-
{
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
46
|
+
createDockerBuildJob(context, {
|
|
47
|
+
script: [
|
|
48
|
+
buildConfig.type === "node-static" || buildConfig.type === "storybook"
|
|
49
|
+
? "ensureNginxDockerfile"
|
|
50
|
+
: "ensureNodeDockerfile",
|
|
51
|
+
],
|
|
52
|
+
cache: [...getYarnCache(context, "pull")],
|
|
53
|
+
variables: {
|
|
54
|
+
// only required for non static
|
|
55
|
+
YARN_INSTALL: getYarnInstallCommand(context, {
|
|
56
|
+
prodOnly: true,
|
|
56
57
|
}),
|
|
57
|
-
|
|
58
|
+
YARN_INSTALL_WITHOUT_SCRIPTS: getYarnInstallCommand(context, {
|
|
59
|
+
prodOnly: true,
|
|
60
|
+
noScripts: true,
|
|
61
|
+
}),
|
|
62
|
+
DOCKER_COPY_WORKSPACE_FILES:
|
|
63
|
+
context.packageManagerInfo?.pathsToCopyInDocker
|
|
64
|
+
.map((dir) => `COPY --chown=node:node ${dir} /app/${dir}`)
|
|
65
|
+
?.join("\n"),
|
|
58
66
|
},
|
|
59
|
-
|
|
67
|
+
|
|
68
|
+
needs: appBuildJob ? [APP_BUILD_JOB_NAME] : [],
|
|
69
|
+
}),
|
|
60
70
|
];
|
|
61
71
|
};
|
package/src/build/node/cache.ts
CHANGED
|
@@ -2,8 +2,25 @@ import { join } from "path";
|
|
|
2
2
|
import { Context } from "../../types/context";
|
|
3
3
|
import { GitlabJobCache } from "../../types/gitlab-types";
|
|
4
4
|
|
|
5
|
-
export const
|
|
6
|
-
|
|
5
|
+
export const getYarnCache = (
|
|
6
|
+
context: Context,
|
|
7
|
+
policy = "pull-push"
|
|
8
|
+
): GitlabJobCache[] => {
|
|
9
|
+
return [
|
|
10
|
+
{
|
|
11
|
+
key: "yarn",
|
|
12
|
+
policy,
|
|
13
|
+
paths: [".yarn"],
|
|
14
|
+
},
|
|
15
|
+
];
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export const getNodeModulesCache = (
|
|
19
|
+
context: Context,
|
|
20
|
+
policy = "pull-push"
|
|
21
|
+
): GitlabJobCache[] => {
|
|
22
|
+
const componentIsInWorkspace =
|
|
23
|
+
context.packageManagerInfo?.componentIsInWorkspace;
|
|
7
24
|
|
|
8
25
|
return [
|
|
9
26
|
{
|
|
@@ -11,13 +28,12 @@ export const getNodeCache = (context: Context): GitlabJobCache[] => {
|
|
|
11
28
|
key: componentIsInWorkspace
|
|
12
29
|
? "node-modules-workspace"
|
|
13
30
|
: context.componentConfig.dir + "-node-modules", // we use the dirname, not the component name, because in certain cases we have two apps in the same directory and want to share the cache, e.g. when having storybook in the same package.json
|
|
14
|
-
policy
|
|
31
|
+
policy,
|
|
15
32
|
paths: [
|
|
16
|
-
".yarn",
|
|
17
33
|
...(componentIsInWorkspace
|
|
18
34
|
? [
|
|
19
35
|
"node_modules",
|
|
20
|
-
...(context.
|
|
36
|
+
...(context.packageManagerInfo?.workspaces.map((w) =>
|
|
21
37
|
join(w.location, "node_modules")
|
|
22
38
|
) ?? []),
|
|
23
39
|
]
|
|
@@ -26,6 +42,15 @@ export const getNodeCache = (context: Context): GitlabJobCache[] => {
|
|
|
26
42
|
},
|
|
27
43
|
];
|
|
28
44
|
};
|
|
45
|
+
export const getNodeCache = (
|
|
46
|
+
context: Context,
|
|
47
|
+
policy = "pull-push"
|
|
48
|
+
): GitlabJobCache[] => {
|
|
49
|
+
return [
|
|
50
|
+
...getYarnCache(context, policy),
|
|
51
|
+
...getNodeModulesCache(context, policy),
|
|
52
|
+
];
|
|
53
|
+
};
|
|
29
54
|
|
|
30
55
|
export const getNextCache = (context: Context): GitlabJobCache[] => [
|
|
31
56
|
{
|
package/src/build/node/index.ts
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
import type { Context } from "../../types/context";
|
|
2
|
-
import
|
|
2
|
+
import { CatladderJob } from "../../types/jobs";
|
|
3
3
|
import { createNodeBuildJobs } from "./buildJob";
|
|
4
4
|
import { createMeteorBuildJobs } from "./meteor";
|
|
5
5
|
import { createNodeTestJobs } from "./testJob";
|
|
6
6
|
|
|
7
|
-
export const createNodeJobs = (context: Context):
|
|
7
|
+
export const createNodeJobs = (context: Context): CatladderJob[] => {
|
|
8
8
|
return [...createNodeTestJobs(context), ...createNodeBuildJobs(context)];
|
|
9
9
|
};
|
|
10
10
|
|
|
11
|
-
export const createStorybookJobs = (context: Context):
|
|
11
|
+
export const createStorybookJobs = (context: Context): CatladderJob[] => {
|
|
12
12
|
return [...createNodeBuildJobs(context)];
|
|
13
13
|
};
|
|
14
14
|
|
|
15
|
-
export const createMeteorJobs = (context: Context):
|
|
15
|
+
export const createMeteorJobs = (context: Context): CatladderJob[] => {
|
|
16
16
|
return [...createNodeTestJobs(context), ...createMeteorBuildJobs(context)];
|
|
17
17
|
};
|
package/src/build/node/meteor.ts
CHANGED
|
@@ -1,15 +1,13 @@
|
|
|
1
1
|
import { join } from "path";
|
|
2
2
|
import { getRunnerImage } from "../../runner";
|
|
3
|
+
import { GitlabJobCache } from "../../types";
|
|
3
4
|
import type { Context } from "../../types/context";
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
GitlabJobCache,
|
|
7
|
-
GitlabJobs,
|
|
8
|
-
} from "../../types/gitlab-types";
|
|
5
|
+
|
|
6
|
+
import { CatladderJob } from "../../types/jobs";
|
|
9
7
|
|
|
10
8
|
import { APP_BUILD_JOB_NAME } from "../base/constants";
|
|
11
9
|
import { createBuildJob } from "../base/createBuildJob";
|
|
12
|
-
import { createDockerBuildJob
|
|
10
|
+
import { createDockerBuildJob } from "../docker";
|
|
13
11
|
import { isOfBuildType } from "../types";
|
|
14
12
|
import { getNodeCache } from "./cache";
|
|
15
13
|
import { getYarnInstall } from "./yarn";
|
|
@@ -29,7 +27,7 @@ const getMeteorCache = (context: Context): GitlabJobCache[] => [
|
|
|
29
27
|
],
|
|
30
28
|
},
|
|
31
29
|
];
|
|
32
|
-
export const createMeteorBuildJobs = (context: Context):
|
|
30
|
+
export const createMeteorBuildJobs = (context: Context): CatladderJob[] => {
|
|
33
31
|
const buildConfig = context.componentConfig.build;
|
|
34
32
|
|
|
35
33
|
if (!isOfBuildType(buildConfig, "meteor")) {
|
|
@@ -37,7 +35,7 @@ export const createMeteorBuildJobs = (context: Context): GitlabJobs => {
|
|
|
37
35
|
}
|
|
38
36
|
|
|
39
37
|
const yarnInstall = getYarnInstall(context);
|
|
40
|
-
const appBuildJob:
|
|
38
|
+
const appBuildJob: CatladderJob | null =
|
|
41
39
|
buildConfig.buildCommand !== null
|
|
42
40
|
? createBuildJob(context, {
|
|
43
41
|
cache: [...getNodeCache(context), ...getMeteorCache(context)],
|
|
@@ -63,15 +61,9 @@ export const createMeteorBuildJobs = (context: Context): GitlabJobs => {
|
|
|
63
61
|
: null;
|
|
64
62
|
return [
|
|
65
63
|
...(appBuildJob ? [appBuildJob] : []),
|
|
66
|
-
{
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
...createDockerBuildJob(context, {
|
|
71
|
-
script: ["ensureMeteorDockerfile"],
|
|
72
|
-
}),
|
|
73
|
-
needs: appBuildJob ? [APP_BUILD_JOB_NAME] : [],
|
|
74
|
-
},
|
|
75
|
-
},
|
|
64
|
+
createDockerBuildJob(context, {
|
|
65
|
+
script: ["ensureMeteorDockerfile"],
|
|
66
|
+
needs: appBuildJob ? [APP_BUILD_JOB_NAME] : [],
|
|
67
|
+
}),
|
|
76
68
|
];
|
|
77
69
|
};
|
|
@@ -1,12 +1,11 @@
|
|
|
1
|
-
import { BASE_RETRY } from "../../defaults";
|
|
2
1
|
import { Context } from "../../types/context";
|
|
3
|
-
import {
|
|
2
|
+
import { CatladderJob } from "../../types/jobs";
|
|
4
3
|
import { ensureArray, notNil } from "../../utils";
|
|
5
4
|
import { getNodeCache } from "./cache";
|
|
6
5
|
import { NODE_RUNNER_BUILD_VARIABLES } from "./constants";
|
|
7
6
|
import { getYarnInstall } from "./yarn";
|
|
8
7
|
|
|
9
|
-
export const createNodeTestJobs = (context: Context):
|
|
8
|
+
export const createNodeTestJobs = (context: Context): CatladderJob[] => {
|
|
10
9
|
// don't run tests after release
|
|
11
10
|
if (context.commitInfo?.trigger === "taggedRelease") {
|
|
12
11
|
return [];
|
|
@@ -14,66 +13,58 @@ export const createNodeTestJobs = (context: Context): GitlabJobs => {
|
|
|
14
13
|
|
|
15
14
|
const buildConfig = context.componentConfig.build;
|
|
16
15
|
|
|
17
|
-
const base: Omit<
|
|
16
|
+
const base: Omit<CatladderJob, "script" | "name"> = {
|
|
18
17
|
variables: {
|
|
19
18
|
APP_PATH: context.componentConfig.dir,
|
|
20
19
|
...NODE_RUNNER_BUILD_VARIABLES,
|
|
21
20
|
...(buildConfig.extraVars ?? {}),
|
|
22
21
|
},
|
|
23
|
-
|
|
24
22
|
stage: "test",
|
|
25
|
-
interruptible: true,
|
|
26
23
|
needs: [],
|
|
27
|
-
|
|
24
|
+
envMode: "none",
|
|
28
25
|
};
|
|
29
26
|
const yarnInstall = getYarnInstall(context);
|
|
30
|
-
const auditJob:
|
|
27
|
+
const auditJob: CatladderJob | null =
|
|
31
28
|
buildConfig.audit !== false
|
|
32
29
|
? {
|
|
33
30
|
name: "๐ก audit",
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
allow_failure: true,
|
|
43
|
-
},
|
|
31
|
+
|
|
32
|
+
...base,
|
|
33
|
+
cache: undefined, // audit does not need yarn install and no cache
|
|
34
|
+
script: [
|
|
35
|
+
`cd ${context.componentConfig.dir}`,
|
|
36
|
+
...(ensureArray(buildConfig.audit?.command) ?? ["yarn audit"]),
|
|
37
|
+
],
|
|
38
|
+
allow_failure: true,
|
|
44
39
|
}
|
|
45
40
|
: null;
|
|
46
41
|
|
|
47
|
-
const lintJob:
|
|
42
|
+
const lintJob: CatladderJob | null =
|
|
48
43
|
buildConfig.lint !== false
|
|
49
44
|
? {
|
|
50
45
|
name: "๐ฎ lint",
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
],
|
|
60
|
-
},
|
|
46
|
+
|
|
47
|
+
...base,
|
|
48
|
+
cache: getNodeCache(context),
|
|
49
|
+
script: [
|
|
50
|
+
`cd ${context.componentConfig.dir}`,
|
|
51
|
+
...yarnInstall,
|
|
52
|
+
...(ensureArray(buildConfig.lint?.command) ?? ["yarn lint"]),
|
|
53
|
+
],
|
|
61
54
|
}
|
|
62
55
|
: null;
|
|
63
|
-
const testJob:
|
|
56
|
+
const testJob: CatladderJob | null =
|
|
64
57
|
buildConfig.test !== false
|
|
65
58
|
? {
|
|
66
59
|
name: "๐งช test",
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
],
|
|
76
|
-
},
|
|
60
|
+
|
|
61
|
+
...base,
|
|
62
|
+
cache: getNodeCache(context),
|
|
63
|
+
script: [
|
|
64
|
+
`cd ${context.componentConfig.dir}`,
|
|
65
|
+
...yarnInstall,
|
|
66
|
+
...(ensureArray(buildConfig.test?.command) ?? ["yarn test"]),
|
|
67
|
+
],
|
|
77
68
|
}
|
|
78
69
|
: null;
|
|
79
70
|
return [auditJob, lintJob, testJob].filter(notNil);
|
package/src/build/node/yarn.ts
CHANGED
|
@@ -1,8 +1,25 @@
|
|
|
1
1
|
import { Context } from "../../types";
|
|
2
2
|
|
|
3
|
+
export const getYarnInstallCommand = (
|
|
4
|
+
context: Context,
|
|
5
|
+
options?: {
|
|
6
|
+
prodOnly?: boolean;
|
|
7
|
+
noScripts?: boolean;
|
|
8
|
+
}
|
|
9
|
+
) =>
|
|
10
|
+
context.packageManagerInfo?.isClassic
|
|
11
|
+
? `yarn install --frozen-lockfile ${
|
|
12
|
+
options?.prodOnly ? "--production" : ""
|
|
13
|
+
} ${options?.noScripts ? "--ignore-scripts" : ""}`
|
|
14
|
+
: options?.prodOnly
|
|
15
|
+
? `${
|
|
16
|
+
options?.noScripts ? "YARN_ENABLE_SCRIPTS=false " : ""
|
|
17
|
+
}yarn plugin import workspace-tools && yarn workspaces focus --production` // needs yarn plugin import workspace-tools
|
|
18
|
+
: `${
|
|
19
|
+
options?.noScripts ? "YARN_ENABLE_SCRIPTS=false " : ""
|
|
20
|
+
}yarn install --immutable`;
|
|
21
|
+
|
|
3
22
|
export const getYarnInstall = (context: Context) => [
|
|
4
23
|
"if [ -f ./.nvmrc ]; then source /root/.nvm/nvm.sh && nvm install <<< .nvmrc; fi",
|
|
5
|
-
context
|
|
6
|
-
? "yarn install --frozen-lockfile"
|
|
7
|
-
: "yarn install --immutable",
|
|
24
|
+
getYarnInstallCommand(context),
|
|
8
25
|
];
|
|
@@ -26,7 +26,8 @@ describe("storybook build", () => {
|
|
|
26
26
|
};
|
|
27
27
|
|
|
28
28
|
it("creates a pipeline for storybook that does not contain test stages", async () => {
|
|
29
|
-
const {
|
|
29
|
+
const { jobs } = await createChildPipeline(
|
|
30
|
+
"gitlab",
|
|
30
31
|
"mainBranch",
|
|
31
32
|
config
|
|
32
33
|
);
|
|
@@ -40,7 +41,8 @@ describe("storybook build", () => {
|
|
|
40
41
|
});
|
|
41
42
|
|
|
42
43
|
it("runs build and renames folder", async () => {
|
|
43
|
-
const {
|
|
44
|
+
const { jobs } = await createChildPipeline(
|
|
45
|
+
"gitlab",
|
|
44
46
|
"mainBranch",
|
|
45
47
|
config
|
|
46
48
|
);
|
package/src/build/types.ts
CHANGED
|
@@ -46,6 +46,12 @@ export type BuildConfigBase = {
|
|
|
46
46
|
| {
|
|
47
47
|
command?: string | string[];
|
|
48
48
|
};
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* additional paths for artifacts,
|
|
52
|
+
* by default "dist" and ".next" are allways included
|
|
53
|
+
*/
|
|
54
|
+
artifactsPaths?: [];
|
|
49
55
|
};
|
|
50
56
|
|
|
51
57
|
export type BuildConfigNodeBase = BuildConfigBase;
|
package/src/catladder-gitlab.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { writeFileSync } from "fs";
|
|
2
|
+
import { dump } from "js-yaml";
|
|
2
3
|
import { readConfigSync } from "./config";
|
|
3
4
|
import { PIPELINE_IMAGE_TAG } from "./constants";
|
|
4
5
|
import { createChildPipeline } from "./pipeline";
|
|
@@ -32,11 +33,14 @@ if (trigger) {
|
|
|
32
33
|
if (!config) {
|
|
33
34
|
throw new Error("no catladder config found");
|
|
34
35
|
}
|
|
35
|
-
createChildPipeline(trigger, config).then(
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
36
|
+
createChildPipeline("gitlab", trigger, config).then(
|
|
37
|
+
({ jobs, ...mainPipeline }) => {
|
|
38
|
+
// need to spread out the jobs
|
|
39
|
+
writeFileSync(`__pipeline.yml`, dump({ ...jobs, ...mainPipeline }), {
|
|
40
|
+
encoding: "utf-8",
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
);
|
|
40
44
|
} else {
|
|
41
45
|
throw new Error(
|
|
42
46
|
"no matching trigger: " +
|