@catladder/pipeline 1.111.5 → 1.113.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 (72) hide show
  1. package/dist/build/base/createAppBuildJob.d.ts +8 -0
  2. package/dist/build/base/{createBuildJob.js → createAppBuildJob.js} +3 -3
  3. package/dist/build/base/index.d.ts +8 -0
  4. package/dist/build/base/index.js +57 -0
  5. package/dist/build/custom/buildJob.js +19 -22
  6. package/dist/build/docker.d.ts +2 -4
  7. package/dist/build/docker.js +4 -39
  8. package/dist/build/node/buildJob.js +30 -32
  9. package/dist/build/node/meteor.js +19 -21
  10. package/dist/build/rails/build.js +12 -19
  11. package/dist/build/types.d.ts +4 -3
  12. package/dist/bundles/catladder-gitlab/index.js +1 -1
  13. package/dist/constants.js +1 -1
  14. package/dist/context/getLabels.d.ts +1 -0
  15. package/dist/context/getLabels.js +1 -0
  16. package/dist/deploy/base/deploy.d.ts +3 -2
  17. package/dist/deploy/base/deploy.js +9 -4
  18. package/dist/deploy/base/index.d.ts +10 -3
  19. package/dist/deploy/base/index.js +37 -16
  20. package/dist/deploy/base/rollback.d.ts +3 -2
  21. package/dist/deploy/base/rollback.js +8 -6
  22. package/dist/deploy/base/stop.d.ts +3 -2
  23. package/dist/deploy/base/stop.js +8 -6
  24. package/dist/deploy/cloudRun/deployJob.js +28 -26
  25. package/dist/deploy/custom/deployJob.js +14 -11
  26. package/dist/deploy/dockerTag/deployJob.js +15 -5
  27. package/dist/deploy/kubernetes/deployJob.js +14 -14
  28. package/dist/deploy/kubernetes/mongodb.d.ts +1 -1
  29. package/dist/deploy/kubernetes/mongodb.js +8 -7
  30. package/dist/deploy/types/index.d.ts +1 -1
  31. package/dist/pipeline/gitlab/createGitlabJobs.d.ts +1 -0
  32. package/dist/pipeline/gitlab/createGitlabJobs.js +4 -1
  33. package/dist/tsconfig.tsbuildinfo +1 -1
  34. package/dist/types/gitlab-ci-yml.d.ts +769 -0
  35. package/dist/types/gitlab-ci-yml.js +9 -0
  36. package/dist/types/gitlab-types.d.ts +12 -82
  37. package/dist/types/jobs.d.ts +3 -3
  38. package/examples/__snapshots__/cloud-run-memory-limit.ts.snap +4 -4
  39. package/examples/__snapshots__/cloud-run-no-cpu-throttling.ts.snap +4 -4
  40. package/examples/__snapshots__/cloud-run-non-public.ts.snap +4 -4
  41. package/examples/__snapshots__/cloud-run-with-sql-reuse-db.ts.snap +8 -8
  42. package/examples/__snapshots__/cloud-run-with-sql.ts.snap +24 -24
  43. package/examples/__snapshots__/custom-build-job-with-tests.ts.snap +4 -4
  44. package/examples/__snapshots__/custom-build-job.ts.snap +4 -4
  45. package/examples/__snapshots__/custom-sbom-java.ts.snap +4 -4
  46. package/examples/__snapshots__/native-app.ts.snap +4 -4
  47. package/examples/__snapshots__/node-build-with-custom-image.ts.snap +4 -4
  48. package/package.json +4 -2
  49. package/scripts/generate-gitlab-ci-types.ts +51 -0
  50. package/src/build/base/{createBuildJob.ts → createAppBuildJob.ts} +3 -2
  51. package/src/build/base/index.ts +35 -0
  52. package/src/build/custom/buildJob.ts +32 -45
  53. package/src/build/docker.ts +14 -17
  54. package/src/build/node/buildJob.ts +50 -61
  55. package/src/build/node/meteor.ts +31 -36
  56. package/src/build/rails/build.ts +8 -10
  57. package/src/build/types.ts +4 -8
  58. package/src/context/getLabels.ts +1 -0
  59. package/src/deploy/base/deploy.ts +16 -2
  60. package/src/deploy/base/index.ts +22 -3
  61. package/src/deploy/base/rollback.ts +13 -2
  62. package/src/deploy/base/stop.ts +13 -4
  63. package/src/deploy/cloudRun/deployJob.ts +13 -15
  64. package/src/deploy/custom/deployJob.ts +17 -20
  65. package/src/deploy/dockerTag/deployJob.ts +6 -7
  66. package/src/deploy/kubernetes/deployJob.ts +17 -23
  67. package/src/deploy/kubernetes/mongodb.ts +3 -2
  68. package/src/pipeline/gitlab/createGitlabJobs.ts +3 -0
  69. package/src/types/gitlab-ci-yml.ts +892 -0
  70. package/src/types/gitlab-types.ts +49 -83
  71. package/src/types/jobs.ts +3 -4
  72. package/dist/build/base/createBuildJob.d.ts +0 -7
