@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,3 +1,7 @@
1
+ import type { GitlabJobImage, GitlabJobService } from "../types";
2
+
3
+ import type { CatladderJob } from "../types/jobs";
4
+
1
5
  export type BuildConfigBase = {
2
6
  /**
3
7
  * command to run on the image to start the app (e.g. yarn start)
@@ -27,6 +31,7 @@ export type BuildConfigBase = {
27
31
  | false
28
32
  | {
29
33
  command?: string | string[];
34
+ jobImage?: GitlabJobImage;
30
35
  };
31
36
 
32
37
  /**
@@ -36,6 +41,7 @@ export type BuildConfigBase = {
36
41
  | false
37
42
  | {
38
43
  command?: string | string[];
44
+ jobImage?: GitlabJobImage;
39
45
  };
40
46
 
41
47
  /**
@@ -45,6 +51,7 @@ export type BuildConfigBase = {
45
51
  | false
46
52
  | {
47
53
  command?: string | string[];
54
+ jobImage?: GitlabJobImage;
48
55
  };
49
56
 
50
57
  /**
@@ -52,6 +59,20 @@ export type BuildConfigBase = {
52
59
  * by default "dist" and ".next" are allways included
53
60
  */
54
61
  artifactsPaths?: string[];
62
+
63
+ /**
64
+ * additional CI/CD artifacts reports,
65
+ * use to display information in merge requests, pipeline views and security dashboards.
66
+ */
67
+ artifactsReports?: {
68
+ /**
69
+ * The junit report collects JUnit report format XML files.
70
+ * The collected Unit test reports upload to GitLab as an artifact.
71
+ * Paths are prefixed with component's root folder.
72
+ * eg. `["dist/test-results/TEST-*.xml", "dist/rspec.xml", ...]`
73
+ */
74
+ junit?: string[];
75
+ };
55
76
  };
56
77
 
57
78
  export type BuildConfigNodeBase = BuildConfigBase;
