@catladder/pipeline 0.0.0-refactor-deploy-5f0bbd8a → 0.0.0-refactor-image-ca767657

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/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 +387 -300
  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 +5 -0
  17. package/dist/deploy/base/deploy.js +106 -0
  18. package/dist/deploy/base/index.d.ts +10 -8
  19. package/dist/deploy/base/index.js +7 -106
  20. package/dist/deploy/base/rollback.d.ts +4 -2
  21. package/dist/deploy/base/rollback.js +10 -8
  22. package/dist/deploy/base/stop.d.ts +5 -0
  23. package/dist/deploy/base/stop.js +41 -0
  24. package/dist/deploy/cloudRun/deployJob.js +29 -27
  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 -26
  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 -85
  37. package/dist/types/jobs.d.ts +3 -3
  38. package/examples/__snapshots__/cloud-run-memory-limit.ts.snap +16 -16
  39. package/examples/__snapshots__/cloud-run-no-cpu-throttling.ts.snap +16 -16
  40. package/examples/__snapshots__/cloud-run-non-public.ts.snap +16 -16
  41. package/examples/__snapshots__/cloud-run-with-sql-reuse-db.ts.snap +32 -32
  42. package/examples/__snapshots__/cloud-run-with-sql.ts.snap +48 -48
  43. package/examples/__snapshots__/custom-build-job-with-tests.ts.snap +16 -16
  44. package/examples/__snapshots__/custom-build-job.ts.snap +16 -16
  45. package/examples/__snapshots__/custom-sbom-java.ts.snap +16 -16
  46. package/examples/__snapshots__/kubernetes-application-customization.ts.snap +0 -36
  47. package/examples/__snapshots__/kubernetes-with-cloud-sql-legacy.ts.snap +0 -36
  48. package/examples/__snapshots__/kubernetes-with-cloud-sql.ts.snap +0 -36
  49. package/examples/__snapshots__/kubernetes-with-jobs.ts.snap +0 -72
  50. package/examples/__snapshots__/kubernetes-with-mongodb.ts.snap +0 -36
  51. package/examples/__snapshots__/meteor-kubernetes.ts.snap +0 -36
  52. package/examples/__snapshots__/native-app.ts.snap +16 -16
  53. package/examples/__snapshots__/node-build-with-custom-image.ts.snap +16 -16
  54. package/examples/__snapshots__/rails-k8s-with-worker.ts.snap +0 -36
  55. package/package.json +4 -2
  56. package/scripts/generate-gitlab-ci-types.ts +51 -0
  57. package/src/build/base/{createBuildJob.ts → createAppBuildJob.ts} +3 -2
  58. package/src/build/base/index.ts +35 -0
  59. package/src/build/custom/buildJob.ts +32 -45
  60. package/src/build/docker.ts +14 -17
  61. package/src/build/node/buildJob.ts +50 -61
  62. package/src/build/node/meteor.ts +31 -36
  63. package/src/build/rails/build.ts +8 -10
  64. package/src/build/types.ts +4 -8
  65. package/src/context/getLabels.ts +1 -0
  66. package/src/deploy/base/deploy.ts +114 -0
  67. package/src/deploy/base/index.ts +21 -133
  68. package/src/deploy/base/rollback.ts +15 -3
  69. package/src/deploy/base/stop.ts +44 -0
  70. package/src/deploy/cloudRun/deployJob.ts +14 -16
  71. package/src/deploy/custom/deployJob.ts +17 -20
  72. package/src/deploy/dockerTag/deployJob.ts +6 -7
  73. package/src/deploy/kubernetes/deployJob.ts +17 -34
  74. package/src/deploy/kubernetes/mongodb.ts +3 -2
  75. package/src/pipeline/gitlab/createGitlabJobs.ts +3 -0
  76. package/src/types/gitlab-ci-yml.ts +892 -0
  77. package/src/types/gitlab-types.ts +49 -86
  78. package/src/types/jobs.ts +3 -4
  79. package/dist/build/base/createBuildJob.d.ts +0 -7
