@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.
Files changed (79) hide show
  1. package/dist/build/base/constants.js +1 -1
  2. package/dist/build/base/createBuildJob.d.ts +4 -2
  3. package/dist/build/base/createBuildJob.js +13 -18
  4. package/dist/build/docker.d.ts +6 -3
  5. package/dist/build/docker.js +24 -9
  6. package/dist/build/index.d.ts +2 -2
  7. package/dist/build/node/buildJob.d.ts +2 -2
  8. package/dist/build/node/buildJob.js +26 -13
  9. package/dist/build/node/cache.d.ts +3 -1
  10. package/dist/build/node/cache.js +33 -5
  11. package/dist/build/node/constants.js +2 -2
  12. package/dist/build/node/index.d.ts +4 -4
  13. package/dist/build/node/meteor.d.ts +2 -2
  14. package/dist/build/node/meteor.js +4 -23
  15. package/dist/build/node/testJob.d.ts +2 -2
  16. package/dist/build/node/testJob.js +20 -29
  17. package/dist/build/node/yarn.d.ts +4 -0
  18. package/dist/build/node/yarn.js +10 -3
  19. package/dist/build/tests/storybook.test.js +10 -23
  20. package/dist/build/types.d.ts +6 -0
  21. package/dist/catladder-gitlab.js +33 -2
  22. package/dist/constants.js +1 -1
  23. package/dist/context/index.d.ts +2 -2
  24. package/dist/context/index.js +2 -2
  25. package/dist/deploy/base.d.ts +3 -4
  26. package/dist/deploy/base.js +27 -33
  27. package/dist/deploy/index.d.ts +2 -2
  28. package/dist/deploy/kubernetes/deployJob.d.ts +2 -2
  29. package/dist/deploy/kubernetes/deployJob.js +32 -38
  30. package/dist/pipeline/createChildPipeline.d.ts +2 -11
  31. package/dist/pipeline/createChildPipeline.js +24 -18
  32. package/dist/pipeline/createChildPipeline.test.js +3 -14
  33. package/dist/pipeline/createJobs.d.ts +2 -2
  34. package/dist/pipeline/createJobs.js +29 -23
  35. package/dist/pipeline/gitlab/makeGitlabJob.d.ts +8 -0
  36. package/dist/pipeline/gitlab/makeGitlabJob.js +45 -0
  37. package/dist/pipeline/packageManager.d.ts +2 -0
  38. package/dist/pipeline/{yarnInfo.js โ†’ packageManager.js} +69 -8
  39. package/dist/tsconfig.tsbuildinfo +1 -1
  40. package/dist/types/context.d.ts +15 -6
  41. package/dist/types/gitlab-types.d.ts +10 -22
  42. package/dist/types/gitlab-types.js +1 -3
  43. package/dist/types/index.d.ts +2 -1
  44. package/dist/types/index.js +3 -1
  45. package/dist/types/jobs.d.ts +75 -0
  46. package/dist/types/jobs.js +5 -0
  47. package/dist/types/pipeline.d.ts +4 -0
  48. package/dist/types/pipeline.js +3 -0
  49. package/package.json +1 -1
  50. package/src/build/base/constants.ts +1 -1
  51. package/src/build/base/createBuildJob.ts +29 -31
  52. package/src/build/docker.ts +50 -45
  53. package/src/build/index.ts +3 -2
  54. package/src/build/node/buildJob.ts +35 -25
  55. package/src/build/node/cache.ts +30 -5
  56. package/src/build/node/constants.ts +2 -2
  57. package/src/build/node/index.ts +4 -4
  58. package/src/build/node/meteor.ts +10 -18
  59. package/src/build/node/testJob.ts +31 -40
  60. package/src/build/node/yarn.ts +20 -3
  61. package/src/build/tests/storybook.test.ts +4 -2
  62. package/src/build/types.ts +6 -0
  63. package/src/catladder-gitlab.ts +9 -5
  64. package/src/context/index.ts +8 -4
  65. package/src/deploy/base.ts +40 -45
  66. package/src/deploy/index.ts +2 -2
  67. package/src/deploy/kubernetes/deployJob.ts +43 -48
  68. package/src/pipeline/createChildPipeline.test.ts +2 -1
  69. package/src/pipeline/createChildPipeline.ts +23 -21
  70. package/src/pipeline/createJobs.ts +50 -41
  71. package/src/pipeline/gitlab/makeGitlabJob.ts +16 -0
  72. package/src/pipeline/packageManager.ts +99 -0
  73. package/src/types/context.ts +14 -3
  74. package/src/types/gitlab-types.ts +10 -30
  75. package/src/types/index.ts +1 -0
  76. package/src/types/jobs.ts +88 -0
  77. package/src/types/pipeline.ts +11 -0
  78. package/dist/pipeline/yarnInfo.d.ts +0 -2
  79. package/src/pipeline/yarnInfo.ts +0 -54