@@ -67,6 +88,71 @@ export type BuildConfigNodeStatic = BuildConfigNodeBase & {
67
88
 
68
89
  export type BuildConfigMeteor = BuildConfigNodeBase & {
69
90
  type: "meteor";
91
+ /**
92
+ * whether to run yarn install inside the source folder in the docker image.
93
+ * This is only required if you have custom scripts in your image
94
+ */
95
+ installScripts?: boolean;
96
+ };
97
+
98
+ export type BuildConfigCustomDocker = BuildConfigBase["docker"] &
99
+ (
100
+ | {
101
+ /**
102
+ * use the built-in nginx image for simple static apps
103
+ */
104
+ type: "nginx";
105
+ }
106
+ | {
107
+ /**
108
+ * custom docker build, expect that a Dockerfile in your directory
109
+ */
110
+ type: "custom";
111
+ }
112
+ );
113
+
114
+ export type BuildConfigCustom = BuildConfigBase & {
115
+ type: "custom";
116
+ jobImage: string;
117
+ jobServices?: GitlabJobService[];
118
+
119
+ docker: BuildConfigCustomDocker;
120
+
121
+ /**
122
+ * customize cache for the job
123
+ */
124
+ jobCache?: CatladderJob["cache"];
125
+ };
126
+
127
+ export type BuildConfigRails = BuildConfigBase & {
128
+ type: "rails";
129
+ cnbBuilder?: {
130
+ /**
131
+ * The Cloud Native Buildpacks builder image to use.
132
+ * See e.g. https://github.com/heroku/builder or others.
133
+ * Default: heroku/buildpacks:20
134
+ */
135
+ image?: string;
136
+ /**
137
+ * The version of the Cloud Native Buildpacks pack command to use.
138
+ * See https://buildpacks.io/docs/tools/pack/
139
+ * Default: 0.28.0
140
+ */
141
+ packVersion?: string;
142
+ /**
143
+ * Additional command arguments passed to the pack command.
144
+ * See https://buildpacks.io/docs/tools/pack/
145
+ */
146
+ packExtraArgs?: string[];
147
+ /**
148
+ * Variables needed for Bundler and Rails asset precompilation.
149
+ *
150
+ * Specify a key with the value `undefined` to inherit it from the EnvVars.
151
+ *
152
+ * See https://github.com/rails/rails/issues/32947
153
+ */
154
+ buildVars?: Record<string, string | undefined>;
155
+ };
70
156
  };
71
157
 
72
158
  export type BuildConfigStorybook = BuildConfigNodeBase & {
@@ -77,9 +163,18 @@ export type BuildConfig =
77
163
  | BuildConfigNode
78
164
  | BuildConfigNodeStatic
79
165
  | BuildConfigStorybook
80
- | BuildConfigMeteor;
166
+ | BuildConfigMeteor
167
+ | BuildConfigCustom
168
+ | BuildConfigRails;
169
+
170
+ export type BuildConfigType = BuildConfig["type"];
171
+
172
+ export type BuildConfigGeneric<T extends BuildConfigType> = Extract<
173
+ BuildConfig,
174
+ { type: T }
175
+ >;
81
176
 
82
- export const isOfBuildType = <T extends Array<BuildConfig["type"]>>(
177
+ export const isOfBuildType = <T extends Array<BuildConfigType>>(
83
178
  t: BuildConfig,
84
179
  ...types: T
85
180
  ): t is Extract<BuildConfig, { type: T[number] }> => {
@@ -3,7 +3,7 @@ import { dump } from "js-yaml";
3
3
  import { readConfigSync } from "./config";
4
4
  import { PIPELINE_IMAGE_TAG } from "./constants";
5
5
  import { createChildPipeline } from "./pipeline";
6
- import { PipelineTrigger } from "./types";
6
+ import type { PipelineTrigger } from "./types";
7
7
 
8
8
  const {
9
9
  CI_MERGE_REQUEST_ID,
@@ -14,7 +14,9 @@ const {
14
14
 
15
15
  const isDefaultBranch =
16
16
  Boolean(CI_DEFAULT_BRANCH) && CI_COMMIT_BRANCH === CI_DEFAULT_BRANCH;
17
- const isHotfixBranch = false; // TODO: $CI_COMMIT_BRANCH =~ /^[0-9]+\.([0-9]+|x)\.x$/
17
+ const isHotfixBranch = CI_COMMIT_BRANCH
18
+ ? /^[0-9]+\.([0-9]+|x)\.x$/.test(CI_COMMIT_BRANCH)
19
+ : false;
18
20
  const isMergeRequest = Boolean(CI_MERGE_REQUEST_ID);
19
21
  const isTaggedRelease = Boolean(CI_COMMIT_TAG);
20
22
 
@@ -1,6 +1,6 @@
1
- import { getAllEnvsByTrigger } from ".";
2
- import { DeployConfigKubernetesCluster } from "..";
3
- import { Config } from "../types";
1
+ import { getAllEnvsByTrigger } from "..";
2
+ import type { DeployConfigKubernetesCluster } from "../..";
3
+ import type { Config } from "../../types";
4
4
 
5
5
  describe("getAllEnvsByTrigger", () => {
6
6
  const cluster: DeployConfigKubernetesCluster = {
@@ -1,10 +1,5 @@
1
- import {
2
- Config,
3
- DEFAULT_ENV_TYPES,
4
- EnvType,
5
- getEnvTypesByTrigger,
6
- PipelineTrigger,
7
- } from "../types";
1
+ import type { Config, EnvType, PipelineTrigger } from "../types";
2
+ import { DEFAULT_ENV_TYPES, getEnvTypesByTrigger } from "../types";
8
3
 
9
4
  const getConfiguredAndDefaultEnvs = (
10
5
  config: Config,
@@ -1,7 +1,7 @@
1
1
  import { existsSync, readFileSync } from "fs";
2
2
  import { register } from "ts-node";
3
3
  import { load } from "js-yaml";
4
- import { Config } from "../types";
4
+ import type { Config } from "../types";
5
5
 
6
6
  // allows us to load ts files
7
7
 
@@ -1,10 +1,10 @@
1
1
  import {
2
2
  resolveReferences,
3
3
  translateLegacyFromComponents,
4
- } from "./resolveReferences";
4
+ } from "../resolveReferences";
5
5
 
6
6
  describe("resolveReferences", () => {
7
- it("replaces occurences of ${componentName:VARIABLE_NAME}", () => {
7
+ it("replaces occurences of ${componentName:VARIABLE_NAME}", async () => {
8
8
  const variables = {
9
9
  a: "hello world",
10
10
  b: "a replaced value looks like this: '${api:FOO}', nice!",
@@ -17,12 +17,9 @@ describe("resolveReferences", () => {
17
17
  FOO: "foo from frontend",
18
18
  },
19
19
  };
20
- const result = resolveReferences(
21
- variables,
22
- (componentName, variableName) => {
23
- return otherVariables[componentName]?.[variableName];
24
- }
25
- );
20
+ const result = await resolveReferences(variables, async (componentName) => {
21
+ return otherVariables[componentName];
22
+ });
26
23
 
27
24
  expect(result).toEqual({
28
25
  a: "hello world",
@@ -30,12 +27,12 @@ describe("resolveReferences", () => {
30
27
  });
31
28
  });
32
29
 
33
- it("replaces self references with structure ${VARIABLE_NAME}", () => {
30
+ it("replaces self references with structure ${VARIABLE_NAME}", async () => {
34
31
  const variables = {
35
32
  FOO: "hello world",
36
33
  BAR: "this: ${FOO}!",
37
34
  };
38
- const result = resolveReferences(variables);
35
+ const result = await resolveReferences(variables);
39
36
 
40
37
  expect(result).toEqual({
41
38
  FOO: "hello world",
@@ -43,7 +40,7 @@ describe("resolveReferences", () => {
43
40
  });
44
41
  });
45
42
 
46
- it("replaces self references mixed with other vars", () => {
43
+ it("replaces self references mixed with other vars", async () => {
47
44
  const variables = {
48
45
  FOO: "hello from ${api:FOO}",
49
46
  BAR: "this: ${FOO}!",
@@ -53,12 +50,9 @@ describe("resolveReferences", () => {
53
50
  FOO: "foo from api",
54
51
  },
55
52
  };
56
- const result = resolveReferences(
57
- variables,
58
- (componentName, variableName) => {
59
- return otherVariables[componentName]?.[variableName];
60
- }
61
- );
53
+ const result = await resolveReferences(variables, async (componentName) => {
54
+ return otherVariables[componentName];
55
+ });
62
56
 
63
57
  expect(result).toEqual({
64
58
  FOO: "hello from foo from api",
@@ -66,18 +60,15 @@ describe("resolveReferences", () => {
66
60
  });
67
61
  });
68
62
 
69
- it("keeps variables as is if not found (when null is returned)", () => {
63
+ it("keeps variables as is if not found (when null is returned)", async () => {
70
64
  const variables = {
71
65
  a: "hello world",
72
66
  b: "a not found value looks like this: '${api:FOO}'",
73
67
  };
74
68
  const otherVariables: Record<string, Record<string, string>> = {};
75
- const result = resolveReferences(
76
- variables,
77
- (componentName, variableName) => {
78
- return otherVariables[componentName]?.[variableName];
79
- }
80
- );
69
+ const result = await resolveReferences(variables, async (componentName) => {
70
+ return otherVariables[componentName];
71
+ });
81
72
 
82
73
  expect(result).toEqual({
83
74
  a: "hello world",
@@ -85,7 +76,7 @@ describe("resolveReferences", () => {
85
76
  });
86
77
  });
87
78
 
88
- it("replaces mulitple levels deep", () => {
79
+ it("replaces mulitple levels deep", async () => {
89
80
  const variables = {
90
81
  a: "value is ${frontend:FOO}!",
91
82
  };
@@ -97,19 +88,16 @@ describe("resolveReferences", () => {
97
88
  FOO: "hi, ${api:FOO}",
98
89
  },
99
90
  };
100
- const result = resolveReferences(
101
- variables,
102
- (componentName, variableName) => {
103
- return otherVariables[componentName]?.[variableName] ?? "";
104
- }
105
- );
91
+ const result = await resolveReferences(variables, async (componentName) => {
92
+ return otherVariables[componentName];
93
+ });
106
94
 
107
95
  expect(result).toEqual({
108
96
  a: "value is hi, foo from api!",
109
97
  });
110
98
  });
111
99
 
112
- it("prevents endless loops", () => {
100
+ it("prevents endless loops", async () => {
113
101
  const variables = {
114
102
  a: "value is ${frontend:FOO}!",
115
103
  };
@@ -121,12 +109,9 @@ describe("resolveReferences", () => {
121
109
  FOO: "frontend ${api:FOO}",
122
110
  },
123
111
  };
124
- const result = resolveReferences(
125
- variables,
126
- (componentName, variableName) => {
127
- return otherVariables[componentName]?.[variableName] ?? "";
128
- }
129
- );
112
+ const result = await resolveReferences(variables, async (componentName) => {
113
+ return otherVariables[componentName];
114
+ });
130
115
 
131
116
  expect(result).toEqual({
132
117
  a: "value is frontend api ${frontend:FOO}!",
@@ -0,0 +1,21 @@
1
+ import type { Config, EnvConfigWithComponent } from "../types/config";
2
+
3
+ import { mergeWithMergingArrays } from "../utils";
4
+
5
+ export const getEnvConfig = (
6
+ config: Config,
7
+ componentName: string,
8
+ env: string
9
+ ): EnvConfigWithComponent => {
10
+ const defaultConfig = config.components[componentName];
11
+ if (!defaultConfig) {
12
+ throw new Error("unknown component " + componentName);
13
+ }
14
+
15
+ const envCustomizations = defaultConfig.env?.[env] ?? {};
16
+ if (envCustomizations === false) {
17
+ throw new Error("env is disabled: " + env + ":" + componentName);
18
+ }
19
+
20
+ return mergeWithMergingArrays(defaultConfig, envCustomizations);
21
+ };
@@ -0,0 +1,17 @@
1
+ import type { EnvType } from "../types";
2
+ import { isKnowEnvType } from "../types";
3
+
4
+ export const getEnvType = (
5
+ env: string,
6
+ envConfig: {
7
+ type?: EnvType;
8
+ }
9
+ ): EnvType => {
10
+ if (envConfig.type) return envConfig.type;
11
+
12
+ if (isKnowEnvType(env)) {
13
+ return env;
14
+ }
15
+
16
+ throw new Error("unknown env type: " + env);
17
+ };
@@ -0,0 +1,40 @@
1
+ import type { Config } from "../types/config";
2
+
3
+ import type { CommitInfo, Environment } from "../types/context";
4
+ import { getEnvironmentContext } from "./getEnvironmentContext";
5
+ import { getEnvironmentVariables } from "./getEnvironmentVariables";
6
+
7
+ export const getEnvironment = async (
8
+ config: Config,
9
+ componentName: string,
10
+ env: string,
11
+ commitInfo?: CommitInfo
12
+ ): Promise<Environment> => {
13
+ const { envVars, secretEnvVarKeys, host, url } =
14
+ await getEnvironmentVariables(config, componentName, env, commitInfo);
15
+
16
+ const envContext = getEnvironmentContext(
17
+ config,
18
+ env,
19
+ componentName,
20
+ commitInfo
21
+ );
22
+
23
+ const envType = envContext.envType;
24
+
25
+ return {
26
+ envType,
27
+ host,
28
+ url,
29
+ gitlabEnvironment: {
30
+ name: envContext.gitlabEnvironmentName,
31
+ url,
32
+ },
33
+ fullName: envContext.fullName,
34
+ slugPrefix: envContext.environmentSlugPrefix,
35
+ slug: envContext.environmentSlug,
36
+ shortName: env,
37
+ envVars,
38
+ secretEnvVarKeys,
39
+ };
40
+ };
@@ -0,0 +1,57 @@
1
+ import type { Config, EnvConfigWithComponent } from "../types/config";
2
+
3
+ import type { CommitInfo } from "../types/context";
4
+ import type { EnvironmentContext } from "../types/environmentContext";
5
+ import { getEnvConfig } from "./getEnvConfig";
6
+ import { getEnvType } from "./getEnvType";
7
+
8
+ const getEnvironmentSlugPrefix = (
9
+ envConfig: EnvConfigWithComponent,
10
+ env: string,
11
+ commitInfo?: CommitInfo
12
+ ) => {
13
+ const envType = getEnvType(env, envConfig);
14
+
15
+ return envType === "review" && commitInfo
16
+ ? `${env}-${commitInfo.reviewSlug}`
17
+ : `${env}`;
18
+ };
19
+
20
+ export const getEnvironmentContext = (
21
+ config: Config,
22
+ env: string,
23
+ componentName: string,
24
+ commitInfo?: CommitInfo
25
+ ): EnvironmentContext<any, any> => {
26
+ const envConfigRaw = getEnvConfig(config, componentName, env);
27
+ const envType = getEnvType(env, envConfigRaw);
28
+
29
+ const environmentSlugPrefix = getEnvironmentSlugPrefix(
30
+ envConfigRaw,
31
+ env,
32
+ commitInfo
33
+ );
34
+
35
+ const environmentSlug = `${environmentSlugPrefix}-${componentName}`;
36
+ const gitlabEnvironmentName =
37
+ envType === "review" && commitInfo
38
+ ? `${env}/${commitInfo.refName}/${componentName}`
39
+ : `${env}/${componentName}`;
40
+
41
+ const fullName = `${config.customerName}-${config.appName}-${environmentSlug}`;
42
+
43
+ return {
44
+ envConfigRaw,
45
+ deployConfigRaw: envConfigRaw.deploy,
46
+ buildConfigRaw: envConfigRaw.build,
47
+ environmentSlugPrefix,
48
+ environmentSlug,
49
+ gitlabEnvironmentName,
50
+ fullName,
51
+ envType,
52
+ commitInfo,
53
+ componentName,
54
+ env,
55
+ fullConfig: config,
56
+ };
57
+ };
@@ -0,0 +1,155 @@
1
+ import { isObject, merge } from "lodash";
2
+ import { DEPLOY_TYPES } from "../deploy";
3
+ import type { CommitInfo, Context } from "../types";
4
+ import type { Config, DevLocalEnvConfig } from "../types/config";
5
+
6
+ import { getEnvironmentContext } from "./getEnvironmentContext";
7
+ import {
8
+ resolveReferences,
9
+ translateLegacyFromComponents,
10
+ } from "./resolveReferences";
11
+
12
+ export const getEnvironmentVariables = async (
13
+ config: Config,
14
+ componentName: string,
15
+ env: string,
16
+ commitInfo?: CommitInfo,
17
+ alreadyVisited: Record<string, Record<string, boolean>> = {} // to prevent endless loop
18
+ ): Promise<{
19
+ envVars: Record<string, string>;
20
+ secretEnvVarKeys: string[];
21
+ host: string;
22
+ url: string;
23
+ }> => {
24
+ const environmentContext = getEnvironmentContext(
25
+ config,
26
+ env,
27
+ componentName,
28
+ commitInfo
29
+ );
30
+
31
+ const { envConfigRaw, deployConfigRaw, envType } = environmentContext;
32
+
33
+ const basePredefinedVariables = {
34
+ ENV_SHORT: env,
35
+ APP_DIR: envConfigRaw.dir,
36
+ ENV_TYPE: envType,
37
+ };
38
+
39
+ let predefinedVariables: Record<string, string>;
40
+ let host: string;
41
+ let url: string;
42
+
43
+ if (envType === "local") {
44
+ const devLocalConfig: DevLocalEnvConfig = envConfigRaw;
45
+ const port = devLocalConfig.port ?? 3000;
46
+ host = "localhost:" + port;
47
+ url = "http://" + host;
48
+ predefinedVariables = {
49
+ ENV_SHORT: "local",
50
+ ROOT_URL: url,
51
+ PORT: port.toString(),
52
+ };
53
+ } else {
54
+ const additionalEnvVars = deployConfigRaw
55
+ ? DEPLOY_TYPES[deployConfigRaw.type].getAdditionalEnvVars(
56
+ environmentContext as never
57
+ )
58
+ : {};
59
+
60
+ host =
61
+ envConfigRaw?.host ??
62
+ additionalEnvVars.HOST_CANONICAL ??
63
+ "unknown-host.example.com";
64
+ url = `https://${host}`;
65
+
66
+ predefinedVariables = {
67
+ ...basePredefinedVariables,
68
+ // Rails before 6.1 (mis)uses the `HOST` environment variable to specify the IP to bind to
69
+ ...(config.components[componentName].build.type === "rails"
70
+ ? {}
71
+ : { HOST: host }),
72
+ ROOT_URL: url,
73
+ ...additionalEnvVars,
74
+ };
75
+ }
76
+ const publicEnvVarsRaw = envConfigRaw.vars?.public ?? {};
77
+
78
+ const additionalSecretKeys = deployConfigRaw
79
+ ? DEPLOY_TYPES[deployConfigRaw.type].additionalSecretKeys(
80
+ environmentContext as never
81
+ )
82
+ : [];
83
+
84
+ const secretEnvVarKeys = [
85
+ ...(envConfigRaw.vars?.secret ?? []),
86
+ ...additionalSecretKeys,
87
+ ];
88
+ const secretEnvVars = Object.fromEntries(
89
+ secretEnvVarKeys.map((key) => [
90
+ key,
91
+ `$${getSecretVarName(env, componentName, key)}`,
92
+ ])
93
+ );
94
+
95
+ // this is deprecated, we now support: $componentname:FOO
96
+ const legacyFromComponents = envConfigRaw.vars?.fromComponents ?? {};
97
+ const publicEnvVarsRawWithLegasyFromComponents = merge(
98
+ {},
99
+ translateLegacyFromComponents(legacyFromComponents),
100
+ publicEnvVarsRaw
101
+ );
102
+
103
+ const publicEnvVarsRawSanitized = Object.fromEntries(
104
+ Object.entries(publicEnvVarsRawWithLegasyFromComponents).map(
105
+ ([key, value]) => [
106
+ key,
107
+ isObject(value) ? JSON.stringify(value) : `${value}`,
108
+ ]
109
+ )
110
+ );
111
+
112
+ const envVarsRaw = addIndexVar({
113
+ ...predefinedVariables,
114
+ ...secretEnvVars,
115
+ ...publicEnvVarsRawSanitized,
116
+ });
117
+
118
+ const envVars = await resolveReferences(
119
+ envVarsRaw,
120
+ async (otherComponentName, alreadyVisited) => {
121
+ const { envVars: otherEnvVars } = await getEnvironmentVariables(
122
+ config,
123
+ otherComponentName,
124
+ env,
125
+ commitInfo,
126
+ alreadyVisited
127
+ );
128
+ return otherEnvVars;
129
+ },
130
+ alreadyVisited
131
+ );
132
+
133
+ return {
134
+ envVars,
135
+ secretEnvVarKeys,
136
+ host,
137
+ url,
138
+ };
139
+ };
140
+
141
+ const sanitizeForEnVar = (s: string) => s.replace(/-/g, "_");
142
+
143
+ export const getSecretVarName = (
144
+ env: string,
145
+ componentName: string,
146
+ key: string
147
+ ) => `CL_${sanitizeForEnVar(env)}_${sanitizeForEnVar(componentName)}_${key}`; // remove dash from component name
148
+
149
+ const addIndexVar = (vars: Record<string, unknown>) => ({
150
+ ...vars,
151
+ _ALL_ENV_VAR_KEYS: JSON.stringify(Object.keys(vars)),
152
+ });
153
+
154
+ export const getSecretVarNameForContext = (context: Context, key: string) =>
155
+ getSecretVarName(context.environment.shortName, context.componentName, key);
@@ -0,0 +1,20 @@
1
+ import slugify from "slugify";
2
+ import type { Context } from "../types";
3
+
4
+ const sanitize = (value?: string) => {
5
+ if (!value) return value;
6
+ //"The value can only contain lowercase letters, numeric characters, underscores and dashes. The value can be at most 63 characters long. International characters are allowed."
7
+ // slugify should do the job
8
+ return slugify(value).toLowerCase();
9
+ };
10
+ export const getLabels = (context: Context) => {
11
+ const labels = {
12
+ "customer-name": sanitize(context.fullConfig.customerName),
13
+ "app-name": sanitize(context.fullConfig.appName),
14
+ "env-type": sanitize(context.environment.envType),
15
+ "env-name": sanitize(context.environment.shortName),
16
+ "build-type": sanitize(context.componentConfig.build?.type),
17
+ ...(context.fullConfig.meta?.labels ?? {}),
18
+ };
19
+ return labels;
20
+ };