@catladder/cli 0.0.0-test3 → 0.0.0-yarnrc-support-bdbef31f

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 (292) hide show
  1. package/.nvmrc +1 -1
  2. package/README.md +4 -2
  3. package/bin/catenv +3 -0
  4. package/bin/catladder +1 -1
  5. package/dist/apps/catenv/catenv.d.ts +2 -0
  6. package/dist/apps/catenv/catenv.js +135 -0
  7. package/dist/apps/catenv/catenv.js.map +1 -0
  8. package/dist/apps/cli/cli.d.ts +2 -0
  9. package/dist/apps/cli/cli.js +81 -0
  10. package/dist/apps/cli/cli.js.map +1 -0
  11. package/dist/apps/cli/commands/general/index.d.ts +4 -0
  12. package/dist/apps/cli/commands/general/index.js +208 -0
  13. package/dist/apps/cli/commands/general/index.js.map +1 -0
  14. package/dist/apps/cli/commands/general/namespaceAutoCompletion.d.ts +3 -0
  15. package/dist/apps/cli/commands/general/namespaceAutoCompletion.js +56 -0
  16. package/dist/apps/cli/commands/general/namespaceAutoCompletion.js.map +1 -0
  17. package/dist/apps/cli/commands/general/portForward.d.ts +3 -0
  18. package/dist/apps/cli/commands/general/portForward.js +98 -0
  19. package/dist/apps/cli/commands/general/portForward.js.map +1 -0
  20. package/dist/apps/cli/commands/mongodb/index.d.ts +3 -0
  21. package/dist/apps/cli/commands/mongodb/index.js +53 -0
  22. package/dist/apps/cli/commands/mongodb/index.js.map +1 -0
  23. package/dist/apps/cli/commands/mongodb/projectMongoDestroyMember.d.ts +3 -0
  24. package/dist/apps/cli/commands/mongodb/projectMongoDestroyMember.js +190 -0
  25. package/dist/apps/cli/commands/mongodb/projectMongoDestroyMember.js.map +1 -0
  26. package/dist/apps/cli/commands/mongodb/projectMongoGetShell.d.ts +3 -0
  27. package/dist/apps/cli/commands/mongodb/projectMongoGetShell.js +96 -0
  28. package/dist/apps/cli/commands/mongodb/projectMongoGetShell.js.map +1 -0
  29. package/dist/apps/cli/commands/mongodb/projectMongoPortForward.d.ts +3 -0
  30. package/dist/apps/cli/commands/mongodb/projectMongoPortForward.js +105 -0
  31. package/dist/apps/cli/commands/mongodb/projectMongoPortForward.js.map +1 -0
  32. package/dist/apps/cli/commands/mongodb/utils/index.d.ts +13 -0
  33. package/dist/apps/cli/commands/mongodb/utils/index.js +167 -0
  34. package/dist/apps/cli/commands/mongodb/utils/index.js.map +1 -0
  35. package/dist/apps/cli/commands/project/commandCloudSqlProxy.d.ts +3 -0
  36. package/dist/apps/cli/commands/project/commandCloudSqlProxy.js +129 -0
  37. package/dist/apps/cli/commands/project/commandCloudSqlProxy.js.map +1 -0
  38. package/dist/apps/cli/commands/project/commandConfigSecrets.d.ts +3 -0
  39. package/dist/apps/cli/commands/project/commandConfigSecrets.js +294 -0
  40. package/dist/apps/cli/commands/project/commandConfigSecrets.js.map +1 -0
  41. package/dist/apps/cli/commands/project/commandCopyDB.d.ts +3 -0
  42. package/dist/apps/cli/commands/project/commandCopyDB.js +102 -0
  43. package/dist/apps/cli/commands/project/commandCopyDB.js.map +1 -0
  44. package/dist/apps/cli/commands/project/commandDeletePods.d.ts +3 -0
  45. package/dist/apps/cli/commands/project/commandDeletePods.js +119 -0
  46. package/dist/apps/cli/commands/project/commandDeletePods.js.map +1 -0
  47. package/dist/apps/cli/commands/project/commandDeleteProject.d.ts +3 -0
  48. package/dist/apps/cli/commands/project/commandDeleteProject.js +97 -0
  49. package/dist/apps/cli/commands/project/commandDeleteProject.js.map +1 -0
  50. package/dist/apps/cli/commands/project/commandEnvVars.d.ts +3 -0
  51. package/dist/apps/cli/commands/project/commandEnvVars.js +74 -0
  52. package/dist/apps/cli/commands/project/commandEnvVars.js.map +1 -0
  53. package/dist/apps/cli/commands/project/commandGetMyTotalWorktime.d.ts +3 -0
  54. package/dist/apps/cli/commands/project/commandGetMyTotalWorktime.js +58 -0
  55. package/dist/apps/cli/commands/project/commandGetMyTotalWorktime.js.map +1 -0
  56. package/dist/apps/cli/commands/project/commandGetShell.d.ts +3 -0
  57. package/dist/apps/cli/commands/project/commandGetShell.js +92 -0
  58. package/dist/apps/cli/commands/project/commandGetShell.js.map +1 -0
  59. package/dist/apps/cli/commands/project/commandGitlabCi.d.ts +3 -0
  60. package/dist/apps/cli/commands/project/commandGitlabCi.js +185 -0
  61. package/dist/apps/cli/commands/project/commandGitlabCi.js.map +1 -0
  62. package/dist/apps/cli/commands/project/commandInitGitlab.d.ts +3 -0
  63. package/dist/apps/cli/commands/project/commandInitGitlab.js +136 -0
  64. package/dist/apps/cli/commands/project/commandInitGitlab.js.map +1 -0
  65. package/dist/apps/cli/commands/project/commandInitProject.d.ts +3 -0
  66. package/dist/apps/cli/commands/project/commandInitProject.js +345 -0
  67. package/dist/apps/cli/commands/project/commandInitProject.js.map +1 -0
  68. package/dist/apps/cli/commands/project/commandListPods.d.ts +3 -0
  69. package/dist/apps/cli/commands/project/commandListPods.js +78 -0
  70. package/dist/apps/cli/commands/project/commandListPods.js.map +1 -0
  71. package/dist/apps/cli/commands/project/commandMigrateHelm3.d.ts +7 -0
  72. package/dist/apps/cli/commands/project/commandMigrateHelm3.js +113 -0
  73. package/dist/apps/cli/commands/project/commandMigrateHelm3.js.map +1 -0
  74. package/dist/apps/cli/commands/project/commandNamespace.d.ts +3 -0
  75. package/dist/apps/cli/commands/project/commandNamespace.js +70 -0
  76. package/dist/apps/cli/commands/project/commandNamespace.js.map +1 -0
  77. package/dist/apps/cli/commands/project/commandOpenCostDashboard.d.ts +3 -0
  78. package/dist/apps/cli/commands/project/commandOpenCostDashboard.js +83 -0
  79. package/dist/apps/cli/commands/project/commandOpenCostDashboard.js.map +1 -0
  80. package/dist/apps/cli/commands/project/commandOpenDashboard.d.ts +3 -0
  81. package/dist/apps/cli/commands/project/commandOpenDashboard.js +85 -0
  82. package/dist/apps/cli/commands/project/commandOpenDashboard.js.map +1 -0
  83. package/dist/apps/cli/commands/project/commandOpenEnv.d.ts +3 -0
  84. package/dist/apps/cli/commands/project/commandOpenEnv.js +80 -0
  85. package/dist/apps/cli/commands/project/commandOpenEnv.js.map +1 -0
  86. package/dist/apps/cli/commands/project/commandOpenGit.d.ts +3 -0
  87. package/dist/apps/cli/commands/project/commandOpenGit.js +61 -0
  88. package/dist/apps/cli/commands/project/commandOpenGit.js.map +1 -0
  89. package/dist/apps/cli/commands/project/commandOpenGrafana.d.ts +3 -0
  90. package/dist/apps/cli/commands/project/commandOpenGrafana.js +83 -0
  91. package/dist/apps/cli/commands/project/commandOpenGrafana.js.map +1 -0
  92. package/dist/apps/cli/commands/project/commandOpenGrafanaPod.d.ts +3 -0
  93. package/dist/apps/cli/commands/project/commandOpenGrafanaPod.js +99 -0
  94. package/dist/apps/cli/commands/project/commandOpenGrafanaPod.js.map +1 -0
  95. package/dist/apps/cli/commands/project/commandOpenLogs.d.ts +3 -0
  96. package/dist/apps/cli/commands/project/commandOpenLogs.js +87 -0
  97. package/dist/apps/cli/commands/project/commandOpenLogs.js.map +1 -0
  98. package/dist/apps/cli/commands/project/commandPauseProject.d.ts +3 -0
  99. package/dist/apps/cli/commands/project/commandPauseProject.js +97 -0
  100. package/dist/apps/cli/commands/project/commandPauseProject.js.map +1 -0
  101. package/dist/apps/cli/commands/project/commandPortForward.d.ts +3 -0
  102. package/dist/apps/cli/commands/project/commandPortForward.js +106 -0
  103. package/dist/apps/cli/commands/project/commandPortForward.js.map +1 -0
  104. package/dist/apps/cli/commands/project/commandReloadConfig.d.ts +3 -0
  105. package/dist/apps/cli/commands/project/commandReloadConfig.js +62 -0
  106. package/dist/apps/cli/commands/project/commandReloadConfig.js.map +1 -0
  107. package/dist/apps/cli/commands/project/commandTriggerCronjob.d.ts +3 -0
  108. package/dist/apps/cli/commands/project/commandTriggerCronjob.js +144 -0
  109. package/dist/apps/cli/commands/project/commandTriggerCronjob.js.map +1 -0
  110. package/dist/apps/cli/commands/project/index.d.ts +3 -0
  111. package/dist/apps/cli/commands/project/index.js +97 -0
  112. package/dist/apps/cli/commands/project/index.js.map +1 -0
  113. package/dist/apps/cli/commands/project/utils/autocompletions.d.ts +3 -0
  114. package/dist/apps/cli/commands/project/utils/autocompletions.js +96 -0
  115. package/dist/apps/cli/commands/project/utils/autocompletions.js.map +1 -0
  116. package/dist/apps/cli/commands/project/utils/ensureCluster.d.ts +1 -0
  117. package/dist/apps/cli/commands/project/utils/ensureCluster.js +84 -0
  118. package/dist/apps/cli/commands/project/utils/ensureCluster.js.map +1 -0
  119. package/dist/apps/cli/commands/project/utils/ensureNamespace.d.ts +2 -0
  120. package/dist/apps/cli/commands/project/utils/ensureNamespace.js +106 -0
  121. package/dist/apps/cli/commands/project/utils/ensureNamespace.js.map +1 -0
  122. package/dist/apps/cli/commands/project/utils/showProjectBanner.d.ts +2 -0
  123. package/dist/apps/cli/commands/project/utils/showProjectBanner.js +58 -0
  124. package/dist/apps/cli/commands/project/utils/showProjectBanner.js.map +1 -0
  125. package/dist/apps/cli/commands/shared/index.d.ts +3 -0
  126. package/dist/apps/cli/commands/shared/index.js +70 -0
  127. package/dist/apps/cli/commands/shared/index.js.map +1 -0
  128. package/dist/apps/cli/commands/theStuffThatReallyMatters/index.d.ts +3 -0
  129. package/dist/apps/cli/commands/theStuffThatReallyMatters/index.js +101 -0
  130. package/dist/apps/cli/commands/theStuffThatReallyMatters/index.js.map +1 -0
  131. package/dist/apps/cli/config/writeConfig.d.ts +5 -0
  132. package/dist/apps/cli/config/writeConfig.js +106 -0
  133. package/dist/apps/cli/config/writeConfig.js.map +1 -0
  134. package/dist/apps/cli/utils/getGoogleAuthUserNumber.d.ts +1 -0
  135. package/dist/apps/cli/utils/getGoogleAuthUserNumber.js +69 -0
  136. package/dist/apps/cli/utils/getGoogleAuthUserNumber.js.map +1 -0
  137. package/dist/apps/cli/verify/index.d.ts +2 -0
  138. package/dist/apps/cli/verify/index.js +94 -0
  139. package/dist/apps/cli/verify/index.js.map +1 -0
  140. package/dist/apps/cli/verify/migration/fromv2.d.ts +4 -0
  141. package/dist/apps/cli/verify/migration/fromv2.js +345 -0
  142. package/dist/apps/cli/verify/migration/fromv2.js.map +1 -0
  143. package/dist/apps/cli/verify/migration/migrateSecrets.d.ts +4 -0
  144. package/dist/apps/cli/verify/migration/migrateSecrets.js +88 -0
  145. package/dist/apps/cli/verify/migration/migrateSecrets.js.map +1 -0
  146. package/dist/apps/cli/verify/migration/oldGitlabCi.d.ts +18 -0
  147. package/dist/apps/cli/verify/migration/oldGitlabCi.js +30 -0
  148. package/dist/apps/cli/verify/migration/oldGitlabCi.js.map +1 -0
  149. package/dist/catenv.d.ts +1 -0
  150. package/dist/catenv.js +10 -0
  151. package/dist/catenv.js.map +1 -0
  152. package/dist/cli.d.ts +1 -0
  153. package/dist/cli.js +15 -0
  154. package/dist/cli.js.map +1 -0
  155. package/dist/config/constants.d.ts +3 -0
  156. package/dist/config/constants.js +7 -0
  157. package/dist/config/constants.js.map +1 -0
  158. package/dist/config/getProjectConfig.d.ts +24 -0
  159. package/dist/config/getProjectConfig.js +232 -0
  160. package/dist/config/getProjectConfig.js.map +1 -0
  161. package/dist/k8sApi/index.d.ts +6 -0
  162. package/dist/k8sApi/index.js +15 -0
  163. package/dist/k8sApi/index.js.map +1 -0
  164. package/dist/packageInfos.d.ts +2 -0
  165. package/dist/packageInfos.js +6 -0
  166. package/dist/packageInfos.js.map +1 -0
  167. package/dist/tsconfig.tsbuildinfo +1 -0
  168. package/dist/types/types.d.ts +18 -0
  169. package/dist/types/types.js +3 -0
  170. package/dist/types/types.js.map +1 -0
  171. package/dist/utils/cluster.d.ts +3 -0
  172. package/dist/utils/cluster.js +75 -0
  173. package/dist/utils/cluster.js.map +1 -0
  174. package/dist/utils/editAsFile.d.ts +1 -0
  175. package/dist/utils/editAsFile.js +85 -0
  176. package/dist/utils/editAsFile.js.map +1 -0
  177. package/dist/utils/files.d.ts +2 -0
  178. package/dist/utils/files.js +83 -0
  179. package/dist/utils/files.js.map +1 -0
  180. package/dist/utils/formatEnvVars.d.ts +2 -0
  181. package/dist/utils/formatEnvVars.js +10 -0
  182. package/dist/utils/formatEnvVars.js.map +1 -0
  183. package/dist/utils/getEditor.d.ts +4 -0
  184. package/dist/utils/getEditor.js +70 -0
  185. package/dist/utils/getEditor.js.map +1 -0
  186. package/dist/utils/gitlab.d.ts +21 -0
  187. package/dist/utils/gitlab.js +262 -0
  188. package/dist/utils/gitlab.js.map +1 -0
  189. package/dist/utils/log.d.ts +1 -0
  190. package/dist/utils/log.js +14 -0
  191. package/dist/utils/log.js.map +1 -0
  192. package/dist/utils/passwordstore/index.d.ts +8 -0
  193. package/dist/utils/passwordstore/index.js +378 -0
  194. package/dist/utils/passwordstore/index.js.map +1 -0
  195. package/dist/utils/portForward.d.ts +4 -0
  196. package/dist/utils/portForward.js +116 -0
  197. package/dist/utils/portForward.js.map +1 -0
  198. package/dist/utils/preferences/index.d.ts +3 -0
  199. package/dist/utils/preferences/index.js +119 -0
  200. package/dist/utils/preferences/index.js.map +1 -0
  201. package/dist/utils/projects/index.d.ts +8 -0
  202. package/dist/utils/projects/index.js +154 -0
  203. package/dist/utils/projects/index.js.map +1 -0
  204. package/dist/utils/promise.d.ts +2 -0
  205. package/dist/utils/promise.js +62 -0
  206. package/dist/utils/promise.js.map +1 -0
  207. package/dist/utils/shell.d.ts +1 -0
  208. package/dist/utils/shell.js +81 -0
  209. package/dist/utils/shell.js.map +1 -0
  210. package/package.json +16 -21
  211. package/src/apps/catenv/catenv.ts +48 -27
  212. package/src/apps/{shell/shell.ts → cli/cli.ts} +10 -2
  213. package/src/apps/{shell → cli}/commands/general/index.ts +2 -40
  214. package/src/apps/{shell → cli}/commands/general/namespaceAutoCompletion.ts +0 -0
  215. package/src/apps/{shell → cli}/commands/general/portForward.ts +1 -1
  216. package/src/apps/{shell → cli}/commands/mongodb/index.ts +1 -1
  217. package/src/apps/{shell → cli}/commands/mongodb/projectMongoDestroyMember.ts +18 -18
  218. package/src/apps/{shell → cli}/commands/mongodb/projectMongoGetShell.ts +12 -10
  219. package/src/apps/{shell → cli}/commands/mongodb/projectMongoPortForward.ts +13 -8
  220. package/src/apps/{shell → cli}/commands/mongodb/utils/index.ts +9 -8
  221. package/src/apps/{shell → cli}/commands/project/commandCloudSqlProxy.ts +26 -21
  222. package/src/apps/cli/commands/project/commandConfigSecrets.ts +205 -0
  223. package/src/apps/{shell → cli}/commands/project/commandCopyDB.ts +24 -26
  224. package/src/apps/{shell → cli}/commands/project/commandDeletePods.ts +8 -9
  225. package/src/apps/{shell → cli}/commands/project/commandDeleteProject.ts +7 -8
  226. package/src/apps/cli/commands/project/commandEnvVars.ts +15 -0
  227. package/src/apps/{shell → cli}/commands/project/commandGetMyTotalWorktime.ts +2 -2
  228. package/src/apps/{shell → cli}/commands/project/commandGetShell.ts +10 -10
  229. package/src/apps/{shell → cli}/commands/project/commandGitlabCi.ts +1 -1
  230. package/src/apps/cli/commands/project/commandInitGitlab.ts +248 -0
  231. package/src/apps/{shell → cli}/commands/project/commandInitProject.ts +14 -6
  232. package/src/apps/cli/commands/project/commandListPods.ts +18 -0
  233. package/src/apps/{shell → cli}/commands/project/commandMigrateHelm3.ts +16 -7
  234. package/src/apps/cli/commands/project/commandNamespace.ts +14 -0
  235. package/src/apps/{shell → cli}/commands/project/commandOpenCostDashboard.ts +10 -7
  236. package/src/apps/cli/commands/project/commandOpenDashboard.ts +48 -0
  237. package/src/apps/cli/commands/project/commandOpenEnv.ts +22 -0
  238. package/src/apps/{shell → cli}/commands/project/commandOpenGit.ts +3 -3
  239. package/src/apps/{shell → cli}/commands/project/commandOpenGrafana.ts +7 -7
  240. package/src/apps/{shell → cli}/commands/project/commandOpenGrafanaPod.ts +9 -10
  241. package/src/apps/cli/commands/project/commandOpenLogs.ts +52 -0
  242. package/src/apps/{shell → cli}/commands/project/commandPauseProject.ts +9 -7
  243. package/src/apps/{shell → cli}/commands/project/commandPortForward.ts +8 -8
  244. package/src/apps/cli/commands/project/commandReloadConfig.ts +12 -0
  245. package/src/apps/{shell → cli}/commands/project/commandTriggerCronjob.ts +7 -7
  246. package/src/apps/{shell → cli}/commands/project/index.ts +4 -3
  247. package/src/apps/cli/commands/project/utils/autocompletions.ts +26 -0
  248. package/src/apps/cli/commands/project/utils/ensureCluster.ts +42 -0
  249. package/src/apps/cli/commands/project/utils/ensureNamespace.ts +55 -0
  250. package/src/apps/cli/commands/project/utils/showProjectBanner.ts +11 -0
  251. package/src/apps/cli/commands/shared/index.ts +36 -0
  252. package/src/apps/{shell → cli}/commands/theStuffThatReallyMatters/index.ts +7 -26
  253. package/src/apps/cli/config/writeConfig.ts +71 -0
  254. package/src/apps/{shell → cli}/utils/getGoogleAuthUserNumber.ts +0 -0
  255. package/src/apps/cli/verify/index.ts +30 -0
  256. package/src/apps/cli/verify/migration/fromv2.ts +262 -0
  257. package/src/apps/cli/verify/migration/migrateSecrets.ts +37 -0
  258. package/src/apps/cli/verify/migration/oldGitlabCi.ts +48 -0
  259. package/src/catenv.ts +4 -0
  260. package/src/cli.ts +9 -0
  261. package/src/config/constants.ts +0 -1
  262. package/src/config/getProjectConfig.ts +136 -0
  263. package/src/k8sApi/index.ts +5 -1
  264. package/src/types/types.ts +0 -2
  265. package/src/utils/cluster.ts +8 -15
  266. package/src/utils/editAsFile.ts +31 -0
  267. package/src/utils/files.ts +6 -2
  268. package/src/utils/gitlab.ts +133 -34
  269. package/src/utils/passwordstore/index.ts +19 -21
  270. package/src/utils/preferences/index.ts +6 -3
  271. package/src/utils/projects/index.ts +15 -136
  272. package/tsconfig.json +3 -7
  273. package/bin/catenv.sh +0 -1
  274. package/src/apps/shell/commands/project/commandConfigSecrets.ts +0 -245
  275. package/src/apps/shell/commands/project/commandEnvVars.ts +0 -17
  276. package/src/apps/shell/commands/project/commandInitGitlab.ts +0 -157
  277. package/src/apps/shell/commands/project/commandListPods.ts +0 -21
  278. package/src/apps/shell/commands/project/commandNamespace.ts +0 -12
  279. package/src/apps/shell/commands/project/commandOpenDashboard.ts +0 -27
  280. package/src/apps/shell/commands/project/commandOpenEnv.ts +0 -18
  281. package/src/apps/shell/commands/project/commandOpenLogs.ts +0 -23
  282. package/src/apps/shell/commands/project/commandVariables.ts +0 -13
  283. package/src/apps/shell/commands/project/utils/autocompletions.ts +0 -7
  284. package/src/apps/shell/commands/project/utils/ensureCluster.ts +0 -31
  285. package/src/apps/shell/commands/project/utils/ensureNamespace.ts +0 -32
  286. package/src/apps/shell/commands/project/utils/monorepo.ts +0 -45
  287. package/src/apps/shell/commands/shared/index.ts +0 -31
  288. package/src/config/clusters.ts +0 -45
  289. package/src/index.ts +0 -17
  290. package/src/types/git-repo-name.d.ts +0 -1
  291. package/src/types/yawn-yaml.d.ts +0 -1
  292. package/src/utils/dashboardToken.ts +0 -20
