@catladder/pipeline 1.87.0 → 1.89.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.
@@ -0,0 +1,57 @@
1
+ import type { Config } from "../src";
2
+ import { createAllPipelines } from "./__utils__/helpers";
3
+ const config: Config = {
4
+ appName: "test-app",
5
+ customerName: "pan",
6
+ components: {
7
+ api: {
8
+ dir: "api",
9
+ build: {
10
+ type: "node",
11
+ },
12
+ deploy: {
13
+ type: "kubernetes",
14
+ cluster: {
15
+ name: "some-cluster-name",
16
+ region: "europe-west6",
17
+ projectId: "some-project-id",
18
+ type: "gcloud",
19
+ domainCanonical: "panter.cloud",
20
+ },
21
+
22
+ values: {
23
+ application: {
24
+ command: "node main.js",
25
+ autoscale: {
26
+ minReplicas: 2,
27
+ maxReplicas: 5,
28
+ metrics: [
29
+ {
30
+ type: "Resource",
31
+ resource: {
32
+ name: "cpu",
33
+
34
+ target: {
35
+ type: "Utilization",
36
+ averageUtilization: 0.5,
37
+ },
38
+ },
39
+ },
40
+ ],
41
+ },
42
+ resources: {
43
+ limits: {
44
+ cpu: "1",
45
+ memory: "2048Mi",
46
+ },
47
+ },
48
+ },
49
+ },
50
+ },
51
+ },
52
+ },
53
+ };
54
+
55
+ it("matches snapshot", async () => {
56
+ expect(await createAllPipelines(config)).toMatchSnapshot();
57
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@catladder/pipeline",
3
- "version": "1.87.0",
3
+ "version": "1.89.0",
4
4
  "scripts": {
5
5
  "build:tsc": "yarn tsc",
6
6
  "build": "yarn build:compile && yarn build:inline-variables && yarn build:bundle",
@@ -45,20 +45,24 @@ export const requiresDockerBuild = (context: Context) => {
45
45
  return false;
46
46
  };
47
47
 
48
+ const getDockerBaseVariables = () => ({
49
+ DOCKER_HOST: "tcp://0.0.0.0:2375",
50
+ DOCKER_TLS_CERTDIR: "",
51
+ DOCKER_DRIVER: "overlay2",
52
+ DOCKER_BUILDKIT: "1", // see https://docs.docker.com/develop/develop-images/build_enhancements/
53
+ });
54
+
48
55
  export const getDockerBuildVariables = (context: Context) => {
49
56
  return {
50
57
  ...DOCKER_RUNNER_BUILD_VARIABLES,
51
- DOCKER_BUILDKIT: "1", // see https://docs.docker.com/develop/develop-images/build_enhancements/
52
58
  DOCKERFILE_ADDITIONS:
53
59
  context.componentConfig.build.docker?.additionsBegin?.join("\n"),
54
60
  DOCKERFILE_ADDITIONS_END:
55
61
  context.componentConfig.build.docker?.additionsEnd?.join("\n"),
56
62
  APP_DIR: context.componentConfig.dir,
57
- DOCKER_HOST: "tcp://0.0.0.0:2375",
58
- DOCKER_TLS_CERTDIR: "",
59
- DOCKER_DIR: ".", // relative to componentdir
60
63
 
61
- DOCKER_DRIVER: "overlay2",
64
+ DOCKER_DIR: ".", // relative to componentdir
65
+ ...getDockerBaseVariables(),
62
66
 
63
67
  ...getDockerImageVariables(context),
64
68
  };
@@ -74,7 +78,7 @@ export const getDockerJobBaseProps = (context: Context) => {
74
78
  command: ["--tls=false"],
75
79
  },
76
80
  ],
77
- variables: getDockerBuildVariables(context),
81
+ variables: getDockerBaseVariables(),
78
82
  };
79
83
  };
80
84
  export const createDockerBuildJobBase = (
@@ -89,6 +93,9 @@ export const createDockerBuildJobBase = (
89
93
  ...getDockerJobBaseProps(context),
90
94
  script: script || [],
91
95
  },
96
+ {
97
+ variables: getDockerBuildVariables(context),
98
+ },
92
99
  def
93
100
  );
94
101
  };