@@ -57,6 +57,7 @@ export const getDockerBuildVariables = (context: Context) => {
57
57
  };
58
58
 
59
59
  export const DOCKER_BUILD_JOB_NAME = "🔨 docker";
60
+
60
61
  export const getDockerJobBaseProps = (context: Context) => {
61
62
  return {
62
63
  image: getRunnerImage("docker-build"),
@@ -69,6 +70,8 @@ export const getDockerJobBaseProps = (context: Context) => {
69
70
  variables: getDockerBaseVariables(),
70
71
  };
71
72
  };
73
+
74
+ export type DockerBuildJobDefinition = Partial<CatladderJob>;
72
75
  export const createDockerBuildJobBase = (
73
76
  context: Context,
74
77
  { script, ...def }: Partial<CatladderJob>
@@ -90,20 +93,14 @@ export const createDockerBuildJobBase = (
90
93
 
91
94
  export const gitlabDockerLogin =
92
95
  "docker login --username gitlab-ci-token --password $CI_JOB_TOKEN $CI_REGISTRY";
93
- export const createDockerBuildJobDefault = (
94
- context: Context,
95
- { script, ...def }: Partial<CatladderJob>
96
- ): CatladderJob => {
97
- return createDockerBuildJobBase(context, {
98
- script: [
99
- ...(script || []),
100
- gitlabDockerLogin,
101
- "docker version",
102
- "docker build --network host --cache-from $DOCKER_CACHE_IMAGE --tag $DOCKER_IMAGE:$DOCKER_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/
103
- "docker push $DOCKER_IMAGE:$DOCKER_IMAGE_TAG",
104
- "docker tag $DOCKER_IMAGE:$DOCKER_IMAGE_TAG $DOCKER_CACHE_IMAGE",
105
- "docker push $DOCKER_CACHE_IMAGE",
106
- ],
107
- ...def,
108
- });
109
- };
96
+
97
+ export const getDockerBuildDefaultScript = (ensureDockerFileScript?: string) =>
98
+ [
99
+ ensureDockerFileScript,
100
+ gitlabDockerLogin,
101
+ "docker version",
102
+ "docker build --network host --cache-from $DOCKER_CACHE_IMAGE --tag $DOCKER_IMAGE:$DOCKER_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/
103
+ "docker push $DOCKER_IMAGE:$DOCKER_IMAGE_TAG",
104
+ "docker tag $DOCKER_IMAGE:$DOCKER_IMAGE_TAG $DOCKER_CACHE_IMAGE",
105
+ "docker push $DOCKER_CACHE_IMAGE",
106
+ ].filter(Boolean);
@@ -1,17 +1,14 @@
1
+ import { join } from "path";
2
+ import { getRunnerImage } from "../../runner";
1
3
  import type { Context } from "../../types/context";
4
+ import type { CatladderJob } from "../../types/jobs";
2
5
  import { ensureArray } from "../../utils";
3
- import { APP_BUILD_JOB_NAME } from "../base/constants";
4
- import { createBuildJob } from "../base/createBuildJob";
5
- import { createDockerBuildJobDefault, requiresDockerBuild } from "../docker";
6
- import { join } from "path";
6
+ import { createBuildJobs } from "../base";
7
+ import { getDockerBuildDefaultScript, requiresDockerBuild } from "../docker";
7
8
  import { isOfBuildType } from "../types";
8
9
  import { getNextCache, getNodeCache, getYarnCache } from "./cache";
9
10
  import { NODE_RUNNER_BUILD_VARIABLES } from "./constants";
10
11
  import { getDockerAppCopyAndBuildScript, getYarnInstall } from "./yarn";
11
- import type { CatladderJob } from "../../types/jobs";
12
- import { getRunnerImage } from "../../runner";
13
- import { createSbomBuildJob } from "../sbom";
14
- import { sbomDeactivated } from "../../deploy/sbom";
15
12
 
16
13
  export const createNodeBuildJobs = (context: Context): CatladderJob[] => {
17
14
  const buildConfig = context.componentConfig.build;
@@ -22,62 +19,54 @@ export const createNodeBuildJobs = (context: Context): CatladderJob[] => {
22
19
 
23
20
  const defaultImage = getRunnerImage("jobs-default");
24
21
  const yarnInstall = getYarnInstall(context);
25
- const appBuildJob: CatladderJob | null =
26
- buildConfig.buildCommand !== null
27
- ? createBuildJob(context, {
28
- image: buildConfig.jobImage ?? defaultImage,
29
- variables: {
30
- ...NODE_RUNNER_BUILD_VARIABLES,
31
- },
32
- cache: [
33
- ...(ensureArray(buildConfig.jobCache) ?? []),
34
- ...getNodeCache(context),
35
- ...getNextCache(context),
36
- ],
37
- script: [
38
- ...yarnInstall,
39
- ...(ensureArray(buildConfig.buildCommand) ?? []),
40
- ],
41
- artifacts: {
42
- paths: [
43
- join(context.componentConfig.dir, "__build_info.json"),
44
- join(context.componentConfig.dir, "dist"),
45
- join(context.componentConfig.dir, ".next"),
46
- ...(buildConfig.artifactsPaths?.map((path) =>
47
- join(context.componentConfig.dir, path)
48
- ) ?? []),
22
+
23
+ return createBuildJobs(context, {
24
+ appBuild:
25
+ buildConfig.buildCommand !== null
26
+ ? {
27
+ image: buildConfig.jobImage ?? defaultImage,
28
+ variables: {
29
+ ...NODE_RUNNER_BUILD_VARIABLES,
30
+ },
31
+ cache: [
32
+ ...(ensureArray(buildConfig.jobCache) ?? []),
33
+ ...getNodeCache(context),
34
+ ...getNextCache(context),
49
35
  ],
50
- expire_in: "1 day",
51
- },
52
- jobTags: buildConfig.jobTags,
53
- })
54
- : null;
55
- return [
56
- ...(appBuildJob ? [appBuildJob] : []),
57
- ...(requiresDockerBuild(context)
58
- ? [
59
- createDockerBuildJobDefault(context, {
60
36
  script: [
61
- buildConfig.type === "node-static" ||
62
- buildConfig.type === "storybook"
63
- ? "ensureNginxDockerfile"
64
- : "ensureNodeDockerfile",
37
+ ...yarnInstall,
38
+ ...(ensureArray(buildConfig.buildCommand) ?? []),
65
39
  ],
66
- cache: [...getYarnCache(context, "pull")],
67
- variables: {
68
- // only required for non static
69
- DOCKER_COPY_AND_INSTALL_APP:
70
- getDockerAppCopyAndBuildScript(context),
71
- DOCKER_COPY_WORKSPACE_FILES:
72
- context.packageManagerInfo?.pathsToCopyInDocker
73
- .map((dir) => `COPY --chown=node:node ${dir} /app/${dir}`)
74
- ?.join("\n"),
40
+ artifacts: {
41
+ paths: [
42
+ join(context.componentConfig.dir, "__build_info.json"),
43
+ join(context.componentConfig.dir, "dist"),
44
+ join(context.componentConfig.dir, ".next"),
45
+ ...(buildConfig.artifactsPaths?.map((path) =>
46
+ join(context.componentConfig.dir, path)
47
+ ) ?? []),
48
+ ],
49
+ expire_in: "1 day",
75
50
  },
51
+ jobTags: buildConfig.jobTags,
52
+ }
53
+ : undefined,
76
54
 
77
- needs: appBuildJob ? [APP_BUILD_JOB_NAME] : [],
78
- }),
79
- ]
80
- : []),
81
- ...(sbomDeactivated(context) ? [] : [createSbomBuildJob(context)]),
82
- ];
55
+ dockerBuild: {
56
+ script: getDockerBuildDefaultScript(
57
+ buildConfig.type === "node-static" || buildConfig.type === "storybook"
58
+ ? "ensureNginxDockerfile"
59
+ : "ensureNodeDockerfile"
60
+ ),
61
+ cache: [...getYarnCache(context, "pull")],
62
+ variables: {
63
+ // only required for non static
64
+ DOCKER_COPY_AND_INSTALL_APP: getDockerAppCopyAndBuildScript(context),
65
+ DOCKER_COPY_WORKSPACE_FILES:
66
+ context.packageManagerInfo?.pathsToCopyInDocker
67
+ .map((dir) => `COPY --chown=node:node ${dir} /app/${dir}`)
68
+ ?.join("\n"),
69
+ },
70
+ },
71
+ });
83
72
  };
@@ -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),
@@ -0,0 +1,114 @@
1
+ import {
2
+ getDockerImageVariables,
3
+ requiresDockerBuild,
4
+ } from "../../build/docker";
5
+ import { SBOM_BUILD_JOB_NAME } from "../../build/sbom";
6
+ import type { Context } from "../../types/context";
7
+ import type { CatladderJob } from "../../types/jobs";
8
+ import { sbomDeactivated } from "../sbom";
9
+ import { contextIsStoppable } from "../utils";
10
+ import { STOP_JOB_NAME } from "./stop";
11
+
12
+ import { DEPLOY_RUNNER_VARIABLES } from "./variables";
13
+
14
+ export const DEPLOY_JOB_NAME = "🚀 Deploy";
15
+
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 => {
24
+ const hasDocker = requiresDockerBuild(context);
25
+ const isStoppable = contextIsStoppable(context);
26
+
27
+ const autoStop =
28
+ context.environment.envType === "review"
29
+ ? "2 week"
30
+ : context.environment.envType === "dev"
31
+ ? "4 weeks"
32
+ : undefined;
33
+
34
+ // if auto or manual is configured explicitly, use that
35
+ const whenDeployDefined =
36
+ context.componentConfig.deploy && context.componentConfig.deploy.when
37
+ ? context.componentConfig.deploy.when
38
+ : undefined;
39
+ // otherwise auto deploy if env is not prod. If its prod, deploy automatically if stage is disabled
40
+ const whenDeployDefault =
41
+ context.environment.envType !== "prod"
42
+ ? "auto" // is not stage, auto deploy
43
+ : context.componentConfig.env?.stage === false
44
+ ? "auto" // is prod, but no staging, auto deploy
45
+ : "manual"; // manually deploy
46
+ const whenDeploy = whenDeployDefined ? whenDeployDefined : whenDeployDefault;
47
+
48
+ return {
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,
55
+ envMode: "stagePerEnv", // makes it easier to run manual tasks er env
56
+
57
+ needs: [
58
+ ...(sbomDeactivated(context)
59
+ ? []
60
+ : [{ job: SBOM_BUILD_JOB_NAME, artifacts: true }]),
61
+ ...(context.componentConfig.deploy
62
+ ? context.componentConfig.deploy.waitFor?.map((c) => ({
63
+ componentName: c,
64
+ job: DEPLOY_JOB_NAME,
65
+ artifacts: false,
66
+ })) ?? []
67
+ : []),
68
+ ],
69
+ // we don't want to deploy when there is a broken test
70
+ needsStages: [
71
+ {
72
+ stage: "build",
73
+ artifacts: hasDocker ? false : true, // we asume that no-docker deployments need build artifacts,
74
+ },
75
+ {
76
+ stage: "test",
77
+ artifacts: false,
78
+ },
79
+ ], // workaround for https://gitlab.com/gitlab-org/gitlab/-/issues/220758
80
+ rules: [
81
+ whenDeploy === "auto"
82
+ ? {
83
+ when: "on_success",
84
+ }
85
+ : {
86
+ when: "manual",
87
+ },
88
+ ],
89
+ allow_failure: whenDeploy === "manual" ? true : false,
90
+ stage: "deploy",
91
+ variables: {
92
+ ...DEPLOY_RUNNER_VARIABLES,
93
+ ...context.environment.envVars,
94
+ ...(hasDocker ? getDockerImageVariables(context) : {}),
95
+ ...context.environment.jobOnlyVars.deploy.envVars,
96
+ ...(context.componentConfig.deploy
97
+ ? context.componentConfig.deploy.extraVars ?? {}
98
+ : {}),
99
+ ...jobDefinition.variables,
100
+ },
101
+ environment: {
102
+ ...context.environment.gitlabEnvironment,
103
+ ...(isStoppable
104
+ ? {
105
+ on_stop: STOP_JOB_NAME,
106
+ auto_stop_in: autoStop,
107
+ }
108
+ : {}),
109
+ },
110
+ jobTags: context.componentConfig.deploy
111
+ ? context.componentConfig.deploy.jobTags
112
+ : undefined,
113
+ };
114
+ };
@@ -1,134 +1,22 @@
1
- import {
2
- getDockerImageVariables,
3
- requiresDockerBuild,
4
- } from "../../build/docker";
5
- import { SBOM_BUILD_JOB_NAME } from "../../build/sbom";
6
- import type { Context } from "../../types";
7
-
8
- import { sbomDeactivated } from "../sbom";
9
- import { contextIsStoppable } from "../utils";
10
- import type { JobWithoutScript } from "./types";
11
- import { DEPLOY_RUNNER_VARIABLES } from "./variables";
12
-
13
- export * from "./rollback";
14
- export const DEPLOY_JOB_NAME = "🚀 Deploy";
15
- export const STOP_JOB_NAME = "🛑 Stop ⚠️";
16
- export const ROLLBACK_JOB_NAME = "↩️ Rollback ⚠️";
17
-
18
- export const getBaseDeploymentJob = (context: Context): JobWithoutScript => {
19
- const hasDocker = requiresDockerBuild(context);
20
- const isStoppable = contextIsStoppable(context);
21
-
22
- const autoStop =
23
- context.environment.envType === "review"
24
- ? "2 week"
25
- : context.environment.envType === "dev"
26
- ? "4 weeks"
27
- : undefined;
28
-
29
- // if auto or manual is configured explicitly, use that
30
- const whenDeployDefined =
31
- context.componentConfig.deploy && context.componentConfig.deploy.when
32
- ? context.componentConfig.deploy.when
33
- : undefined;
34
- // otherwise auto deploy if env is not prod. If its prod, deploy automatically if stage is disabled
35
- const whenDeployDefault =
36
- context.environment.envType !== "prod"
37
- ? "auto" // is not stage, auto deploy
38
- : context.componentConfig.env?.stage === false
39
- ? "auto" // is prod, but no staging, auto deploy
40
- : "manual"; // manually deploy
41
- const whenDeploy = whenDeployDefined ? whenDeployDefined : whenDeployDefault;
42
-
43
- return {
44
- name: DEPLOY_JOB_NAME,
45
- envMode: "stagePerEnv", // makes it easier to run manual tasks er env
46
-
47
- needs: [
48
- ...(sbomDeactivated(context)
49
- ? []
50
- : [{ job: SBOM_BUILD_JOB_NAME, artifacts: true }]),
51
- ...(context.componentConfig.deploy
52
- ? context.componentConfig.deploy.waitFor?.map((c) => ({
53
- componentName: c,
54
- job: DEPLOY_JOB_NAME,
55
- artifacts: false,
56
- })) ?? []
57
- : []),
58
- ],
59
- // we don't want to deploy when there is a broken test
60
- needsStages: [
61
- {
62
- stage: "build",
63
- artifacts: hasDocker ? false : true, // we asume that no-docker deployments need build artifacts,
64
- },
65
- {
66
- stage: "test",
67
- artifacts: false,
68
- },
69
- ], // workaround for https://gitlab.com/gitlab-org/gitlab/-/issues/220758
70
- rules: [
71
- whenDeploy === "auto"
72
- ? {
73
- when: "on_success",
74
- }
75
- : {
76
- when: "manual",
77
- },
78
- ],
79
- allow_failure: whenDeploy === "manual" ? true : false,
80
- stage: "deploy",
81
- variables: {
82
- ...DEPLOY_RUNNER_VARIABLES,
83
- ...context.environment.envVars,
84
- ...(hasDocker ? getDockerImageVariables(context) : {}),
85
- ...context.environment.jobOnlyVars.deploy.envVars,
86
- ...(context.componentConfig.deploy
87
- ? context.componentConfig.deploy.extraVars ?? {}
88
- : {}),
89
- },
90
- environment: {
91
- ...context.environment.gitlabEnvironment,
92
- ...(isStoppable
93
- ? {
94
- on_stop: STOP_JOB_NAME,
95
- auto_stop_in: autoStop,
96
- }
97
- : {}),
98
- },
99
- jobTags: context.componentConfig.deploy
100
- ? context.componentConfig.deploy.jobTags
101
- : undefined,
102
- };
103
- };
104
-
105
- export const getBaseDeploymentStopJob = (
106
- context: Context
107
- ): JobWithoutScript => {
108
- return {
109
- name: STOP_JOB_NAME,
110
- envMode: "stagePerEnv", // makes it easier to run manual tasks er env
111
- needs: [], // can be executed even if the deploy job failed
112
- rules: [
113
- {
114
- if: "$CI_COMMIT_BRANCH =~ /^[0-9]+\\.([0-9]+|x)\\.x$/", // automatic on hotfix branches
115
- when: "on_success",
116
- allow_failure: true,
117
- },
118
- {
119
- when: "manual",
120
- allow_failure: true,
121
- },
122
- ],
123
- variables: {
124
- ...DEPLOY_RUNNER_VARIABLES,
125
- ...context.environment.jobOnlyVars.deploy.envVars,
126
- GIT_STRATEGY: "none",
127
- },
128
- stage: "stop",
129
- environment: {
130
- ...context.environment.gitlabEnvironment,
131
- action: "stop",
132
- },
133
- };
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
+ ];
134
22
  };
@@ -1,11 +1,20 @@
1
- import { ROLLBACK_JOB_NAME } from ".";
2
1
  import type { Context } from "../../types/context";
3
- import type { JobWithoutScript } from "./types";
2
+ import type { CatladderJob } from "../../types/jobs";
4
3
  import { DEPLOY_RUNNER_VARIABLES } from "./variables";
5
4
 
6
- export const getBaseRollbackJob = (context: Context): JobWithoutScript => {
5
+ export const ROLLBACK_JOB_NAME = "↩️ Rollback ⚠️";
6
+
7
+ export type RollbackJobDefinition = Pick<
8
+ CatladderJob,
9
+ "script" | "variables" | "image"
10
+ >;
11
+ export const createRollbackJob = (
12
+ context: Context,
13
+ jobDefinition: RollbackJobDefinition
14
+ ): CatladderJob => {
7
15
  return {
8
16
  name: ROLLBACK_JOB_NAME,
17
+ image: jobDefinition.image,
9
18
  envMode: "stagePerEnv", // makes it easier to run manual tasks er env
10
19
  needs: [], // can be executed even if the deploy job failed
11
20
  rules: [
@@ -18,11 +27,14 @@ export const getBaseRollbackJob = (context: Context): JobWithoutScript => {
18
27
  ...DEPLOY_RUNNER_VARIABLES,
19
28
  ...context.environment.jobOnlyVars.deploy.envVars,
20
29
  GIT_STRATEGY: "none",
30
+ ...jobDefinition.variables,
21
31
  },
22
32
  stage: "rollback",
23
33
  environment: {
24
34
  ...context.environment.gitlabEnvironment,
25
35
  action: "access",
26
36
  },
37
+
38
+ script: jobDefinition.script,
27
39
  };
28
40
  };