@@ -0,0 +1,262 @@
1
+ import {
2
+ BuildConfig,
3
+ ComponentConfig,
4
+ Config,
5
+ DeployConfigKubernetes,
6
+ Env,
7
+ } from "@catladder/pipeline";
8
+ import {
9
+ existsSync,
10
+ lstatSync,
11
+ readdirSync,
12
+ readFile,
13
+ writeFile,
14
+ } from "fs-extra";
15
+ import { isEmpty } from "lodash";
16
+ import { join } from "path";
17
+ import Vorpal from "vorpal";
18
+ import {
19
+ getGitlabCi,
20
+ getGitlabCiFilePath,
21
+ } from "../../../../config/getProjectConfig";
22
+ import { readYaml } from "../../../../utils/files";
23
+ import { syncBitwarden } from "../../../../utils/passwordstore";
24
+ import { getGitRoot } from "../../../../utils/projects";
25
+ import { writeConfig } from "../../config/writeConfig";
26
+ import { migrateSecrets } from "./migrateSecrets";
27
+ import {
28
+ detectBuildConfig,
29
+ isOldInclude,
30
+ OldGitlabCiFile,
31
+ } from "./oldGitlabCi";
32
+ export const LEGACY_ENVS = [
33
+ "dev-local",
34
+ "dev",
35
+ "review",
36
+ "stage",
37
+ "prod",
38
+ ] as const;
39
+
40
+ const arrayToRecord = (arr: { name: string }[]): Record<string, any> => {
41
+ if (!arr) return undefined;
42
+ return Object.fromEntries(arr.map(({ name, ...rest }) => [name, rest]));
43
+ };
44
+
45
+ const transformVars = (rawVars: {
46
+ public: Record<string, any>;
47
+ secret: Record<string, any>;
48
+ fromCommponents: any;
49
+ }) => {
50
+ if (rawVars.fromCommponents) {
51
+ console.warn("cant transform legacy fromCommponents");
52
+ }
53
+
54
+ return {
55
+ public: rawVars.public,
56
+ secret: rawVars.secret ? Object.keys(rawVars.secret) : undefined,
57
+ };
58
+ };
59
+
60
+ const getLegacyMonorepoSubCiFiles = (dir: string) => {
61
+ return readdirSync(dir)
62
+ .filter((file) => lstatSync(file).isDirectory())
63
+ .map((dir) => ({
64
+ dir,
65
+ ci: join(dir, ".gitlab-ci.yml"),
66
+ }))
67
+ .filter(({ ci }) => existsSync(ci));
68
+ };
69
+
70
+ const transformValues = (
71
+ valuesIn: Record<string, any>
72
+ ): DeployConfigKubernetes["values"] => {
73
+ if (isEmpty(valuesIn)) {
74
+ return undefined;
75
+ }
76
+ delete valuesIn?.application?.host;
77
+ delete valuesIn?.application?.command;
78
+
79
+ return {
80
+ ...valuesIn,
81
+ jobs: arrayToRecord(valuesIn?.jobs),
82
+ cronjobs: arrayToRecord(valuesIn?.cronjobs),
83
+ };
84
+ };
85
+
86
+ export const isV2 = async () => {
87
+ const gitlabCi = await getGitlabCi<OldGitlabCiFile>();
88
+ return isOldInclude(gitlabCi);
89
+ };
90
+ export const migrateV2 = async (vorpal: Vorpal) => {
91
+ const gitlabCi = await getGitlabCi<OldGitlabCiFile>();
92
+ const gitRoot = await getGitRoot();
93
+
94
+ const {
95
+ CUSTOMER_NAME,
96
+ APP_NAME,
97
+ COMPONENT_NAME,
98
+ APP_DIR = ".",
99
+ STAGING_ENABLED,
100
+ } = gitlabCi.variables;
101
+
102
+ vorpal
103
+ .command("migrate")
104
+
105
+ .action(async function () {
106
+ this.log("");
107
+ this.log("⚠️ this project uses legacy catladder (v2)");
108
+ this.log("");
109
+ this.log(
110
+ "😼 I can migrate the project for you. This contains the following steps:"
111
+ );
112
+ this.log("");
113
+ this.log(
114
+ " - migrate the config from values-*.yml to catladder config file"
115
+ );
116
+ this.log(
117
+ " - migrate the secrets from bitwarden to gitlab (this will trash the entries in bitwarden)"
118
+ );
119
+ this.log("");
120
+ this.log(
121
+ "☝ make sure that you checked in your current state in case something goes wrong."
122
+ );
123
+ this.log(
124
+ "☝ secrets in bitwarden are deleted, but can be restored within 30 days."
125
+ );
126
+ this.log("");
127
+ const { shouldContinue } = await this.prompt({
128
+ default: true,
129
+ message: "Migrate project now? 🤔",
130
+ name: "shouldContinue",
131
+ type: "confirm",
132
+ });
133
+
134
+ if (shouldContinue) {
135
+ vorpal.log("");
136
+ vorpal.log("");
137
+ vorpal.log("💪😼 ok, let's go...");
138
+ vorpal.log("");
139
+ vorpal.log("");
140
+
141
+ const createComponent = async (
142
+ dir: string,
143
+ ciFile: OldGitlabCiFile
144
+ ): Promise<ComponentConfig> => {
145
+ const { env, ...baseValues } =
146
+ (await readYaml(dir + "/values.yml")) ?? {};
147
+
148
+ const startCommand = Array.isArray(baseValues?.application?.command)
149
+ ? baseValues?.application?.command.join(" ")
150
+ : baseValues?.application?.command
151
+ return {
152
+ vars: env ? transformVars(env) : undefined,
153
+ dir: dir,
154
+ build: {
155
+ type: detectBuildConfig(ciFile),
156
+ startCommand: startCommand,
157
+ } as BuildConfig,
158
+ deploy: {
159
+ type: "kubernetes",
160
+ values: transformValues(baseValues),
161
+ cluster: {
162
+ type: "gcloud",
163
+ name: "ch-production",
164
+ projectId: "skynet-swiss",
165
+ region: "europe-west6-a",
166
+ domainCanonical: "panter.swiss",
167
+ },
168
+ },
169
+ env: await LEGACY_ENVS.reduce<Promise<Env>>(
170
+ async (acc, envName) => {
171
+ if (envName === "stage" && !STAGING_ENABLED) {
172
+ return {
173
+ ...(await acc),
174
+ [envName]: false,
175
+ };
176
+ }
177
+ const newEnvName = envName === "dev-local" ? "local" : envName;
178
+
179
+ const envValues =
180
+ (await readYaml(dir + `/values-${envName}.yml`)) ?? {};
181
+ const { env, ...rest } = envValues;
182
+ const host = rest?.application?.host;
183
+ const values = transformValues(rest);
184
+ return {
185
+ ...(await acc),
186
+ [newEnvName]: {
187
+ host: host,
188
+ vars: env ? transformVars(env) : undefined,
189
+ deploy: values
190
+ ? {
191
+ values: values,
192
+ }
193
+ : undefined,
194
+ },
195
+ };
196
+ },
197
+ Promise.resolve({})
198
+ ),
199
+ };
200
+ };
201
+ let components: Record<string, ComponentConfig>;
202
+ if (detectBuildConfig(gitlabCi) === "monorepo") {
203
+ components = await getLegacyMonorepoSubCiFiles(gitRoot).reduce<
204
+ Promise<Record<string, ComponentConfig>>
205
+ >(async (acc, el) => {
206
+ return {
207
+ ...(await acc),
208
+ [el.dir]: await createComponent(el.dir, await readYaml(el.ci)),
209
+ };
210
+ }, Promise.resolve({}));
211
+ } else {
212
+ components = {
213
+ [COMPONENT_NAME]: await createComponent(APP_DIR, gitlabCi),
214
+ };
215
+ }
216
+ // we only have one component
217
+ const config: Config = {
218
+ customerName: CUSTOMER_NAME,
219
+ appName: APP_NAME,
220
+ components,
221
+ };
222
+
223
+ const comment =
224
+ "Old migrated config:\n\n" +
225
+ (await readFile(await getGitlabCiFilePath(), {
226
+ encoding: "utf-8",
227
+ }));
228
+
229
+ this.log("-------------------");
230
+ this.log("migrate config");
231
+ await writeConfig(this, config, {
232
+ endComment: comment,
233
+ });
234
+ this.log("write gitlab-ci.yml");
235
+ await writeFile(
236
+ await getGitlabCiFilePath(),
237
+ "include: https://git.panter.ch/api/v4/projects/catladder%2Fcatladder/packages/generic/ci-includes/main/gitlab-ci.yml",
238
+ { encoding: "utf-8" }
239
+ );
240
+
241
+ this.log("-------------------");
242
+ this.log("migrate secrets");
243
+ await syncBitwarden();
244
+ for (const env of LEGACY_ENVS) {
245
+ if (env === "stage" && !STAGING_ENABLED) return;
246
+ await migrateSecrets(this, config, env);
247
+ }
248
+
249
+ this.log("-------------------");
250
+
251
+ this.log("done!");
252
+
253
+ this.log("-------------------");
254
+ } else {
255
+ this.log(
256
+ "☝ if you want to use catladder in legacy mode, install @panter/catladder globally and invoke catladder-legacy"
257
+ );
258
+ }
259
+ });
260
+
261
+ vorpal.exec("migrate");
262
+ };
@@ -0,0 +1,37 @@
1
+ import { Config, getEnvironment } from "@catladder/pipeline";
2
+ import { load } from "js-yaml";
3
+ import { pick } from "lodash";
4
+ import { CommandInstance } from "vorpal";
5
+ import { upsertAllVariables } from "../../../../utils/gitlab";
6
+ import { readPass, trashItem } from "../../../../utils/passwordstore";
7
+ import { LEGACY_ENVS } from "./fromv2";
8
+
9
+ const getPassPath = (newConfig: Config, env: string) => {
10
+ return `${newConfig.customerName}/${newConfig.appName}/${env}/secrets.yml`;
11
+ };
12
+
13
+ export const migrateSecrets = async (
14
+ vorpal: CommandInstance,
15
+ newConfig: Config,
16
+ oldEnv: typeof LEGACY_ENVS[number]
17
+ ) => {
18
+ const newEnv = oldEnv === "dev-local" ? "local" : oldEnv;
19
+ const path = getPassPath(newConfig, oldEnv);
20
+ try {
21
+ const yamlstring = await readPass(path);
22
+ const secrets = load(yamlstring);
23
+
24
+ Object.keys(newConfig.components).forEach(async (componentName) => {
25
+ const environment = getEnvironment(newConfig, componentName, newEnv);
26
+ await upsertAllVariables(
27
+ vorpal,
28
+ pick(secrets, environment.secretEnvVarKeys),
29
+ newEnv,
30
+ componentName
31
+ );
32
+ });
33
+ await trashItem(path);
34
+ } catch (e) {
35
+ console.warn(`could not migrate secrets for env '${oldEnv}': ${e}`);
36
+ }
37
+ };
@@ -0,0 +1,48 @@
1
+ import { BuildConfig } from "@catladder/pipeline";
2
+
3
+ export type OldGitlabCiFile = {
4
+ variables: {
5
+ CUSTOMER_NAME: string;
6
+ APP_NAME: string;
7
+ COMPONENT_NAME?: string;
8
+ APP_DIR?: string;
9
+ CLUSTER_NAME?: string;
10
+ STAGING_ENABLED?: string;
11
+ };
12
+ include: {
13
+ project: string;
14
+ ref: string;
15
+ file: string;
16
+ }[];
17
+ };
18
+
19
+ export const isOldInclude = (gitlabCi: OldGitlabCiFile) => {
20
+ return gitlabCi.include[0]?.project === "catladder/gitlab-ci";
21
+ };
22
+
23
+ export const detectBuildConfig = (
24
+ gitlabCi: OldGitlabCiFile
25
+ ): BuildConfig["type"] | "monorepo" => {
26
+ if (!isOldInclude(gitlabCi)) {
27
+ throw new Error("unsupported gitlab-ci file");
28
+ }
29
+
30
+ const firstInclude = gitlabCi.include[0];
31
+
32
+ if (firstInclude.file === "monorepo.yml") return "monorepo";
33
+
34
+ if (firstInclude.file === "node-kubernetes.yml") {
35
+ return "node";
36
+ }
37
+
38
+ if (firstInclude.file === "static-js-kubernetes.yml") {
39
+ return "node-static";
40
+ }
41
+ if (firstInclude.file === "meteor-kubernetes.yml") {
42
+ return "meteor";
43
+ }
44
+
45
+ if (firstInclude.file === "rails-kubernetes.yml") {
46
+ throw new Error("rails is not yet implemented");
47
+ }
48
+ };
package/src/catenv.ts ADDED
@@ -0,0 +1,4 @@
1
+ import catenv from "./apps/catenv/catenv";
2
+ import { $ } from "zx";
3
+ $.verbose = false;
4
+ catenv();
package/src/cli.ts ADDED
@@ -0,0 +1,9 @@
1
+ import updateNotifier from "update-notifier";
2
+ import cli from "./apps/cli/cli";
3
+ import packageInfos from "./packageInfos";
4
+ import { $ } from "zx";
5
+ $.verbose = false;
6
+ updateNotifier({
7
+ pkg: packageInfos,
8
+ }).notify();
9
+ cli();
@@ -1,5 +1,4 @@
1
1
  export const GRAFANA_PROXY_LOCAL_PORT = 9090;
