@catladder/pipeline 0.0.0-node16-ddfae617 → 0.0.0-prettier-cbceeed9

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 (275) hide show
  1. package/bin/catladder-gitlab-dev.js +3 -0
  2. package/bin/catladder-gitlab.js +1 -1
  3. package/dist/build/base/createBuildJob.d.ts +2 -2
  4. package/dist/build/base/createBuildJob.js +15 -30
  5. package/dist/build/base/writeBuildInfo.d.ts +2 -0
  6. package/dist/build/base/{getBuildInfo.js → writeBuildInfo.js} +3 -6
  7. package/dist/build/custom/buildJob.d.ts +3 -0
  8. package/dist/build/custom/buildJob.js +83 -0
  9. package/dist/build/custom/index.d.ts +3 -0
  10. package/dist/build/custom/index.js +40 -0
  11. package/dist/build/docker.d.ts +33 -9
  12. package/dist/build/docker.js +51 -54
  13. package/dist/build/index.d.ts +6 -5
  14. package/dist/build/index.js +20 -6
  15. package/dist/build/node/buildJob.d.ts +2 -2
  16. package/dist/build/node/buildJob.js +3 -25
  17. package/dist/build/node/cache.d.ts +2 -2
  18. package/dist/build/node/cache.js +19 -22
  19. package/dist/build/node/index.d.ts +1 -1
  20. package/dist/build/node/index.js +3 -16
  21. package/dist/build/node/meteor.d.ts +1 -1
  22. package/dist/build/node/meteor.js +9 -20
  23. package/dist/build/node/testJob.d.ts +2 -2
  24. package/dist/build/node/testJob.js +7 -21
  25. package/dist/build/node/yarn.d.ts +1 -1
  26. package/dist/build/node/yarn.js +14 -15
  27. package/dist/build/rails/build.d.ts +3 -0
  28. package/dist/build/rails/build.js +51 -0
  29. package/dist/build/rails/index.d.ts +3 -0
  30. package/dist/build/rails/index.js +41 -0
  31. package/dist/build/rails/test.d.ts +3 -0
  32. package/dist/build/rails/test.js +94 -0
  33. package/dist/build/types.d.ts +84 -9
  34. package/dist/build/types.js +0 -4
  35. package/dist/bundles/catladder-gitlab/index.js +32979 -0
  36. package/dist/catladder-gitlab.js +7 -26
  37. package/dist/config/{configruedEnvs.test.d.ts → __tests__/configruedEnvs.test.d.ts} +0 -0
  38. package/dist/config/{configruedEnvs.test.js → __tests__/configruedEnvs.test.js} +10 -12
  39. package/dist/config/configruedEnvs.d.ts +1 -1
  40. package/dist/config/configruedEnvs.js +7 -22
  41. package/dist/config/index.js +0 -4
  42. package/dist/config/readConfig.d.ts +1 -1
  43. package/dist/config/readConfig.js +2 -13
  44. package/dist/constants.js +1 -1
  45. package/dist/context/{resolveReferences.test.d.ts → __tests__/resolveReferences.test.d.ts} +0 -0
  46. package/dist/context/__tests__/resolveReferences.test.js +336 -0
  47. package/dist/context/getEnvConfig.d.ts +2 -0
  48. package/dist/context/getEnvConfig.js +18 -0
  49. package/dist/context/getEnvType.d.ts +4 -0
  50. package/dist/context/getEnvType.js +13 -0
  51. package/dist/context/getEnvironment.d.ts +3 -0
  52. package/dist/{pipeline/createChildPipeline.test.js → context/getEnvironment.js} +42 -84
  53. package/dist/context/getEnvironmentContext.d.ts +4 -0
  54. package/dist/context/getEnvironmentContext.js +33 -0
  55. package/dist/context/getEnvironmentVariables.d.ts +10 -0
  56. package/dist/context/getEnvironmentVariables.js +260 -0
  57. package/dist/context/getLabels.d.ts +8 -0
  58. package/dist/context/getLabels.js +38 -0
  59. package/dist/context/index.d.ts +5 -6
  60. package/dist/context/index.js +158 -208
  61. package/dist/context/resolveReferences.d.ts +1 -3
  62. package/dist/context/resolveReferences.js +213 -52
  63. package/dist/defaults/index.d.ts +1 -1
  64. package/dist/deploy/base.d.ts +4 -2
  65. package/dist/deploy/base.js +38 -33
  66. package/dist/deploy/cloudRun/deployJob.d.ts +3 -0
  67. package/dist/deploy/cloudRun/deployJob.js +238 -0
  68. package/dist/deploy/cloudRun/index.d.ts +4 -0
  69. package/dist/deploy/cloudRun/index.js +112 -0
  70. package/dist/deploy/cloudRun/utils/createArgsString.d.ts +11 -0
  71. package/dist/deploy/cloudRun/utils/createArgsString.js +55 -0
  72. package/dist/deploy/cloudRun/utils/database.d.ts +4 -0
  73. package/dist/deploy/cloudRun/utils/database.js +64 -0
  74. package/dist/deploy/cloudRun/utils/gcloudServiceAccountLoginCommands.d.ts +2 -0
  75. package/dist/deploy/cloudRun/utils/gcloudServiceAccountLoginCommands.js +10 -0
  76. package/dist/deploy/cloudRun/utils/jobName.d.ts +1 -0
  77. package/dist/deploy/cloudRun/utils/jobName.js +8 -0
  78. package/dist/deploy/custom/deployJob.d.ts +2 -2
  79. package/dist/deploy/custom/deployJob.js +10 -16
  80. package/dist/deploy/custom/index.d.ts +2 -1
  81. package/dist/deploy/custom/index.js +14 -19
  82. package/dist/deploy/dockerTag/deployJob.d.ts +3 -0
  83. package/dist/deploy/dockerTag/deployJob.js +24 -0
  84. package/dist/deploy/dockerTag/index.d.ts +2 -0
  85. package/dist/deploy/dockerTag/index.js +17 -0
  86. package/dist/deploy/index.d.ts +12 -8
  87. package/dist/deploy/index.js +7 -20
  88. package/dist/deploy/kubernetes/additionalSecretKeys.d.ts +4 -0
  89. package/dist/deploy/kubernetes/additionalSecretKeys.js +24 -0
  90. package/dist/deploy/kubernetes/cloudSql/index.d.ts +13 -0
  91. package/dist/deploy/kubernetes/cloudSql/index.js +30 -0
  92. package/dist/deploy/kubernetes/deployJob.d.ts +2 -2
  93. package/dist/deploy/kubernetes/deployJob.js +17 -91
  94. package/dist/deploy/kubernetes/index.d.ts +3 -1
  95. package/dist/deploy/kubernetes/index.js +42 -4
  96. package/dist/deploy/kubernetes/kubeEnv.d.ts +9 -0
  97. package/dist/deploy/kubernetes/kubeEnv.js +72 -0
  98. package/dist/deploy/kubernetes/kubeValues.d.ts +97 -0
  99. package/dist/deploy/kubernetes/kubeValues.js +124 -0
  100. package/dist/deploy/kubernetes/mongodb.d.ts +18 -5
  101. package/dist/deploy/kubernetes/mongodb.js +96 -10
  102. package/dist/deploy/kubernetes/processSecretsAsFiles.d.ts +25 -21
  103. package/dist/deploy/kubernetes/processSecretsAsFiles.js +2 -10
  104. package/dist/deploy/types/base.d.ts +14 -0
  105. package/dist/deploy/types/base.js +3 -0
  106. package/dist/deploy/types/custom.d.ts +33 -0
  107. package/dist/deploy/types/custom.js +3 -0
  108. package/dist/deploy/types/dockerTag.d.ts +10 -0
  109. package/dist/deploy/types/dockerTag.js +3 -0
  110. package/dist/deploy/types/googleCloudRun.d.ts +121 -0
  111. package/dist/deploy/types/googleCloudRun.js +3 -0
  112. package/dist/deploy/types/index.d.ts +22 -0
  113. package/dist/deploy/types/index.js +31 -0
  114. package/dist/deploy/types/kubernetes.d.ts +276 -0
  115. package/dist/deploy/types/kubernetes.js +3 -0
  116. package/dist/deploy/utils.d.ts +2 -2
  117. package/dist/deploy/utils.js +3 -10
  118. package/dist/index.js +0 -10
  119. package/dist/pipeline/commitInfo/getBuildId.d.ts +1 -0
  120. package/dist/pipeline/commitInfo/getBuildId.js +135 -0
  121. package/dist/pipeline/commitInfo/getCommitInfo.d.ts +2 -0
  122. package/dist/pipeline/commitInfo/getCommitInfo.js +140 -0
  123. package/dist/pipeline/createAllJobs.d.ts +8 -0
  124. package/dist/{build/tests/storybook.test.js → pipeline/createAllJobs.js} +54 -104
  125. package/dist/pipeline/createChildPipeline.d.ts +2 -2
  126. package/dist/pipeline/createChildPipeline.js +40 -121
  127. package/dist/pipeline/createJobsForComponent.d.ts +3 -0
  128. package/dist/pipeline/{createJobs.js → createJobsForComponent.js} +33 -192
  129. package/dist/pipeline/gitlab/createGitlabJobs.d.ts +14 -0
  130. package/dist/pipeline/gitlab/createGitlabJobs.js +260 -0
  131. package/dist/pipeline/index.d.ts +1 -1
  132. package/dist/pipeline/index.js +1 -5
  133. package/dist/pipeline/packageManager.d.ts +1 -1
  134. package/dist/pipeline/packageManager.js +20 -173
  135. package/dist/pipeline/yarn/yarnUtils.d.ts +4 -0
  136. package/dist/pipeline/yarn/yarnUtils.js +193 -0
  137. package/dist/rules/index.d.ts +3 -1
  138. package/dist/rules/index.js +7 -6
  139. package/dist/runner/index.d.ts +2 -3
  140. package/dist/runner/index.js +0 -3
  141. package/dist/tsconfig.tsbuildinfo +1 -1
  142. package/dist/types/config.d.ts +19 -25
  143. package/dist/types/config.js +6 -16
  144. package/dist/types/context.d.ts +16 -3
  145. package/dist/types/environmentContext.d.ts +28 -0
  146. package/dist/types/environmentContext.js +3 -0
  147. package/dist/types/gitlab-types.d.ts +39 -7
  148. package/dist/types/index.js +0 -6
  149. package/dist/types/jobs.d.ts +25 -17
  150. package/dist/types/jobs.js +1 -1
  151. package/dist/types/pipeline.d.ts +1 -1
  152. package/dist/types/utils.d.ts +1 -0
  153. package/dist/types/utils.js +3 -0
  154. package/dist/utils/gitlab.d.ts +5 -0
  155. package/dist/utils/gitlab.js +48 -0
  156. package/dist/utils/index.js +5 -15
  157. package/examples/__snapshots__/cloud-run-memory-limit.ts.snap +1560 -0
  158. package/examples/__snapshots__/cloud-run-no-cpu-throttling.ts.snap +1560 -0
  159. package/examples/__snapshots__/cloud-run-non-public.ts.snap +1560 -0
  160. package/examples/__snapshots__/cloud-run-with-sql-reuse-db.ts.snap +3092 -0
  161. package/examples/__snapshots__/cloud-run-with-sql.ts.snap +3103 -0
  162. package/examples/__snapshots__/custom-build-job.ts.snap +1162 -0
  163. package/examples/__snapshots__/custom-envs.ts.snap +261 -0
  164. package/examples/__snapshots__/kubernetes-application-customization.ts.snap +2280 -0
  165. package/examples/__snapshots__/kubernetes-with-jobs.ts.snap +4077 -0
  166. package/examples/__snapshots__/rails-k8s-with-worker.ts.snap +1911 -0
  167. package/examples/__snapshots__/wait-for-other-deploy.ts.snap +1626 -0
  168. package/examples/__utils__/helpers.ts +14 -0
  169. package/examples/cloud-run-memory-limit.ts +28 -0
  170. package/examples/cloud-run-no-cpu-throttling.ts +33 -0
  171. package/examples/cloud-run-non-public.ts +27 -0
  172. package/examples/cloud-run-with-sql-reuse-db.ts +54 -0
  173. package/examples/cloud-run-with-sql.ts +61 -0
  174. package/examples/custom-build-job.ts +28 -0
  175. package/examples/custom-envs.ts +31 -0
  176. package/examples/kubernetes-application-customization.ts +57 -0
  177. package/examples/kubernetes-with-jobs.ts +68 -0
  178. package/examples/rails-k8s-with-worker.ts +95 -0
  179. package/examples/wait-for-other-deploy.ts +36 -0
  180. package/package.json +16 -13
  181. package/scripts/bundle +2 -0
  182. package/src/build/base/createBuildJob.ts +12 -5
  183. package/src/build/base/{getBuildInfo.ts → writeBuildInfo.ts} +2 -2
  184. package/src/build/custom/buildJob.ts +64 -0
  185. package/src/build/custom/index.ts +7 -0
  186. package/src/build/docker.ts +58 -33
  187. package/src/build/index.ts +24 -5
  188. package/src/build/node/buildJob.ts +2 -2
  189. package/src/build/node/cache.ts +19 -8
  190. package/src/build/node/index.ts +1 -1
  191. package/src/build/node/meteor.ts +8 -2
  192. package/src/build/node/testJob.ts +4 -2
  193. package/src/build/node/yarn.ts +21 -10
  194. package/src/build/rails/build.ts +38 -0
  195. package/src/build/rails/index.ts +8 -0
  196. package/src/build/rails/test.ts +86 -0
  197. package/src/build/types.ts +97 -2
  198. package/src/catladder-gitlab.ts +4 -2
  199. package/src/config/{configruedEnvs.test.ts → __tests__/configruedEnvs.test.ts} +3 -3
  200. package/src/config/configruedEnvs.ts +2 -7
  201. package/src/config/readConfig.ts +1 -1
  202. package/src/context/{resolveReferences.test.ts → __tests__/resolveReferences.test.ts} +23 -38
  203. package/src/context/getEnvConfig.ts +21 -0
  204. package/src/context/getEnvType.ts +17 -0
  205. package/src/context/getEnvironment.ts +40 -0
  206. package/src/context/getEnvironmentContext.ts +57 -0
  207. package/src/context/getEnvironmentVariables.ts +155 -0
  208. package/src/context/getLabels.ts +20 -0
  209. package/src/context/index.ts +28 -193
  210. package/src/context/resolveReferences.ts +35 -31
  211. package/src/defaults/index.ts +1 -1
  212. package/src/deploy/base.ts +43 -19
  213. package/src/deploy/cloudRun/deployJob.ts +276 -0
  214. package/src/deploy/cloudRun/index.ts +95 -0
  215. package/src/deploy/cloudRun/utils/createArgsString.ts +26 -0
  216. package/src/deploy/cloudRun/utils/database.ts +55 -0
  217. package/src/deploy/cloudRun/utils/gcloudServiceAccountLoginCommands.ts +14 -0
  218. package/src/deploy/cloudRun/utils/jobName.ts +2 -0
  219. package/src/deploy/custom/deployJob.ts +13 -3
  220. package/src/deploy/custom/index.ts +9 -1
  221. package/src/deploy/dockerTag/deployJob.ts +31 -0
  222. package/src/deploy/dockerTag/index.ts +9 -0
  223. package/src/deploy/index.ts +26 -17
  224. package/src/deploy/kubernetes/additionalSecretKeys.ts +23 -0
  225. package/src/deploy/kubernetes/cloudSql/index.ts +28 -0
  226. package/src/deploy/kubernetes/deployJob.ts +21 -78
  227. package/src/deploy/kubernetes/index.ts +42 -1
  228. package/src/deploy/kubernetes/kubeEnv.ts +48 -0
  229. package/src/deploy/kubernetes/kubeValues.ts +96 -0
  230. package/src/deploy/kubernetes/mongodb.ts +104 -7
  231. package/src/deploy/kubernetes/processSecretsAsFiles.ts +1 -1
  232. package/src/deploy/types/base.ts +17 -0
  233. package/src/deploy/types/custom.ts +36 -0
  234. package/src/deploy/types/dockerTag.ts +12 -0
  235. package/src/deploy/types/googleCloudRun.ts +179 -0
  236. package/src/deploy/types/index.ts +28 -0
  237. package/src/deploy/types/kubernetes.ts +301 -0
  238. package/src/deploy/utils.ts +6 -2
  239. package/src/pipeline/commitInfo/getBuildId.ts +6 -0
  240. package/src/pipeline/commitInfo/getCommitInfo.ts +12 -0
  241. package/src/pipeline/createAllJobs.ts +38 -0
  242. package/src/pipeline/createChildPipeline.ts +9 -20
  243. package/src/pipeline/createJobsForComponent.ts +64 -0
  244. package/src/pipeline/gitlab/createGitlabJobs.ts +149 -0
  245. package/src/pipeline/index.ts +1 -1
  246. package/src/pipeline/packageManager.ts +4 -38
  247. package/src/pipeline/yarn/yarnUtils.ts +37 -0
  248. package/src/rules/index.ts +9 -6
  249. package/src/runner/index.ts +2 -1
  250. package/src/types/config.ts +26 -13
  251. package/src/types/context.ts +23 -2
  252. package/src/types/environmentContext.ts +33 -0
  253. package/src/types/gitlab-types.ts +36 -6
  254. package/src/types/jobs.ts +30 -6
  255. package/src/types/pipeline.ts +1 -1
  256. package/src/types/utils.ts +7 -0
  257. package/src/utils/gitlab.ts +23 -0
  258. package/tsconfig.json +3 -1
  259. package/dist/build/base/getBuildInfo.d.ts +0 -2
  260. package/dist/build/tests/storybook.test.d.ts +0 -1
  261. package/dist/context/resolveReferences.test.js +0 -141
  262. package/dist/deploy/kubernetes/cloudsql.d.ts +0 -6
  263. package/dist/deploy/kubernetes/cloudsql.js +0 -16
  264. package/dist/deploy/types.d.ts +0 -196
  265. package/dist/deploy/types.js +0 -16
  266. package/dist/pipeline/createChildPipeline.test.d.ts +0 -1
  267. package/dist/pipeline/createJobs.d.ts +0 -3
  268. package/dist/pipeline/gitlab/makeGitlabJob.d.ts +0 -8
  269. package/dist/pipeline/gitlab/makeGitlabJob.js +0 -45
  270. package/src/build/tests/storybook.test.ts +0 -54
  271. package/src/deploy/kubernetes/cloudsql.ts +0 -12
  272. package/src/deploy/types.ts +0 -189
  273. package/src/pipeline/createChildPipeline.test.ts +0 -49
  274. package/src/pipeline/createJobs.ts +0 -195
  275. package/src/pipeline/gitlab/makeGitlabJob.ts +0 -16