@@ -1,6 +1,6 @@
1
1
  import { merge } from "lodash";
2
- import { Context, getRunnerImage, GitlabJob, GitlabJobDef } from "../..";
3
- import { BASE_RETRY } from "../../defaults";
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<GitlabJobDef>
14
- ): GitlabJob => {
15
- return {
16
- name: APP_BUILD_JOB_NAME,
17
- envMode: "jobPerEnv",
18
- job: merge(
19
- {
20
- image: getRunnerImage("jobs-default"),
21
- needs: [],
22
- cache: [],
23
- variables: {
24
- ...RUNNER_BUILD_RESOURCE_VARIABLES,
25
- ...context.environment.envVars,
26
- ...(context.componentConfig.build.extraVars ?? {}),
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
- def
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
  };
@@ -1,5 +1,7 @@
1
+ import { merge } from "lodash";
1
2
  import { getRunnerImage } from "../runner";
2
- import { GitlabJobDef, Context } from "../types";
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 }: Pick<GitlabJobDef, "script">
15
- ): GitlabJobDef => {
16
- const base: Omit<GitlabJobDef, "script"> = {
17
- stage: "build",
18
- image: getRunnerImage("docker-build"),
19
- interruptible: true,
20
- services: [
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
- CACHE_IMAGE: "$CI_REGISTRY_IMAGE/caches/" + context.componentName,
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
- return {
50
- ...base,
51
- script: [
52
- ...script,
53
- "docker login --username gitlab-ci-token --password $CI_JOB_TOKEN $CI_REGISTRY",
46
+ IMAGE_NAME:
47
+ "$CI_REGISTRY_IMAGE/" +
48
+ context.environment.shortName +
49
+ "/" +
50
+ context.componentName,
54
51
 
55
- "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/
56
- "docker push $IMAGE_NAME:$IMAGE_TAG",
57
- "docker tag $IMAGE_NAME:$IMAGE_TAG $CACHE_IMAGE",
58
- "docker push $CACHE_IMAGE",
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
  };
@@ -1,5 +1,6 @@
1
1
  import { Context } from "../types/context";
2
- import { GitlabJobs } from "../types/gitlab-types";
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) => GitlabJobs;
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, DOCKER_BUILD_JOB_NAME } from "../docker";
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): GitlabJobs => {
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: GitlabJob | null =
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 + "/__build_info.json",
37
- context.componentConfig.dir + "/dist",
38
- context.componentConfig.dir + "/.next",
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
- name: DOCKER_BUILD_JOB_NAME,
47
- envMode: "jobPerEnv",
48
- job: {
49
- ...createDockerBuildJob(context, {
50
- script: [
51
- buildConfig.type === "node-static" ||
52
- buildConfig.type === "storybook"
53
- ? "ensureNginxDockerfile"
54
- : "ensureNodeDockerfile",
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
- needs: appBuildJob ? [APP_BUILD_JOB_NAME] : [],
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
  };
@@ -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 getNodeCache = (context: Context): GitlabJobCache[] => {
6
- const componentIsInWorkspace = context.yarnInfo?.componentIsInWorkspace;
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: "pull-push",
31
+ policy,
15
32
  paths: [
16
- ".yarn",
17
33
  ...(componentIsInWorkspace
18
34
  ? [
19
35
  "node_modules",
20
- ...(context.yarnInfo?.workspaces.map((w) =>
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
  {
@@ -1,6 +1,6 @@
1
1
  export const NODE_RUNNER_BUILD_VARIABLES = {
2
2
  KUBERNETES_CPU_REQUEST: "0.5",
3
3
  KUBERNETES_CPU_LIMIT: "2",
4
- KUBERNETES_MEMORY_REQUEST: "1Gi",
5
- KUBERNETES_MEMORY_LIMIT: "3Gi",
4
+ KUBERNETES_MEMORY_REQUEST: "2Gi",
5
+ KUBERNETES_MEMORY_LIMIT: "4Gi",
6
6
  };
@@ -1,17 +1,17 @@
1
1
  import type { Context } from "../../types/context";
2
- import type { GitlabJobs } from "../../types/gitlab-types";
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): GitlabJobs => {
7
+ export const createNodeJobs = (context: Context): CatladderJob[] => {
8
8
  return [...createNodeTestJobs(context), ...createNodeBuildJobs(context)];
9
9
  };
10
10
 
11
- export const createStorybookJobs = (context: Context): GitlabJobs => {
11
+ export const createStorybookJobs = (context: Context): CatladderJob[] => {
12
12
  return [...createNodeBuildJobs(context)];
13
13
  };
14
14
 
15
- export const createMeteorJobs = (context: Context): GitlabJobs => {
15
+ export const createMeteorJobs = (context: Context): CatladderJob[] => {
16
16
  return [...createNodeTestJobs(context), ...createMeteorBuildJobs(context)];
17
17
  };
@@ -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
- import type {
5
- GitlabJob,
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, DOCKER_BUILD_JOB_NAME } from "../docker";
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): GitlabJobs => {
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: GitlabJob | null =
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
- name: DOCKER_BUILD_JOB_NAME,
68
- envMode: "jobPerEnv",
69
- job: {
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 { GitlabJob, GitlabJobDef, GitlabJobs } from "../../types/gitlab-types";
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): GitlabJobs => {
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<GitlabJobDef, "script"> = {
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
- retry: BASE_RETRY,
24
+ envMode: "none",
28
25
  };
29
26
  const yarnInstall = getYarnInstall(context);
30
- const auditJob: GitlabJob | null =
27
+ const auditJob: CatladderJob | null =
31
28
  buildConfig.audit !== false
32
29
  ? {
33
30
  name: "๐Ÿ›ก audit",
34
- envMode: "none",
35
- job: {
36
- ...base,
37
- cache: undefined, // audit does not need yarn install and no cache
38
- script: [
39
- `cd ${context.componentConfig.dir}`,
40
- ...(ensureArray(buildConfig.audit?.command) ?? ["yarn audit"]),
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: GitlabJob | null =
42
+ const lintJob: CatladderJob | null =
48
43
  buildConfig.lint !== false
49
44
  ? {
50
45
  name: "๐Ÿ‘ฎ lint",
51
- envMode: "none",
52
- job: {
53
- ...base,
54
- cache: getNodeCache(context),
55
- script: [
56
- `cd ${context.componentConfig.dir}`,
57
- ...yarnInstall,
58
- ...(ensureArray(buildConfig.lint?.command) ?? ["yarn lint"]),
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: GitlabJob | null =
56
+ const testJob: CatladderJob | null =
64
57
  buildConfig.test !== false
65
58
  ? {
66
59
  name: "๐Ÿงช test",
67
- envMode: "none",
68
- job: {
69
- ...base,
70
- cache: getNodeCache(context),
71
- script: [
72
- `cd ${context.componentConfig.dir}`,
73
- ...yarnInstall,
74
- ...(ensureArray(buildConfig.test?.command) ?? ["yarn test"]),
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);
@@ -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.yarnInfo?.isClassic
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 { image, stages, workflow, ...jobs } = await createChildPipeline(
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 { image, stages, workflow, ...jobs } = await createChildPipeline(
44
+ const { jobs } = await createChildPipeline(
45
+ "gitlab",
44
46
  "mainBranch",
45
47
  config
46
48
  );
@@ -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;
@@ -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((mainPipeline) => {
36
- writeFileSync(`__pipeline.yml`, JSON.stringify(mainPipeline, null, 2), {
37
- encoding: "utf-8",
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: " +