@catladder/pipeline 1.100.1 → 1.101.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 (49) hide show
  1. package/dist/build/node/buildJob.js +9 -8
  2. package/dist/build/node/yarn.js +1 -1
  3. package/dist/build/types.d.ts +8 -4
  4. package/dist/bundles/catladder-gitlab/index.js +3 -3
  5. package/dist/constants.js +1 -1
  6. package/dist/context/getEnvironmentVariables.js +4 -1
  7. package/dist/deploy/base.js +5 -4
  8. package/dist/deploy/types/base.d.ts +8 -0
  9. package/dist/pipeline/commitInfo/getBuildId.d.ts +6 -1
  10. package/dist/pipeline/commitInfo/getBuildId.js +22 -2
  11. package/dist/pipeline/commitInfo/getCommitInfo.js +4 -1
  12. package/dist/pipeline/gitlab/createGitlabJobs.d.ts +1 -0
  13. package/dist/pipeline/gitlab/createGitlabJobs.js +12 -3
  14. package/dist/tsconfig.tsbuildinfo +1 -1
  15. package/dist/types/context.d.ts +1 -0
  16. package/dist/types/gitlab-types.d.ts +1 -0
  17. package/dist/types/jobs.d.ts +4 -0
  18. package/dist/utils/index.d.ts +1 -1
  19. package/examples/__snapshots__/cloud-run-memory-limit.ts.snap +80 -64
  20. package/examples/__snapshots__/cloud-run-no-cpu-throttling.ts.snap +80 -64
  21. package/examples/__snapshots__/cloud-run-non-public.ts.snap +80 -64
  22. package/examples/__snapshots__/cloud-run-with-sql-reuse-db.ts.snap +160 -128
  23. package/examples/__snapshots__/cloud-run-with-sql.ts.snap +160 -128
  24. package/examples/__snapshots__/custom-build-job-with-tests.ts.snap +64 -60
  25. package/examples/__snapshots__/custom-build-job.ts.snap +64 -52
  26. package/examples/__snapshots__/custom-deploy.ts.snap +64 -60
  27. package/examples/__snapshots__/custom-envs.ts.snap +56 -60
  28. package/examples/__snapshots__/custom-sbom-java.ts.snap +64 -52
  29. package/examples/__snapshots__/kubernetes-application-customization.ts.snap +148 -84
  30. package/examples/__snapshots__/kubernetes-with-cloud-sql-legacy.ts.snap +148 -84
  31. package/examples/__snapshots__/kubernetes-with-cloud-sql.ts.snap +148 -84
  32. package/examples/__snapshots__/kubernetes-with-jobs.ts.snap +296 -168
  33. package/examples/__snapshots__/kubernetes-with-mongodb.ts.snap +148 -84
  34. package/examples/__snapshots__/rails-k8s-with-worker.ts.snap +108 -64
  35. package/examples/__snapshots__/wait-for-other-deploy.ts.snap +120 -104
  36. package/package.json +1 -1
  37. package/src/build/node/buildJob.ts +6 -1
  38. package/src/build/node/yarn.ts +2 -1
  39. package/src/build/types.ts +10 -5
  40. package/src/context/getEnvironmentVariables.ts +4 -1
  41. package/src/deploy/base.ts +7 -2
  42. package/src/deploy/types/base.ts +10 -0
  43. package/src/pipeline/commitInfo/getBuildId.ts +11 -0
  44. package/src/pipeline/commitInfo/getCommitInfo.ts +2 -1
  45. package/src/pipeline/gitlab/createGitlabJobs.ts +8 -2
  46. package/src/types/context.ts +1 -0
  47. package/src/types/gitlab-types.ts +1 -0
  48. package/src/types/jobs.ts +5 -0
  49. package/src/utils/index.ts +1 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@catladder/pipeline",
3
- "version": "1.100.1",
3
+ "version": "1.101.0",
4
4
  "scripts": {
5
5
  "build:tsc": "yarn tsc",
6
6
  "build": "yarn build:compile && yarn build:inline-variables && yarn build:bundle",
@@ -24,7 +24,11 @@ export const createNodeBuildJobs = (context: Context): CatladderJob[] => {
24
24
  variables: {
25
25
  ...NODE_RUNNER_BUILD_VARIABLES,
26
26
  },
27
- cache: [...getNodeCache(context), ...getNextCache(context)],
27
+ cache: [
28
+ ...(ensureArray(buildConfig.jobCache) ?? []),
29
+ ...getNodeCache(context),
30
+ ...getNextCache(context),
31
+ ],
28
32
  script: [
29
33
  ...yarnInstall,
30
34
  ...(ensureArray(buildConfig.buildCommand) ?? []),
@@ -39,6 +43,7 @@ export const createNodeBuildJobs = (context: Context): CatladderJob[] => {
39
43
  ) ?? []),
40
44
  ],
41
45
  },