@@ -44,7 +44,7 @@ export const getBaseDeploymentJob = (context: Context): JobWithoutScript => {
44
44
  name: DEPLOY_JOB_NAME,
45
45
  envMode: "stagePerEnv", // makes it easier to run manual tasks er env
46
46
 
47
- needsOtherComponent: context.componentConfig.deploy
47
+ needs: context.componentConfig.deploy
48
48
  ? context.componentConfig.deploy.waitFor?.map((c) => ({
49
49
  componentName: c,
50
50
  job: DEPLOY_JOB_NAME,
@@ -20,27 +20,29 @@ const createAppConfig = (
20
20
  };
21
21
  }
22
22
 
23
+ const { healthRoute, command, ...rest } = application ?? {};
24
+
23
25
  return mergeWithMergingArrays(
24
26
  {
25
27
  host: context.environment.host,
26
- command: context.componentConfig.build.startCommand,
28
+ command: command ?? context.componentConfig.build.startCommand,
27
29
  livenessProbe: {
28
30
  httpGet: {
29
- path: application?.healthRoute ?? "__health",
31
+ path: healthRoute ?? "__health",
30
32
  },
31
33
  },
32
34
  readinessProbe: {
33
35
  httpGet: {
34
- path: application?.healthRoute ?? "__health",
36
+ path: healthRoute ?? "__health",
35
37
  },
36
38
  },
37
39
  startupProbe: {
38
40
  httpGet: {
39
- path: application?.healthRoute ?? "__health",
41
+ path: healthRoute ?? "__health",
40
42
  },
41
43
  },
42
44
  }, // default
43
- application // merge rest in
45
+ rest // merge rest in
44
46
  );
45
47
  };
46
48
 
@@ -192,6 +192,11 @@ export type DeployConfigKubernetesValues = AllowUnknownProps<{
192
192
  application?:
193
193
  | false
194
194
  | AllowUnknownProps<{
195
+ /**
196
+ * command to start, defaults to build's startCommand
197
+ */
198
+ command?: string;
199
+
195
200
  /**
196
201
  * enable, disable app deployment, defaults to true
197
202
  */
@@ -240,7 +245,7 @@ export type DeployConfigKubernetesValues = AllowUnknownProps<{
240
245
  */
241
246
  jobDefaults?: {
242
247
  resources: KubernetesResourcesDef;
243
- }
248
+ };
244
249
  }>;
245
250
 
246
251
  /**
@@ -292,5 +297,5 @@ export type DeployConfigKubernetes = {
292
297
  * Custom Helm chart location.
293
298
  * Not recommended to use.
294
299
  */
295
- chartName?: string
300
+ chartName?: string;
296
301
  } & DeployConfigBase;
@@ -5,7 +5,7 @@ import { DEPLOY_TYPES } from "../deploy";
5
5
  import type { PipelineJob, PipelineType } from "../types";
6
6
  import type { Config, PipelineTrigger } from "../types/config";
7
7
  import type { CommitInfo, Context } from "../types/context";
8
- import type { CatladderJob, CatladderJobNeed } from "../types/jobs";
8
+ import type { CatladderJob } from "../types/jobs";
9
9
  import { notNil } from "../utils";
10
10
  import { getBaseCommitInfo } from "./commitInfo/getCommitInfo";
11
11
  import { makeGitlabJob } from "./gitlab/makeGitlabJob";
@@ -78,28 +78,25 @@ const replaceReferences = (
78
78
  const stage =
79
79
  job.envMode === "stagePerEnv" ? `${job.stage} ${env}` : job.stage;
80
80
 
81
- const needsFromNeeds: CatladderJob["needs"] = job.needs?.map((n) =>
81
+ const cleanedNeeds: CatladderJob["needs"] = [
82
+ ...(job.needs ?? []),
83
+ // pull in legacy needs from other component, which is now identical to needs
84
+ ...(job.needsOtherComponent ?? []),
85
+ ];
86
+ const needs: CatladderJob["needs"] = cleanedNeeds?.map((n) =>
82
87
  isObject(n)
83
88
  ? {
84
- job: getFullReferencedJobName(n.job, componentName, env, allRawJobs),
89
+ job: getFullReferencedJobName(
90
+ n.job,
91
+ n.componentName ?? componentName,
92
+ env,
93
+ allRawJobs
94
+ ),
85
95
  artifacts: n.artifacts,
86
96
  }
87
97
  : getFullReferencedJobName(n, componentName, env, allRawJobs)
88
98
  );
89
- const needsFromOtherComponents: CatladderJob["needs"] =
90
- job.needsOtherComponent?.map((other) => ({
91
- artifacts: other.artifacts,
92
- job: getFullReferencedJobName(
93
- other.job,
94
- other.componentName,
95
- env,
96
- allRawJobs
97
- ),
98
- }));
99
- const needs = [
100
- ...(needsFromNeeds ?? []),
101
- ...(needsFromOtherComponents ?? []),
102
- ];
99
+
103
100
  return {
104
101
  ...job,
105
102
  stage,
@@ -16,7 +16,9 @@ export const makeGitlabJob = ({
16
16
  return {
17
17
  ...rest,
18
18
  // sort in a predictable manner for snapshot tests
19
- needs: needs?.sort((a, b) => getJobName(a).localeCompare(getJobName(b))),
19
+ needs: needs
20
+ ? [...needs].sort((a, b) => getJobName(a).localeCompare(getJobName(b)))
21
+ : undefined,
20
22
  retry: BASE_RETRY,
21
23
  interruptible: true,
22
24
  };
package/src/types/jobs.ts CHANGED
@@ -19,7 +19,9 @@ export const BASE_STAGES = [
19
19
  ] as const;
20
20
  export type BaseStage = typeof BASE_STAGES[number];
21
21
 
22
- export type CatladderJobNeed = string | { job: string; artifacts: boolean };
22
+ export type CatladderJobNeed =
23
+ | string
24
+ | { job: string; artifacts: boolean; componentName?: string };
23
25
  export type CatladderJob<S = BaseStage> = {
24
26
  /**
25
27
  * the name of the job (without any env or app prefix and suffix)
@@ -53,9 +55,15 @@ export type CatladderJob<S = BaseStage> = {
53
55
 
54
56
  /**
55
57
  * does this require another job (from the same component)?
58
+ *
59
+ * You can also require a job from another component if you set `componentName`
60
+ *
56
61
  */
57
62
  needs?: Array<CatladderJobNeed>;
58
63
 
64
+ /**
65
+ * @deprecated set `componentName` to `needs` if you want to wait for a job from another component
66
+ */
59
67
  needsOtherComponent?: Array<{
60
68
  componentName: string;
61
69
  job: string;