2
2
  export const GRAFANA_PROXY_TARGET_PORT = 9090;
3
3
 
4
- export const GOOGLE_PROJECT = "skynet-164509";
5
4
  export const GOOGLE_CLOUD_SQL_PASS_PATH = "cloud-sql-proxy-credentials";
@@ -0,0 +1,136 @@
1
+ import {
2
+ readConfigSync,
3
+ getAllEnvs,
4
+ getEnvironment as _getEnvironment,
5
+ createContext,
6
+ } from "@catladder/pipeline";
7
+
8
+ import { CommandInstance } from "vorpal";
9
+ import { getAllVariables } from "../utils/gitlab";
10
+ import memoizee from "memoizee";
11
+ import { getGitRoot } from "../utils/projects";
12
+ import { readYaml } from "../utils/files";
13
+ // currently cant change
14
+
15
+ export const getProjectConfig = memoizee(
16
+ async () => {
17
+ try {
18
+ const gitRoot = await getGitRoot();
19
+ return readConfigSync(gitRoot);
20
+ } catch (e) {
21
+ // ignore
22
+ return null;
23
+ }
24
+ },
25
+ { promise: true }
26
+ );
27
+
28
+ export const reloadConfig = () => getProjectConfig.clear();
29
+
30
+ export const getGitlabCiFilePath = async () => {
31
+ const gitRoot = await getGitRoot();
32
+ return gitRoot + "/.gitlab-ci.yml";
33
+ };
34
+ export const getGitlabCi = async <T = Record<string, any>>() => {
35
+ try {
36
+ return readYaml(await getGitlabCiFilePath()) as Promise<T>;
37
+ } catch (e) {
38
+ // ignore
39
+ return null;
40
+ }
41
+ };
42
+
43
+ export const getProjectComponents = async () => {
44
+ const config = await getProjectConfig();
45
+ if (!config) return [];
46
+ return Object.keys(config.components);
47
+ };
48
+
49
+ export const parseChoice = (envComponent: string) => {
50
+ const [env, componentName] = envComponent.split(":");
51
+ return { env, componentName };
52
+ };
53
+
54
+ export const getPipelineContextByChoice = async (
55
+ env: string,
56
+ componentName: string
57
+ ) => {
58
+ const config = await getProjectConfig();
59
+ return createContext(config, componentName, env);
60
+ };
61
+ export const getAllComponentsWithAllEnvsFlat = async (): Promise<
62
+ Array<{ env: string; componentName: string }>
63
+ > => {
64
+ const config = await getProjectConfig();
65
+ if (!config) {
66
+ return [];
67
+ }
68
+ return Object.keys(config.components).flatMap((componentName) =>
69
+ getAllEnvs(config, componentName).map((env) => ({ env, componentName }))
70
+ );
71
+ };
72
+
73
+ export const getAllComponentsWithAllEnvsHierarchical = async (): Promise<{
74
+ [componentName: string]: string[];
75
+ }> => {
76
+ const config = await getProjectConfig();
77
+ if (!config) {
78
+ return {};
79
+ }
80
+
81
+ return Object.fromEntries(
82
+ Object.keys(config.components).map((componentName) => [
83
+ componentName,
84
+ getAllEnvs(config, componentName),
85
+ ])
86
+ );
87
+ };
88
+
89
+ export const getAllPipelineContexts = async () => {
90
+ return Promise.all(
91
+ (await getAllComponentsWithAllEnvsFlat())
92
+ .filter((c) => c.env !== "local")
93
+ .map(({ env, componentName }) =>
94
+ getPipelineContextByChoice(env, componentName)
95
+ )
96
+ );
97
+ };
98
+
99
+ export const getEnvironment = async (env: string, componentName: string) => {
100
+ const config = await getProjectConfig();
101
+ return _getEnvironment(config, componentName, env);
102
+ };
103
+
104
+ const resolveSecrets = async (
105
+ vorpal: CommandInstance,
106
+ allEnvVars: Record<string, string>
107
+ ) => {
108
+ const allVariablesInGitlab = await getAllVariables(vorpal);
109
+
110
+ return Object.fromEntries(
111
+ Object.entries(allEnvVars).map(([key, value]) => {
112
+ const isSecret = String(value)?.startsWith?.("$CL_");
113
+ if (isSecret) {
114
+ // secrets have CL_XXXX structure
115
+ const found = allVariablesInGitlab.find((v) => "$" + v.key === value);
116
+
117
+ if (found) {
118
+ return [key, found.value];
119
+ } else {
120
+ return [key, ""];
121
+ }
122
+ }
123
+ return [key, value];
124
+ })
125
+ );
126
+ };
127
+
128
+ export const getEnvVars = async (
129
+ vorpal: CommandInstance,
130
+ env: string,
131
+ componentName: string
132
+ ) => {
133
+ const envionment = await getEnvironment(env, componentName);
134
+
135
+ return resolveSecrets(vorpal, envionment.envVars);
136
+ };
@@ -7,7 +7,11 @@ import {
7
7
 
8
8
  const kc = new KubeConfig();
9
9
 
10
- kc.loadFromDefault();
10
+ export const reload = () => {
11
+ kc.loadFromDefault();
12
+ };
13
+
14
+ reload();
11
15
 
12
16
  const k8sApi = kc.makeApiClient(CoreV1Api);
13
17
 
@@ -1,5 +1,3 @@
1
- export type Env = "dev-local" | "prod" | "dev" | "stage" | "review";
2
-
3
1
  export type KubernetesSecretName = string;
4
2
  export interface ISecrets {
5
3
  [key: string]: KubernetesSecretName;
@@ -1,21 +1,14 @@
1
- import { exec } from "child-process-promise";
2
- import { findKey } from "lodash";
3
- import clusters from "../config/clusters";
1
+ import { $ } from "zx";
2
+ import { reload } from "../k8sApi";
3
+
4
4
  export const getCurrentContext = async () =>
5
- (await exec("kubectl config current-context")).stdout.trim();
5
+ (await $`kubectl config current-context`).stdout.trim();
6
6
 
7
7
  export const getCurrentConnectedClusterName = async () => {
8
- const currentContext = await getCurrentContext();
9
- return findKey(clusters, { fullName: currentContext });
10
- };
11
-
12
- export const getClusterByName = (name: string) => {
13
- return clusters[name];
8
+ return await getCurrentContext();
14
9
  };
15
10
 
16
- export const getAllClusterNames = () => Object.keys(clusters);
17
-
18
- export const connectToCluster = async (clusterName: string) => {
19
- const { connect } = getClusterByName(clusterName);
20
- await connect();
11
+ export const connectToCluster = async (fullname: string) => {
12
+ await $`kubectl config use-context ${fullname}`;
13
+ reload();
21
14
  };
@@ -0,0 +1,31 @@
1
+ import { withFile } from "tmp-promise";
2
+ import { dump, load } from "js-yaml";
3
+
4
+ import { readFile, writeFile } from "fs-extra";
5
+ import getEditor from "./getEditor";
6
+
7
+ export const editAsFile = async <T>(
8
+ inObject: T,
9
+ preamble?: string
10
+ ): Promise<T> => {
11
+ const fullPreamble = preamble
12
+ ? `#
13
+ # ${preamble.split("\n").join("\n# ")}
14
+ #
15
+
16
+ `
17
+ : "\n";
18
+ const asString = fullPreamble + dump(inObject, { noRefs: true });
19
+ let newContent: T;
20
+
21
+ await withFile(
22
+ async ({ path: tmpFilePath }) => {
23
+ await writeFile(tmpFilePath, asString);
24
+ await (await getEditor()).open(tmpFilePath);
25
+ newContent = load((await readFile(tmpFilePath)).toString("utf-8")) as T;
26
+ },
27
+ { postfix: ".yml" }
28
+ );
29
+
30
+ return newContent;
31
+ };
@@ -13,6 +13,10 @@ export const readFileOrError = async (filePath: string) => {
13
13
  }
14
14
  };
15
15
 
16
- export const readYaml = async (filename: string) => {
17
- return yaml.load(await readFile(filename));
16
+ export const readYaml = async <T = Record<string, any>>(filename: string) => {
17
+ try {
18
+ return yaml.load(await readFile(filename)) as T;
19
+ } catch (e) {
20
+ return null;
21
+ }
18
22
  };