46
+ jobTags: buildConfig.jobTags,
42
47
  })
43
48
  : null;
44
49
  return [
@@ -14,7 +14,8 @@ const getYarnInstallCommand = (context: Context) => {
14
14
  };
15
15
 
16
16
  export const ensureNodeVersion = (context: Context) => [
17
- "if [ -f ./.nvmrc ]; then source /root/.nvm/nvm.sh && nvm install <<< .nvmrc; fi",
17
+ "if [ -f ~/.nvm/nvm.sh ]; then source ~/.nvm/nvm.sh; fi",
18
+ "if [ -f ./.nvmrc ]; then nvm install <<< .nvmrc; fi",
18
19
  ];
19
20
 
20
21
  export const getYarnInstall = (context: Context) => [
@@ -75,6 +75,16 @@ export type BuildConfigBase = {
75
75
  * use to display information in merge requests, pipeline views and security dashboards.
76
76
  */
77
77
  artifactsReports?: BuildConfigArtifactsReports;
78
+
79
+ /**
80
+ * customize cache for the job
81
+ */
82
+ jobCache?: CatladderJob["cache"];
83
+
84
+ /**
85
+ * tags for the underlying job runner (e.g gitlab)
86
+ */
87
+ jobTags?: string[];
78
88
  };
79
89
 
80
90
  export type BuildConfigNodeBase = BuildConfigBase;
@@ -123,11 +133,6 @@ export type BuildConfigCustom = Omit<
123
133
 
124
134
  docker: BuildConfigCustomDocker;
125
135
 
126
- /**
127
- * customize cache for the job
128
- */
129
- jobCache?: CatladderJob["cache"];
130
-
131
136
  /**
132
137
  * custom lint, disabled when not set
133
138
  */
@@ -39,9 +39,12 @@ export const getEnvironmentVariables = async (
39
39
  ENV_SHORT: env,
40
40
  APP_DIR: envConfigRaw.dir,
41
41
  ENV_TYPE: envType,
42
+ BUILD_INFO_ID: commitInfo?.buildId,
43
+ BUILD_INFO_BUILD_TIME: commitInfo?.buildTime,
44
+ BUILD_INFO_CURRENT_VERSION: commitInfo?.currentVersion,
42
45
  };
43
46
 
44
- let predefinedVariables: Record<string, string>;
47
+ let predefinedVariables: Record<string, string | undefined>;
45
48
  let host: string;
46
49
  let url: string;
47
50
 
@@ -1,7 +1,6 @@
1
1
  import { getDockerImageVariables, requiresDockerBuild } from "../build/docker";
2
2
  import type { Context } from "../types";
3
3
  import type { CatladderJob } from "../types/jobs";
4
- import { isOfDeployType } from "./types";
5
4
  import { contextIsStoppable } from "./utils";
6
5
 
7
6
  export const DEPLOY_JOB_NAME = "🚀 Deploy";
@@ -12,7 +11,7 @@ const DEPLOY_RUNNER_VARIABLES = {
12
11
  KUBERNETES_CPU_REQUEST: "0.5",
13
12
  KUBERNETES_CPU_LIMIT: "1",
14
13
  KUBERNETES_MEMORY_REQUEST: "200Mi",
15
- KUBERNETES_MEMORY_LIMIT: "500Mi",
14
+ KUBERNETES_MEMORY_LIMIT: "200Mi",
16
15
  };
17
16
  type JobWithoutScript = Omit<CatladderJob, "script">;
18
17
  export const getBaseDeploymentJob = (context: Context): JobWithoutScript => {
@@ -77,6 +76,9 @@ export const getBaseDeploymentJob = (context: Context): JobWithoutScript => {
77
76
  ...DEPLOY_RUNNER_VARIABLES,
78
77
  ...context.environment.envVars,
79
78
  ...(hasDocker ? getDockerImageVariables(context) : {}),
79
+ ...(context.componentConfig.deploy
80
+ ? context.componentConfig.deploy.extraVars ?? {}
81
+ : {}),
80
82
  },
81
83
  environment: {
82
84
  ...context.environment.gitlabEnvironment,
@@ -87,6 +89,9 @@ export const getBaseDeploymentJob = (context: Context): JobWithoutScript => {
87
89
  }
88
90
  : {}),
89
91
  },
92
+ jobTags: context.componentConfig.deploy
93
+ ? context.componentConfig.deploy.jobTags
94
+ : undefined,
90
95
  };
91
96
  };
92
97
 
@@ -11,6 +11,16 @@ export type DeployConfigBase = {
11
11
  * wait for other components to deploy first, before doing this deployment
12
12
  */
13
13
  waitFor?: string[];
14
+
15
+ /**
16
+ * tags for the underlying job runner (e.g gitlab)
17
+ */
18
+ jobTags?: string[];
19
+
20
+ /**
21
+ * additional env vars for the deploy job
22
+ */
23
+ extraVars?: Record<string, string>;
14
24
  };