@@ -5,14 +5,11 @@ import type { Context } from "../../types/context";
5
5
 
6
6
  import type { CatladderJob } from "../../types/jobs";
7
7
 
8
- import { APP_BUILD_JOB_NAME } from "../base/constants";
9
- import { createBuildJob } from "../base/createBuildJob";
10
- import { createDockerBuildJobDefault } from "../docker";
8
+ import { createBuildJobs } from "../base";
9
+ import { getDockerBuildDefaultScript } from "../docker";
11
10
  import { isOfBuildType } from "../types";
12
11
  import { getNodeCache } from "./cache";
13
12
  import { getYarnInstall } from "./yarn";
14
- import { sbomDeactivated } from "../../deploy/sbom";
15
- import { createSbomBuildJob } from "../sbom";
16
13
 
17
14
  const getMeteorCache = (context: Context): GitlabJobCache[] => [
18
15
  {
@@ -37,42 +34,40 @@ export const createMeteorBuildJobs = (context: Context): CatladderJob[] => {
37
34
  }
38
35
 
39
36
  const yarnInstall = getYarnInstall(context);
40
- const appBuildJob: CatladderJob | null =
41
- buildConfig.buildCommand !== null
42
- ? createBuildJob(context, {
43
- cache: [...getNodeCache(context), ...getMeteorCache(context)],
44
- image: getRunnerImage("jobs-meteor"),
45
- variables: {
46
- METEOR_DISABLE_OPTIMISTIC_CACHING: "1", // see https://forums.meteor.com/t/veeery-long-building-time-inside-docker-container/58673/17?u=macrozone
47
- },
48
- script: [
49
- ...yarnInstall,
50
37
 
51
- 'echo "add healthcheck package"',
52
- "meteor add panter:healthroute --allow-superuser",
53
- "meteor add qualia:prod-shell --allow-superuser",
38
+ return createBuildJobs(context, {
39
+ appBuild:
40
+ buildConfig.buildCommand !== null
41
+ ? {
42
+ cache: [...getNodeCache(context), ...getMeteorCache(context)],
43
+ image: getRunnerImage("jobs-meteor"),
44
+ variables: {
45
+ METEOR_DISABLE_OPTIMISTIC_CACHING: "1", // see https://forums.meteor.com/t/veeery-long-building-time-inside-docker-container/58673/17?u=macrozone
46
+ },
47
+ script: [
48
+ ...yarnInstall,
54
49
 
55
- 'TOOL_NODE_FLAGS="--max_old_space_size=3584 --min_semi_space_size=8 --max_semi_space_size=256 --optimize_for_size" meteor build ./dist --architecture os.linux.x86_64 --allow-superuser --server-only --directory',
50
+ 'echo "add healthcheck package"',
51
+ "meteor add panter:healthroute --allow-superuser",
52
+ "meteor add qualia:prod-shell --allow-superuser",
56
53
 
57
- "cp ./__build_info.json ./dist/bundle/programs/server",
58
- ],
59
- artifacts: {
60
- paths: [
61
- context.componentConfig.dir + "/__build_info.json",
62
- context.componentConfig.dir + "/dist",
54
+ 'TOOL_NODE_FLAGS="--max_old_space_size=3584 --min_semi_space_size=8 --max_semi_space_size=256 --optimize_for_size" meteor build ./dist --architecture os.linux.x86_64 --allow-superuser --server-only --directory',
55
+
56
+ "cp ./__build_info.json ./dist/bundle/programs/server",
63
57
  ],
64
- },
65
- })
66
- : null;
67
- return [
68
- ...(appBuildJob ? [appBuildJob] : []),
69
- createDockerBuildJobDefault(context, {
70
- script: ["ensureMeteorDockerfile"],
58
+ artifacts: {
59
+ paths: [
60
+ context.componentConfig.dir + "/__build_info.json",
61
+ context.componentConfig.dir + "/dist",
62
+ ],
63
+ },
64
+ }
65
+ : undefined,
66
+ dockerBuild: {
67
+ script: getDockerBuildDefaultScript("ensureMeteorDockerfile"),
71
68
  variables: {
72
69
  METEOR_INSTALL_SCRIPTS: buildConfig.installScripts ? "true" : "",
73
70
  },
74
- needs: appBuildJob ? [APP_BUILD_JOB_NAME] : [],
75
- }),
76
- ...(sbomDeactivated(context) ? [] : [createSbomBuildJob(context)]),
77
- ];
71
+ },
72
+ });
78
73
  };
@@ -1,9 +1,8 @@
1
1
  import type { Context } from "../..";
2
- import { isOfBuildType } from "../types";
3
2
  import type { CatladderJob } from "../../types/jobs";
4
- import { createDockerBuildJobBase, gitlabDockerLogin } from "../docker";
5
- import { sbomDeactivated } from "../../deploy/sbom";
6
- import { createSbomBuildJob } from "../sbom";
3
+ import { createBuildJobs } from "../base";
4
+ import { gitlabDockerLogin } from "../docker";
5
+ import { isOfBuildType } from "../types";
7
6
 
8
7
  export const createRailsBuildJobs = (context: Context): CatladderJob[] => {
9
8
  const buildConfig = context.componentConfig.build;
@@ -17,9 +16,9 @@ export const createRailsBuildJobs = (context: Context): CatladderJob[] => {
17
16
  const packEnvArgs = Object.entries(cnbConf?.buildVars ?? {})
18
17
  .map(([k, v]) => `--env '${k}${v ? `=${v}` : ""}'`)
19
18
  .join(" ");
20
-
21
- return [
22
- createDockerBuildJobBase(context, {
19
+ return createBuildJobs(context, {
20
+ appBuild: undefined,
21
+ dockerBuild: {
23
22
  variables: {
24
23
  ...context.environment.jobOnlyVars.build.envVars,
25
24
  ...context.componentConfig.build.extraVars,
@@ -38,7 +37,6 @@ export const createRailsBuildJobs = (context: Context): CatladderJob[] => {
38
37
  cnbConf?.packExtraArgs?.join(" ") ?? ""
39
38
  }`,
40
39
  ],
41
- }),
42
- ...(sbomDeactivated(context) ? [] : [createSbomBuildJob(context)]),
43
- ];
40
+ },
41
+ });
44
42
  };
@@ -1,9 +1,5 @@
1
- import type {
2
- Artifacts,
3
- EnvVars,
4
- GitlabJobImage,
5
- GitlabJobService,
6
- } from "../types";
1
+ import type { Artifacts, EnvVars, GitlabJobImage } from "../types";
2
+ import type { Services } from "../types/gitlab-ci-yml";
7
3
 
8
4
  import type { CatladderJob } from "../types/jobs";
9
5
 
@@ -168,9 +164,9 @@ export type BuildConfigCustom = Omit<
168
164
  type: "custom";
169
165
  jobImage: GitlabJobImage;
170
166
  /**
171
- * {@link GitlabJobService}s used in lint, test, audit, and build jobs.
167
+ * {@link Services}s used in lint, test, audit, and build jobs.
172
168
  */
173
- jobServices?: GitlabJobService[];
169
+ jobServices?: Services;
174
170
 
175
171
  docker: BuildConfigCustomDocker;
176
172
 
@@ -10,6 +10,7 @@ const sanitize = (value?: string) => {
10
10
  export const getLabels = (context: Context) => {
11
11
  const labels = {
12
12
  "customer-name": sanitize(context.fullConfig.customerName),
13
+ "component-name": sanitize(context.componentName),
13
14
  "app-name": sanitize(context.fullConfig.appName),
14
15
  "env-type": sanitize(context.environment.envType),
15
16
  "env-name": sanitize(context.environment.shortName),
@@ -4,15 +4,23 @@ import {
4
4
  } from "../../build/docker";
5
5
  import { SBOM_BUILD_JOB_NAME } from "../../build/sbom";
6
6
  import type { Context } from "../../types/context";
7
+ import type { CatladderJob } from "../../types/jobs";
7
8
  import { sbomDeactivated } from "../sbom";
8
9
  import { contextIsStoppable } from "../utils";
9
10
  import { STOP_JOB_NAME } from "./stop";
10
- import type { JobWithoutScript } from "./types";
11
+
11
12
  import { DEPLOY_RUNNER_VARIABLES } from "./variables";
12
13
 
13
14
  export const DEPLOY_JOB_NAME = "🚀 Deploy";
14
15
 
15
- export const getBaseDeploymentJob = (context: Context): JobWithoutScript => {
16
+ export type DeployJobDefinition = Pick<
17
+ CatladderJob,
18
+ "script" | "variables" | "image" | "cache" | "artifacts" | "services"
19
+ >;
20
+ export const createDeployJob = (
21
+ context: Context,
22
+ jobDefinition: DeployJobDefinition
23
+ ): CatladderJob => {
16
24
  const hasDocker = requiresDockerBuild(context);
17
25
  const isStoppable = contextIsStoppable(context);
18
26
 
@@ -39,6 +47,11 @@ export const getBaseDeploymentJob = (context: Context): JobWithoutScript => {
39
47
 
40
48
  return {
41
49
  name: DEPLOY_JOB_NAME,
50
+ script: jobDefinition.script,
51
+ image: jobDefinition.image,
52
+ cache: jobDefinition.cache,
53
+ artifacts: jobDefinition.artifacts,
54
+ services: jobDefinition.services,
42
55
  envMode: "stagePerEnv", // makes it easier to run manual tasks er env
43
56
 
44
57
  needs: [
@@ -83,6 +96,7 @@ export const getBaseDeploymentJob = (context: Context): JobWithoutScript => {
83
96
  ...(context.componentConfig.deploy
84
97
  ? context.componentConfig.deploy.extraVars ?? {}
85
98
  : {}),
99
+ ...jobDefinition.variables,
86
100
  },
87
101
  environment: {
88
102
  ...context.environment.gitlabEnvironment,
@@ -1,3 +1,22 @@
1
- export * from "./deploy";
2
- export * from "./rollback";
3
- export * from "./stop";
1
+ import type { Context } from "../../types/context";
2
+ import type { CatladderJob } from "../../types/jobs";
3
+ import { createDeployJob, type DeployJobDefinition } from "./deploy";
4
+ import { createRollbackJob, type RollbackJobDefinition } from "./rollback";
5
+ import { createStopJob, type StopJobDefinition } from "./stop";
6
+
7
+ export const createDeployementJobs = (
8
+ context: Context,
9
+ definitions: {
10
+ deploy: DeployJobDefinition;
11
+ stop?: StopJobDefinition;
12
+ rollback?: RollbackJobDefinition;
13
+ }
14
+ ): CatladderJob[] => {
15
+ return [
16
+ createDeployJob(context, definitions.deploy),
17
+ ...(definitions.stop ? [createStopJob(context, definitions.stop)] : []),
18
+ ...(definitions.rollback
19
+ ? [createRollbackJob(context, definitions.rollback)]
20
+ : []),
21
+ ];
22
+ };
@@ -1,12 +1,20 @@
1
1
  import type { Context } from "../../types/context";
2
- import type { JobWithoutScript } from "./types";
2
+ import type { CatladderJob } from "../../types/jobs";
3
3
  import { DEPLOY_RUNNER_VARIABLES } from "./variables";
4
4
 
5
5
  export const ROLLBACK_JOB_NAME = "↩️ Rollback ⚠️";
6
6
 
7
- export const getBaseRollbackJob = (context: Context): JobWithoutScript => {
7
+ export type RollbackJobDefinition = Pick<
8
+ CatladderJob,
9
+ "script" | "variables" | "image"
10
+ >;
11
+ export const createRollbackJob = (
12
+ context: Context,
13
+ jobDefinition: RollbackJobDefinition
14
+ ): CatladderJob => {
8
15
  return {
9
16
  name: ROLLBACK_JOB_NAME,
17
+ image: jobDefinition.image,
10
18
  envMode: "stagePerEnv", // makes it easier to run manual tasks er env
11
19
  needs: [], // can be executed even if the deploy job failed
12
20
  rules: [
@@ -19,11 +27,14 @@ export const getBaseRollbackJob = (context: Context): JobWithoutScript => {
19
27
  ...DEPLOY_RUNNER_VARIABLES,
20
28
  ...context.environment.jobOnlyVars.deploy.envVars,
21
29
  GIT_STRATEGY: "none",
30
+ ...jobDefinition.variables,
22
31
  },
23
32
  stage: "rollback",
24
33
  environment: {
25
34
  ...context.environment.gitlabEnvironment,
26
35
  action: "access",
27
36
  },
37
+
38
+ script: jobDefinition.script,
28
39
  };
29
40
  };
@@ -1,13 +1,20 @@
1
1
  import type { Context } from "../../types/context";
2
- import type { JobWithoutScript } from "./types";
2
+ import type { CatladderJob } from "../../types/jobs";
3
+
3
4
  import { DEPLOY_RUNNER_VARIABLES } from "./variables";
4
5
  export const STOP_JOB_NAME = "🛑 Stop ⚠️";
5
6
 
6
- export const getBaseDeploymentStopJob = (
7
- context: Context
8
- ): JobWithoutScript => {
7
+ export type StopJobDefinition = Pick<
8
+ CatladderJob,
9
+ "script" | "variables" | "image"
10
+ >;
11
+ export const createStopJob = (
12
+ context: Context,
13
+ jobDefinition: StopJobDefinition
14
+ ): CatladderJob => {
9
15
  return {
10
16
  name: STOP_JOB_NAME,
17
+ image: jobDefinition.image,
11
18
  envMode: "stagePerEnv", // makes it easier to run manual tasks er env
12
19
  needs: [], // can be executed even if the deploy job failed
13
20
  rules: [
@@ -25,11 +32,13 @@ export const getBaseDeploymentStopJob = (
25
32
  ...DEPLOY_RUNNER_VARIABLES,
26
33
  ...context.environment.jobOnlyVars.deploy.envVars,
27
34
  GIT_STRATEGY: "none",
35
+ ...jobDefinition.variables,
28
36
  },
29
37
  stage: "stop",
30
38
  environment: {
31
39
  ...context.environment.gitlabEnvironment,
32
40
  action: "stop",
33
41
  },
42
+ script: jobDefinition.script,
34
43
  };
35
44
  };
@@ -6,7 +6,12 @@ import { getLabels } from "../../context/getLabels";
6
6
  import { getRunnerImage } from "../../runner";
7
7
  import type { Context } from "../../types/context";
8
8
  import type { CatladderJob } from "../../types/jobs";
9
- import { getBaseDeploymentJob, getBaseDeploymentStopJob } from "../base";
9
+ import { allowFailureInScripts } from "../../utils/gitlab";
10
+ import { createDeployementJobs } from "../base";
11
+ import {
12
+ getDependencyTrackDeleteScript,
13
+ getDependencyTrackUploadScript,
14
+ } from "../sbom";
10
15
  import type {
11
16
  DeployConfigCloudRun,
12
17
  DeployConfigCloudRunJob,
@@ -14,18 +19,13 @@ import type {
14
19
  DeployConfigCloudRunService,
15
20
  } from "../types";
16
21
  import { isOfDeployType } from "../types";
17
- import { gcloudServiceAccountLoginCommands } from "./utils/gcloudServiceAccountLoginCommands";
22
+ import { createArgsString } from "./utils/createArgsString";
18
23
  import {
19
24
  getDatabaseCreateScript,
20
25
  getDatabaseDeleteScript,
21
26
  } from "./utils/database";
22
- import { allowFailureInScripts } from "../../utils/gitlab";
27
+ import { gcloudServiceAccountLoginCommands } from "./utils/gcloudServiceAccountLoginCommands";
23
28
  import { getCloudRunJobName } from "./utils/jobName";
24
- import { createArgsString } from "./utils/createArgsString";
25
- import {
26
- getDependencyTrackDeleteScript,
27
- getDependencyTrackUploadScript,
28
- } from "../sbom";
29
29
 
30
30
  const setExtraVarsScripts = (deployConfig: DeployConfigCloudRun) => [
31
31
  `export GCLOUD_PROJECT_NUMBER=$(gcloud projects describe ${deployConfig.projectId} --format="value(projectNumber)")`,
@@ -43,7 +43,6 @@ export const createGoogleCloudRunDeployJobs = (
43
43
  // should not happen
44
44
  throw new Error("deploy config is wrong");
45
45
  }
46
- const baseDeploymentJob = getBaseDeploymentJob(context);
47
46
 
48
47
  const fullAppName = `${context.fullConfig.customerName}-${context.fullConfig.appName}`;
49
48
  const dockerUrl = `${deployConfig.region}-docker.pkg.dev/${deployConfig.projectId}/catladder-deploy/${fullAppName}`;
@@ -257,8 +256,8 @@ export const createGoogleCloudRunDeployJobs = (
257
256
  : []),
258
257
  ...getDependencyTrackDeleteScript(context),
259
258
  ];
260
- return [
261
- merge({}, baseDeploymentJob, getDockerJobBaseProps(context), {
259
+ return createDeployementJobs(context, {
260
+ deploy: merge(getDockerJobBaseProps(context), {
262
261
  artifacts: { paths: ["____envvars.yaml"] },
263
262
  variables: {
264
263
  CLOUDSDK_CORE_DISABLE_PROMPTS: "1",
@@ -271,13 +270,12 @@ export const createGoogleCloudRunDeployJobs = (
271
270
  image: getRunnerImage("gcloud"),
272
271
  script: deployScripts,
273
272
  }),
274
-
275
- merge({}, getBaseDeploymentStopJob(context), {
273
+ stop: {
276
274
  image: getRunnerImage("gcloud"),
277
275
  variables: {
278
276
  CLOUDSDK_CORE_DISABLE_PROMPTS: "1",
279
277
  },
280
278
  script: allowFailureInScripts(stopScripts),
281
- }),
282
- ];
279
+ },
280
+ });
283
281
  };
@@ -1,15 +1,13 @@
1
- import { merge } from "lodash";
2
-
3
1
  import { getYarnInstall } from "../../build/node/yarn";
4
2
  import { getRunnerImage } from "../../runner";
5
3
  import type { Context } from "../../types/context";
6
4
  import type { CatladderJob } from "../../types/jobs";
7
- import { getBaseDeploymentJob, getBaseDeploymentStopJob } from "../base";
8
- import { isOfDeployType } from "../types";
5
+ import { createDeployementJobs } from "../base";
9
6
  import {
10
7
  getDependencyTrackDeleteScript,
11
8
  getDependencyTrackUploadScript,
12
9
  } from "../sbom";
10
+ import { isOfDeployType } from "../types";
13
11
 
14
12
  export const createCustomDeployJobs = (context: Context): CatladderJob[] => {
15
13
  const deployConfig = context.componentConfig.deploy;
@@ -20,11 +18,10 @@ export const createCustomDeployJobs = (context: Context): CatladderJob[] => {
20
18
  // should not happen
21
19
  throw new Error("deploy config is not custom");
22
20
  }
23
- const baseDeploymentJob = getBaseDeploymentJob(context);
24
21
  // FIXME: custom deploy currently assumes yarn-based project
25
22
  const yarnInstall = getYarnInstall(context, { noCustomPostInstall: true });
26
- return [
27
- merge({}, baseDeploymentJob, {
23
+ return createDeployementJobs(context, {
24
+ deploy: {
28
25
  image: deployConfig.jobImage ?? getRunnerImage("jobs-default"),
29
26
  cache: deployConfig.jobCache ?? [],
30
27
  script: [
@@ -33,17 +30,17 @@ export const createCustomDeployJobs = (context: Context): CatladderJob[] => {
33
30
  ...deployConfig.script,
34
31
  ...getDependencyTrackUploadScript(context),
35
32
  ],
36
- }),
37
- ...(deployConfig.stopScript
38
- ? [
39
- merge({}, getBaseDeploymentStopJob(context), {
40
- image: deployConfig.jobImage ?? getRunnerImage("jobs-default"),
41
- script: [
42
- ...deployConfig.stopScript,
43
- ...getDependencyTrackDeleteScript(context),
44
- ],
45
- }),
46
- ]
47
- : []),
48
- ];
33
+ variables: {},
34
+ },
35
+ stop: deployConfig.stopScript
36
+ ? {
37
+ image: deployConfig.jobImage ?? getRunnerImage("jobs-default"),
38
+ script: [
39
+ ...deployConfig.stopScript,
40
+ ...getDependencyTrackDeleteScript(context),
41
+ ],
42
+ variables: {},
43
+ }
44
+ : undefined,
45
+ });
49
46
  };
@@ -1,9 +1,8 @@
1
- import { merge } from "lodash";
2
1
  import { getDockerJobBaseProps, gitlabDockerLogin } from "../../build/docker";
3
2
 
4
3
  import type { Context } from "../../types/context";
5
4
  import type { CatladderJob } from "../../types/jobs";
6
- import { getBaseDeploymentJob } from "../base";
5
+ import { createDeployementJobs } from "../base";
7
6
  import { isOfDeployType } from "../types";
8
7
 
9
8
  export const createDockerTagDeployJobs = (context: Context): CatladderJob[] => {
@@ -15,10 +14,10 @@ export const createDockerTagDeployJobs = (context: Context): CatladderJob[] => {
15
14
  // should not happen
16
15
  throw new Error("deploy config is not dockerTag");
17
16
  }
18
- const baseDeploymentJob = getBaseDeploymentJob(context);
19
17
  const tag = deployConfig.tag;
20
- return [
21
- merge({}, baseDeploymentJob, getDockerJobBaseProps(context), {
18
+ return createDeployementJobs(context, {
19
+ deploy: {
20
+ ...getDockerJobBaseProps(context),
22
21
  script: [
23
22
  gitlabDockerLogin,
24
23
  `docker pull $DOCKER_IMAGE:$DOCKER_IMAGE_TAG`,
@@ -26,6 +25,6 @@ export const createDockerTagDeployJobs = (context: Context): CatladderJob[] => {
26
25
  `docker push $DOCKER_IMAGE:${tag}`,
27
26
  `echo "pushed as $DOCKER_IMAGE:${tag}"`,
28
27
  ],
29
- }),
30
- ];
28
+ },
29
+ });
31
30
  };
@@ -1,20 +1,15 @@
1
1
  import { dump } from "js-yaml";
2
- import { merge } from "lodash";
3
- import { getSecretVarNameForContext } from "../..";
4
2
  import { getRunnerImage } from "../../runner";
5
3
  import type { Context } from "../../types/context";
6
4
  import type { CatladderJob } from "../../types/jobs";
7
- import {
8
- getBaseDeploymentJob,
9
- getBaseDeploymentStopJob,
10
- getBaseRollbackJob,
11
- } from "../base";
12
- import { isOfDeployType } from "../types";
13
- import { createKubeValues } from "./kubeValues";
5
+ import { createDeployementJobs } from "../base";
14
6
  import {
15
7
  getDependencyTrackDeleteScript,
16
8
  getDependencyTrackUploadScript,
17
9
  } from "../sbom";
10
+ import { isOfDeployType } from "../types";
11
+ import { createKubeValues } from "./kubeValues";
12
+ import { getSecretVarNameForContext } from "../../context/getEnvironmentVariables";
18
13
 
19
14
  export const createKubernetesDeployJobs = (
20
15
  context: Context
@@ -29,8 +24,7 @@ export const createKubernetesDeployJobs = (
29
24
  }
30
25
 
31
26
  const kubeValues = createKubeValues(context);
32
-
33
- const shared = {
27
+ const shared: Pick<CatladderJob, "image" | "variables"> = {
34
28
  image: getRunnerImage("kubernetes"),
35
29
  variables: {
36
30
  ...context.environment.envVars,
@@ -53,9 +47,6 @@ export const createKubernetesDeployJobs = (
53
47
  },
54
48
  };
55
49
 
56
- const baseDeploymentJob = getBaseDeploymentJob(context);
57
- const baseStopJob = getBaseDeploymentStopJob(context);
58
- const baseRollbackJob = getBaseRollbackJob(context);
59
50
  const clusterName = `kube-${context.environment.fullName}`;
60
51
  const connectContext = [
61
52
  `kubectl config set-cluster "${clusterName}" --server="$${getSecretVarNameForContext(
@@ -72,8 +63,10 @@ export const createKubernetesDeployJobs = (
72
63
  `kubectl config set-context "${clusterName}" --cluster="${clusterName}" --user="${clusterName}" --namespace="${context.environment.envVars.KUBE_NAMESPACE}"`,
73
64
  `kubectl config use-context "${clusterName}"`,
74
65
  ];
75
- return [
76
- merge({}, baseDeploymentJob, shared, {
66
+
67
+ return createDeployementJobs(context, {
68
+ deploy: {
69
+ ...shared,
77
70
  script: [
78
71
  ...connectContext,
79
72
  "kubernetesCreateSecret",
@@ -81,17 +74,18 @@ export const createKubernetesDeployJobs = (
81
74
  ...getDependencyTrackUploadScript(context),
82
75
  "echo deployment successful 😻",
83
76
  ],
84
- }),
85
- merge({}, baseStopJob, shared, {
77
+ },
78
+ stop: {
79
+ ...shared,
86
80
  script: [
87
81
  ...connectContext,
88
82
  "kubernetesDelete",
89
83
  ...getDependencyTrackDeleteScript(context),
90
84
  ],
91
- }),
92
-
93
- merge({}, baseRollbackJob, shared, {
85
+ },
86
+ rollback: {
87
+ ...shared,
94
88
  script: [...connectContext, "kubernetesRollback"],
95
- }),
96
- ];
89
+ },
90
+ });
97
91
  };
@@ -1,6 +1,7 @@
1
1
  import { range } from "lodash";
2
- import type { Context } from "../..";
3
- import { getSecretVarNameForContext, isOfDeployType } from "../..";
2
+ import { getSecretVarNameForContext } from "../../context/getEnvironmentVariables";
3
+ import type { Context } from "../../types/context";
4
+ import { isOfDeployType } from "../types";
4
5
 
5
6
  const getCredentialString = (context: Context) =>
6
7
  `root:$${getSecretVarNameForContext(context, "MONGODB_ROOT_PASSWORD")}@`;
@@ -3,6 +3,7 @@ import { BASE_RETRY } from "../../defaults";
3
3
  import type { GitlabJobDef } from "../../types";
4
4
  import type { CatladderJob, CatladderJobNeed } from "../../types/jobs";
5
5
  import type { AllCatladderJobs } from "../createAllJobs";
6
+ import { notNil } from "../../utils";
6
7
 
7
8
  type AllGitlabJobs = Record<string, GitlabJobDef>;
8
9
 
@@ -52,6 +53,7 @@ export const makeGitlabJob = (
52
53
  name,
53
54
  needs,
54
55
  jobTags,
56
+ script,
55
57
  ...job
56
58
  }: CatladderJob<string>,
57
59
  allJobs: AllCatladderJobs
@@ -106,6 +108,7 @@ export const makeGitlabJob = (
106
108
 
107
109
  const gitlabJob: GitlabJobDef = removeUndefined({
108
110
  ...job,
111
+ script: script?.filter(notNil),
109
112
  tags: jobTags,
110
113
  stage,
111
114
  environment: job.environment?.on_stop