@@ -1,16 +1,16 @@
1
1
  import { dump } from "js-yaml";
2
2
  import { merge } from "lodash";
3
- import { DeployConfigKubernetesValues } from "..";
4
3
  import { getSecretVarNameForContext } from "../..";
5
4
  import { getRunnerImage } from "../../runner";
6
- import { Context } from "../../types/context";
7
- import { CatladderJob } from "../../types/jobs";
8
- import { mergeWithMergingArrays } from "../../utils";
9
- import { getBaseDeploymentJob, getBaseDeploymentStopJob } from "../base";
5
+ import type { Context } from "../../types/context";
6
+ import type { CatladderJob } from "../../types/jobs";
7
+ import {
8
+ getBaseDeploymentJob,
9
+ getBaseDeploymentStopJob,
10
+ getBaseRollbackJob,
11
+ } from "../base";
10
12
  import { isOfDeployType } from "../types";
11
- import { createCloudsqlBaseConfig } from "./cloudsql";
12
- import { createMongodbBaseConfig } from "./mongodb";
13
- import { processSecretsAsFiles } from "./processSecretsAsFiles";
13
+ import { createKubeValues } from "./kubeValues";
14
14
 
15
15
  export const createKubernetesDeployJobs = (
16
16
  context: Context
@@ -24,71 +24,7 @@ export const createKubernetesDeployJobs = (
24
24
  throw new Error("deploy config is not kubernetes");
25
25
  }
26
26
 
27
- const allEnvVars = context.environment.envVars;
28
- /**
29
- * separate by secrets and public.
30
- * we evalulate the actual values later, but want to store the secrets in kubernetes secrets
31
- */
32
- const env = Object.entries(allEnvVars).reduce<{
33
- secret: Record<string, string>;
34
- public: Record<string, string>;
35
- }>(
36
- (acc, [key, value]) => {
37
- if (String(value)?.startsWith("$CL_")) {
38
- acc.secret = {
39
- ...acc.secret,
40
- [key]: value,
41
- };
42
- return acc;
43
- }
44
- acc.public = {
45
- ...acc.public,
46
- [key]: value,
47
- };
48
- return acc;
49
- },
50
- {
51
- secret: {},
52
- public: {},
53
- }
54
- );
55
-
56
- const defaultAppConfig: DeployConfigKubernetesValues["application"] = {
57
- host: context.environment.host,
58
- command: context.componentConfig.build.startCommand,
59
- livenessProbe: {
60
- httpGet: {
61
- path: deployConfig.values?.application?.healthRoute ?? "__health",
62
- },
63
- },
64
- readinessProbe: {
65
- httpGet: {
66
- path: deployConfig.values?.application?.healthRoute ?? "__health",
67
- },
68
- },
69
- startupProbe: {
70
- httpGet: {
71
- path: deployConfig.values?.application?.healthRoute ?? "__health",
72
- },
73
- },
74
- };
75
-
76
- const defaultKubeValues = {
77
- application: defaultAppConfig,
78
-
79
- env: env,
80
- ...(deployConfig.values?.cloudsql?.enabled
81
- ? createCloudsqlBaseConfig(context)
82
- : {}),
83
- ...(deployConfig.values?.mongodb?.enabled
84
- ? createMongodbBaseConfig(context)
85
- : {}),
86
- };
87
-
88
- const kubeValues = processSecretsAsFiles(
89
- mergeWithMergingArrays(defaultKubeValues, deployConfig.values)
90
- );
91
-
27
+ const kubeValues = createKubeValues(context);
92
28
  const kubernetesEnvironment = {
93
29
  namespace: context.environment.envVars.KUBE_NAMESPACE,
94
30
  };
@@ -96,28 +32,28 @@ export const createKubernetesDeployJobs = (
96
32
  image: getRunnerImage("kubernetes"),
97
33
  variables: {
98
34
  ...context.environment.envVars,
35
+ RELEASE_NAME: context.environment.fullName,
99
36
  HELM_EXPERIMENTAL_OCI: "1",
100
- IMAGE_PULL_SECRET: `gitlab-registry-${context.componentName}`,
37
+ KUBE_DOCKER_IMAGE_PULL_SECRET: `gitlab-registry-${context.componentName}`,
101
38
  KUBE_VALUES: dump(kubeValues, {
102
39
  lineWidth: -1,
103
40
  quotingType: "'",
104
41
  forceQuotes: true,
105
42
  }),
106
- HELM_GITLAB_CHART_NAME: "the-panter-chart",
43
+ HELM_GITLAB_CHART_NAME:
44
+ deployConfig.chartName ?? "/helm-charts/the-panter-chart",
107
45
  HELM_ARGS: [
108
46
  ...(deployConfig.debug ? ["--debug"] : []),
109
47
  ...(deployConfig.additionalHelmArgs ?? []),
110
48
  ].join(" "),
111
49
  COMPONENT_NAME: context.componentName,
112
50
  BUILD_ID: context.commitInfo?.buildId,
113
- // TODO: unify with docker build stage
114
- IMAGE_NAME: context.environment.shortName + "/" + context.componentName,
115
- IMAGE_TAG: "$CI_COMMIT_SHA",
116
51
  },
117
52
  };
118
53
 
119
54
  const baseDeploymentJob = getBaseDeploymentJob(context);
120
55
  const baseStopJob = getBaseDeploymentStopJob(context);
56
+ const baseRollbackJob = getBaseRollbackJob(context);
121
57
  const clusterName = `kube-${context.environment.fullName}`;
122
58
  const connectContext = [
123
59
  `kubectl config set-cluster "${clusterName}" --server="$${getSecretVarNameForContext(
@@ -152,5 +88,12 @@ export const createKubernetesDeployJobs = (
152
88
  kubernetes: kubernetesEnvironment,
153
89
  },
154
90
  }),
91
+
92
+ merge({}, baseRollbackJob, shared, {
93
+ script: [...connectContext, "kubernetesRollback"],
94
+ environment: {
95
+ kubernetes: kubernetesEnvironment,
96
+ },
97
+ }),
155
98
  ];
156
99
  };
@@ -1 +1,42 @@
1
- export * from "./deployJob";
1
+ import slugify from "slugify";
2
+ import type { DeployTypeDefinition } from "..";
3
+ import { getKubernetesNamespace } from "..";
4
+ import { additionalKubernetesSecretKeys } from "./additionalSecretKeys";
5
+ import { createKubernetesDeployJobs } from "./deployJob";
6
+ export * from "./cloudSql";
7
+ export const KUBERNETES_DEPLOY_TYPE: DeployTypeDefinition<"kubernetes"> = {
8
+ jobs: createKubernetesDeployJobs,
9
+ defaults: () => ({}),
10
+ additionalSecretKeys: additionalKubernetesSecretKeys,
11
+ getAdditionalEnvVars: ({
12
+ componentName,
13
+ fullConfig,
14
+ deployConfigRaw,
15
+ env,
16
+ envType,
17
+ commitInfo,
18
+ }) => {
19
+ const KUBE_APP_NAME_PREFIX =
20
+ envType === "review" && commitInfo ? `${commitInfo.reviewSlug}-` : "";
21
+ const KUBE_APP_NAME = `${KUBE_APP_NAME_PREFIX}${componentName}`;
22
+ const KUBE_NAMESPACE = getKubernetesNamespace(fullConfig, env);
23
+ const componentSlug = slugify(componentName);
24
+ const envInUrl =
25
+ envType === "review" && commitInfo
26
+ ? `${commitInfo.reviewSlug}.${env}`
27
+ : env;
28
+
29
+ const domainCanonical =
30
+ (deployConfigRaw && deployConfigRaw.cluster?.domainCanonical) || // for convenience, we allow clusters to define a canonical domain, because a cluster has a fixed ip and you will usually have a domain pointing to that cluster
31
+ fullConfig.domainCanonical ||
32
+ "panter.cloud";
33
+ const HOST_CANONICAL = `${componentSlug}.${envInUrl}.${fullConfig.appName}.${fullConfig.customerName}.${domainCanonical}`; // default for kubernetes and rest
34
+
35
+ return {
36
+ KUBE_NAMESPACE,
37
+ KUBE_APP_NAME,
38
+ KUBE_APP_NAME_PREFIX,
39
+ HOST_CANONICAL,
40
+ };
41
+ },
42
+ };
@@ -0,0 +1,48 @@
1
+ import type { Context } from "../../types";
2
+ import { isOfDeployType } from "../types";
3
+
4
+ const shouldGoIntoSecrets = (key: string, value: string) => {
5
+ if (String(value)?.includes("$CL_")) {
6
+ return true;
7
+ }
8
+ return false;
9
+ };
10
+
11
+ /**
12
+ * separate by secrets and public.
13
+ * we evalulate the actual values later, but want to store the secrets in kubernetes secrets
14
+ */
15
+ export const createKubeEnv = (context: Context) => {
16
+ if (!isOfDeployType(context.componentConfig.deploy, "kubernetes")) {
17
+ // should not happen
18
+ throw new Error("deploy config is not kubernetes");
19
+ }
20
+
21
+ const allEnvVars = context.environment.envVars;
22
+
23
+ const env = Object.entries(allEnvVars).reduce<{
24
+ secret: Record<string, string>;
25
+ public: Record<string, string>;
26
+ }>(
27
+ (acc, [key, value]) => {
28
+ if (shouldGoIntoSecrets(key, value)) {
29
+ acc.secret = {
30
+ ...acc.secret,
31
+ [key]: value,
32
+ };
33
+ return acc;
34
+ }
35
+ acc.public = {
36
+ ...acc.public,
37
+ [key]: value,
38
+ };
39
+ return acc;
40
+ },
41
+ {
42
+ secret: {},
43
+ public: {},
44
+ }
45
+ );
46
+
47
+ return env;
48
+ };
@@ -0,0 +1,96 @@
1
+ import { merge } from "lodash";
2
+
3
+ import type { Context } from "../../types/context";
4
+ import { mergeWithMergingArrays } from "../../utils";
5
+ import type { DeployConfigKubernetesValues } from "../types";
6
+ import { isOfDeployType } from "../types";
7
+ import { hasKubernetesCloudSQL, createCloudsqlBaseConfig } from "./cloudSql";
8
+
9
+ import { createKubeEnv } from "./kubeEnv";
10
+ import { createMongodbBaseConfig } from "./mongodb";
11
+ import { processSecretsAsFiles } from "./processSecretsAsFiles";
12
+
13
+ const createAppConfig = (
14
+ context: Context,
15
+ application: DeployConfigKubernetesValues["application"]
16
+ ): DeployConfigKubernetesValues["application"] => {
17
+ if (application === false) {
18
+ return {
19
+ enabled: false,
20
+ };
21
+ }
22
+
23
+ const { healthRoute, command, ...rest } = application ?? {};
24
+
25
+ return mergeWithMergingArrays(
26
+ {
27
+ host: context.environment.host,
28
+ command: command ?? context.componentConfig.build.startCommand,
29
+ livenessProbe: {
30
+ httpGet: {
31
+ path: healthRoute ?? "__health",
32
+ },
33
+ },
34
+ readinessProbe: {
35
+ httpGet: {
36
+ path: healthRoute ?? "__health",
37
+ },
38
+ },
39
+ startupProbe: {
40
+ httpGet: {
41
+ path: healthRoute ?? "__health",
42
+ },
43
+ },
44
+ }, // default
45
+ rest // merge rest in
46
+ );
47
+ };
48
+
49
+ const removeFalsy = <T>(record?: Record<string, false | T>) => {
50
+ if (!record) return undefined;
51
+ return Object.fromEntries(
52
+ Object.entries(record).filter(([, value]) => value !== false)
53
+ );
54
+ };
55
+
56
+ export const createKubeValues = (context: Context) => {
57
+ const deployConfig = context.componentConfig.deploy;
58
+ if (deployConfig === false) {
59
+ return [];
60
+ }
61
+ if (!isOfDeployType(deployConfig, "kubernetes")) {
62
+ // should not happen
63
+ throw new Error("deploy config is not kubernetes");
64
+ }
65
+
66
+ const { values } = deployConfig;
67
+
68
+ // we remove the application config because it can be just the value `false` which is a convenience feature, but not supported in the helm chart
69
+ // we only merge the rest of the values in
70
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
71
+ const { application, jobs, cronjobs, ...rest } = values ?? {};
72
+
73
+ const env = createKubeEnv(context);
74
+
75
+ const defaultKubeValues = merge(
76
+ {
77
+ env,
78
+ application: createAppConfig(context, application),
79
+ },
80
+ hasKubernetesCloudSQL(context) ? createCloudsqlBaseConfig(context) : {},
81
+ deployConfig.values?.mongodb?.enabled
82
+ ? createMongodbBaseConfig(context)
83
+ : {}
84
+ );
85
+
86
+ const kubeValues = processSecretsAsFiles(
87
+ mergeWithMergingArrays(defaultKubeValues, {
88
+ jobs: removeFalsy(jobs),
89
+ cronjobs: removeFalsy(cronjobs),
90
+
91
+ ...rest,
92
+ })
93
+ );
94
+
95
+ return kubeValues;
96
+ };
@@ -1,17 +1,114 @@
1
- import { Context } from "../..";
1
+ import { range } from "lodash";
2
+ import type { Context } from "../..";
3
+ import { getSecretVarNameForContext, isOfDeployType } from "../..";
2
4
 
5
+ const getCredentialString = (context: Context) =>
6
+ `root:$${getSecretVarNameForContext(context, "MONGODB_ROOT_PASSWORD")}@`;
7
+ const getMongodbHost = (context: Context, name: string) => {
8
+ const namespace = context.environment.envVars.KUBE_NAMESPACE;
9
+ return `${name}.${namespace}.svc.cluster.local:27017`;
10
+ };
11
+
12
+ const getMongodbStandaloneHost = (context: Context) => {
13
+ const fullAppname = context.environment.envVars.KUBE_APP_NAME;
14
+ return getMongodbHost(context, `${fullAppname}-mongodb`);
15
+ };
16
+
17
+ const getMongodbReplicasetHost = (context: Context, index: number) => {
18
+ const fullAppname = context.environment.envVars.KUBE_APP_NAME;
19
+ return getMongodbHost(
20
+ context,
21
+ `${fullAppname}-mongodb-${index}.${fullAppname}-mongodb-headless`
22
+ );
23
+ };
24
+ const createMongodbUrl = (context: Context, dbName: string) => {
25
+ if (!isOfDeployType(context.componentConfig.deploy, "kubernetes")) {
26
+ throw new Error("can only createMongodbUrl on supported deploys");
27
+ }
28
+ const mongodbConfig = context.componentConfig.deploy.values?.mongodb;
29
+
30
+ let queryParams: string | undefined = undefined;
31
+
32
+ let hosts = "";
33
+ if (mongodbConfig?.architecture === "replicaset") {
34
+ hosts = range(0, mongodbConfig?.replicaCount ?? 2)
35
+ .map((i) => getMongodbReplicasetHost(context, i))
36
+ .join(",");
37
+
38
+ queryParams = "replicaSet=rs0&authSource=admin";
39
+ } else {
40
+ hosts = getMongodbStandaloneHost(context);
41
+ queryParams = "authSource=admin";
42
+ }
43
+
44
+ return `mongodb://${getCredentialString(context)}${hosts}/${dbName}${
45
+ queryParams ? `?${queryParams}` : ""
46
+ }`;
47
+ };
48
+ const createMongoBackupDefaultConfig = (context: Context) => {
49
+ if (!isOfDeployType(context.componentConfig.deploy, "kubernetes")) {
50
+ throw new Error("can only create mongodb base config on supported deploys");
51
+ }
52
+ const mongodbConfig = context.componentConfig.deploy.values?.mongodb;
53
+ const fullAppName = context.environment.envVars.KUBE_APP_NAME;
54
+ const backupEnabled = ["prod", "stage"].includes(context.environment.envType);
55
+
56
+ let hostToBackup: string;
57
+ let pvcToBackup: string;
58
+
59
+ if (mongodbConfig?.architecture === "replicaset") {
60
+ // bit quirky, we need to specify the host and its volume
61
+ // on replicaset its probably best to not use the first one, whcih usually starts as master, so we take the second (last one would also be ok)
62
+ const backupHostIndex =
63
+ mongodbConfig?.architecture === "replicaset" &&
64
+ mongodbConfig.replicaCount &&
65
+ mongodbConfig.replicaCount > 1
66
+ ? 1
67
+ : 0;
68
+
69
+ hostToBackup = getMongodbReplicasetHost(context, backupHostIndex);
70
+ pvcToBackup = `datadir-${fullAppName}-mongodb-${backupHostIndex}`;
71
+ } else {
72
+ hostToBackup = getMongodbStandaloneHost(context);
73
+ pvcToBackup = `${fullAppName}-mongodb`;
74
+ }
75
+
76
+ return {
77
+ enabled: backupEnabled,
78
+ hostToBackup,
79
+ pvcToBackup,
80
+ image: "mrelite/kubectlmongoshell:v1.0",
81
+ schedule: "0 4 * * *",
82
+ volumeSnapshotClass: "snapshotclass",
83
+ };
84
+ };
3
85
  export const createMongodbBaseConfig = (context: Context) => {
86
+ if (!isOfDeployType(context.componentConfig.deploy, "kubernetes")) {
87
+ throw new Error("can only create mongodb base config on supported deploys");
88
+ }
89
+ const mongodbConfig = context.componentConfig.deploy.values?.mongodb;
90
+
4
91
  return {
5
92
  mongodb: {
6
93
  enabled: true,
7
- backup: {
8
- enabled: ["prod", "stage"].includes(context.environment.envType),
94
+ auth: {
95
+ enabled: true,
96
+ rootPassword:
97
+ "$" + getSecretVarNameForContext(context, "MONGODB_ROOT_PASSWORD"),
98
+ replicaSetKey:
99
+ "$" + getSecretVarNameForContext(context, "MONGODB_REPLICASET_KEY"),
100
+ },
101
+ persistence: {
102
+ storageClass: "standard-rwo",
9
103
  },
104
+ backup: createMongoBackupDefaultConfig(context),
10
105
  },
11
- "mongodb-replicaset": {
12
- replicas: 1,
13
- persistentVolume: {
14
- storageClass: "standard",
106
+ env: {
107
+ secret: {
108
+ MONGO_URL: createMongodbUrl(context, mongodbConfig?.dbName ?? "app"),
109
+ ...(mongodbConfig?.architecture === "replicaset"
110
+ ? { MONGO_OPLOG_URL: createMongodbUrl(context, "local") } // oplog only works with replicasets
111
+ : {}),
15
112
  },
16
113
  },
17
114
  };
@@ -1,5 +1,5 @@
1
1
  import { omit } from "lodash";
2
- import { DeployConfigKubernetesValues } from "../types";
2
+ import type { DeployConfigKubernetesValues } from "../types";
3
3
 
4
4
  export const processSecretsAsFiles = <
5
5
  T extends {
@@ -0,0 +1,17 @@
1
+ export type DeployConfigBase = {
2
+ /**
3
+ * whether to deploy automatically or manual. If not defined, these rules apply:
4
+ * - prod: manual
5
+ * - all other envs: auto
6
+ */
7
+ when?: "manual" | "auto";
8
+
9
+ /**
10
+ * EXPERIMENTAL
11
+ * wait for other components to deploy first, before doing this deployment
12
+ */
13
+ waitFor?: string[];
14
+ };
15
+
16
+ export type AllowUnknownProps<T extends Record<string, unknown>> = T &
17
+ Record<string, unknown>;
@@ -0,0 +1,36 @@
1
+ import type { GitlabJobImage } from "../../types";
2
+ import type { CatladderJob } from "../../types/jobs";
3
+ import type { DeployConfigBase } from "./base";
4
+
5
+ export type DeployConfigCustom = {
6
+ /**
7
+ * custom deploy types allow you to specify custom commands to deploy your app
8
+ */
9
+ type: "custom";
10
+ /**
11
+ * whether the deploy script requires a docker image to be built
12
+ */
13
+ requiresDocker: boolean;
14
+ /**
15
+ * whether your custom script requires yarn install
16
+ */
17
+ requiresYarnInstall?: boolean;
18
+ /**
19
+ * your custom script
20
+ */
21
+ script: string[];
22
+ /**
23
+ * script to run to stop the environment
24
+ */
25
+ stopScript?: string[];
26
+
27
+ /**
28
+ * image to use
29
+ */
30
+ jobImage?: GitlabJobImage;
31
+
32
+ /**
33
+ * customize cache for the job
34
+ */
35
+ jobCache?: CatladderJob["cache"];
36
+ } & DeployConfigBase;
@@ -0,0 +1,12 @@
1
+ import type { DeployConfigBase } from "./base";
2
+
3
+ export type DeployConfigDockerTag = {
4
+ /**
5
+ * adds a custom tag on the repo to deploy it.
6
+ *
7
+ * only used in veloplus atm, generally not recommended to use
8
+ */
9
+ type: "dockerTag";
10
+
11
+ tag: string;
12
+ } & DeployConfigBase;