15
25
 
16
26
  export type AllowUnknownProps<T extends Record<string, unknown>> = T &
@@ -4,3 +4,14 @@ export const getBuildId = async () =>
4
4
  await exec("git describe --tags || git rev-parse HEAD").then((s) =>
5
5
  s.stdout.trim()
6
6
  );
7
+
8
+ // thx chat gpt
9
+ /**
10
+ * returns the last tagged version string Major.minor.patch
11
+ * returns 0.0.0 if there is no tag
12
+ */
13
+ export const getCurrentVersionString = async () => {
14
+ return await exec(
15
+ 'latest_tag=$(git describe --tags --abbrev=0 2>/dev/null); if [ -z "$latest_tag" ]; then echo "0.0.0"; else echo "${latest_tag#v}"; fi | cut -d "." -f 1-3'
16
+ ).then((s) => s.stdout.trim());
17
+ };
@@ -1,5 +1,5 @@
1
1
  import type { CommitInfo } from "../../types";
2
- import { getBuildId } from "./getBuildId";
2
+ import { getBuildId, getCurrentVersionString } from "./getBuildId";
3
3
  export const getBaseCommitInfo = async (): Promise<
4
4
  Omit<CommitInfo, "trigger">
5
5
  > => ({
@@ -9,4 +9,5 @@ export const getBaseCommitInfo = async (): Promise<
9
9
  : "unknown",
10
10
  buildTime: new Date().toISOString(),
11
11
  buildId: await getBuildId(),
12
+ currentVersion: await getCurrentVersionString(),
12
13
  });
@@ -6,6 +6,10 @@ import type { AllCatladderJobs } from "../createAllJobs";
6
6
 
7
7
  type AllGitlabJobs = Record<string, GitlabJobDef>;
8
8
 
9
+ const removeUndefined = <T extends Record<string, unknown>>(obj: T): T =>
10
+ Object.fromEntries(
11
+ Object.entries(obj).filter(([, value]) => value !== undefined)
12
+ ) as T;
9
13
  const getFullJobName = (
10
14
  name: string,
11
15
  componentName: string,
@@ -47,6 +51,7 @@ export const makeGitlabJob = (
47
51
  needsOtherComponent,
48
52
  name,
49
53
  needs,
54
+ jobTags,
50
55
  ...job
51
56
  }: CatladderJob<string>,
52
57
  allJobs: AllCatladderJobs
@@ -95,8 +100,9 @@ export const makeGitlabJob = (
95
100
  envMode !== "none" ? env : undefined
96
101
  );
97
102
 
98
- const gitlabJob = {
103
+ const gitlabJob: GitlabJobDef = removeUndefined({
99
104
  ...job,
105
+ tags: jobTags,
100
106
  stage,
101
107
  environment: job.environment?.on_stop
102
108
  ? {
@@ -113,7 +119,7 @@ export const makeGitlabJob = (
113
119
  needs: gitlabNeeds,
114
120
  retry: BASE_RETRY,
115
121
  interruptible: true,
116
- };
122
+ });
117
123
 
118
124
  return [fullJobName, gitlabJob];
119
125
  };
@@ -35,6 +35,7 @@ export type CommitInfo = {
35
35
  buildTime: string;
36
36
  buildId: string;
37
37
  trigger: PipelineTrigger;
38
+ currentVersion: string;
38
39
  };
39
40
 
40
41
  type Workspace = {
@@ -77,6 +77,7 @@ export type GitlabJobDef = {
77
77
  environment?: GitlabEnvironment;
78
78
  allow_failure?: boolean;
79
79
  parallel?: number;
80
+ tags?: string[];
80
81
  trigger?: {
81
82
  strategy: "depend";
82
83
  include: Array<{
package/src/types/jobs.ts CHANGED
@@ -109,4 +109,9 @@ export type CatladderJob<S = BaseStage> = {
109
109
  * We use the same shape as GitLab itself.
110
110
  */
111
111
  parallel?: number;
112
+
113
+ /**
114
+ * tags for the underlying job runner (e.g gitlab)
115
+ */
116
+ jobTags?: string[];
112
117
  };
@@ -6,7 +6,7 @@ export function notNil<TValue>(
6
6
  return value !== null && value !== undefined;
7
7
  }
8
8
 
9
- export const ensureArray = <T>(s: T | T[]): T[] | null =>
9
+ export const ensureArray = <T>(s: undefined | T | T[]): T[] | null =>
10
10
  isNil(s) ? null : Array.isArray(s) ? s : [s];
11
11
 
12
12
  // see https://github.com/lodash/lodash/issues/5384