@catladder/cli 0.0.0-test3 → 0.0.0-vars-5d04a62d

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 (307) hide show
  1. package/.nvmrc +1 -1
  2. package/README.md +6 -3
  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 +216 -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 +97 -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 +132 -0
  37. package/dist/apps/cli/commands/project/commandCloudSqlProxy.js.map +1 -0
  38. package/dist/apps/cli/commands/project/commandConfigSecrets.d.ts +4 -0
  39. package/dist/apps/cli/commands/project/commandConfigSecrets.js +312 -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 +120 -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/commandInitProject.old.d.ts +3 -0
  63. package/dist/apps/cli/commands/project/commandInitProject.old.js +345 -0
  64. package/dist/apps/cli/commands/project/commandInitProject.old.js.map +1 -0
  65. package/dist/apps/cli/commands/project/commandListPods.d.ts +3 -0
  66. package/dist/apps/cli/commands/project/commandListPods.js +78 -0
  67. package/dist/apps/cli/commands/project/commandListPods.js.map +1 -0
  68. package/dist/apps/cli/commands/project/commandMigrateHelm3.d.ts +7 -0
  69. package/dist/apps/cli/commands/project/commandMigrateHelm3.js +113 -0
  70. package/dist/apps/cli/commands/project/commandMigrateHelm3.js.map +1 -0
  71. package/dist/apps/cli/commands/project/commandNamespace.d.ts +3 -0
  72. package/dist/apps/cli/commands/project/commandNamespace.js +70 -0
  73. package/dist/apps/cli/commands/project/commandNamespace.js.map +1 -0
  74. package/dist/apps/cli/commands/project/commandOpenCostDashboard.d.ts +3 -0
  75. package/dist/apps/cli/commands/project/commandOpenCostDashboard.js +83 -0
  76. package/dist/apps/cli/commands/project/commandOpenCostDashboard.js.map +1 -0
  77. package/dist/apps/cli/commands/project/commandOpenDashboard.d.ts +3 -0
  78. package/dist/apps/cli/commands/project/commandOpenDashboard.js +85 -0
  79. package/dist/apps/cli/commands/project/commandOpenDashboard.js.map +1 -0
  80. package/dist/apps/cli/commands/project/commandOpenEnv.d.ts +3 -0
  81. package/dist/apps/cli/commands/project/commandOpenEnv.js +80 -0
  82. package/dist/apps/cli/commands/project/commandOpenEnv.js.map +1 -0
  83. package/dist/apps/cli/commands/project/commandOpenGit.d.ts +3 -0
  84. package/dist/apps/cli/commands/project/commandOpenGit.js +61 -0
  85. package/dist/apps/cli/commands/project/commandOpenGit.js.map +1 -0
  86. package/dist/apps/cli/commands/project/commandOpenGrafana.d.ts +3 -0
  87. package/dist/apps/cli/commands/project/commandOpenGrafana.js +83 -0
  88. package/dist/apps/cli/commands/project/commandOpenGrafana.js.map +1 -0
  89. package/dist/apps/cli/commands/project/commandOpenGrafanaPod.d.ts +3 -0
  90. package/dist/apps/cli/commands/project/commandOpenGrafanaPod.js +99 -0
  91. package/dist/apps/cli/commands/project/commandOpenGrafanaPod.js.map +1 -0
  92. package/dist/apps/cli/commands/project/commandOpenLogs.d.ts +3 -0
  93. package/dist/apps/cli/commands/project/commandOpenLogs.js +87 -0
  94. package/dist/apps/cli/commands/project/commandOpenLogs.js.map +1 -0
  95. package/dist/apps/cli/commands/project/commandPauseProject.d.ts +3 -0
  96. package/dist/apps/cli/commands/project/commandPauseProject.js +97 -0
  97. package/dist/apps/cli/commands/project/commandPauseProject.js.map +1 -0
  98. package/dist/apps/cli/commands/project/commandPortForward.d.ts +3 -0
  99. package/dist/apps/cli/commands/project/commandPortForward.js +106 -0
  100. package/dist/apps/cli/commands/project/commandPortForward.js.map +1 -0
  101. package/dist/apps/cli/commands/project/commandReloadConfig.d.ts +3 -0
  102. package/dist/apps/cli/commands/project/commandReloadConfig.js +62 -0
  103. package/dist/apps/cli/commands/project/commandReloadConfig.js.map +1 -0
  104. package/dist/apps/cli/commands/project/commandSetup.d.ts +3 -0
  105. package/dist/apps/cli/commands/project/commandSetup.js +58 -0
  106. package/dist/apps/cli/commands/project/commandSetup.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 +96 -0
  112. package/dist/apps/cli/commands/project/index.js.map +1 -0
  113. package/dist/apps/cli/commands/project/setup/index.d.ts +2 -0
  114. package/dist/apps/cli/commands/project/setup/index.js +103 -0
  115. package/dist/apps/cli/commands/project/setup/index.js.map +1 -0
  116. package/dist/apps/cli/commands/project/setup/setupAccessTokens.d.ts +2 -0
  117. package/dist/apps/cli/commands/project/setup/setupAccessTokens.js +115 -0
  118. package/dist/apps/cli/commands/project/setup/setupAccessTokens.js.map +1 -0
  119. package/dist/apps/cli/commands/project/setup/setupContext.d.ts +3 -0
  120. package/dist/apps/cli/commands/project/setup/setupContext.js +74 -0
  121. package/dist/apps/cli/commands/project/setup/setupContext.js.map +1 -0
  122. package/dist/apps/cli/commands/project/setup/setupKubernetes.d.ts +3 -0
  123. package/dist/apps/cli/commands/project/setup/setupKubernetes.js +132 -0
  124. package/dist/apps/cli/commands/project/setup/setupKubernetes.js.map +1 -0
  125. package/dist/apps/cli/commands/project/utils/autocompletions.d.ts +3 -0
  126. package/dist/apps/cli/commands/project/utils/autocompletions.js +96 -0
  127. package/dist/apps/cli/commands/project/utils/autocompletions.js.map +1 -0
  128. package/dist/apps/cli/commands/project/utils/ensureCluster.d.ts +1 -0
  129. package/dist/apps/cli/commands/project/utils/ensureCluster.js +84 -0
  130. package/dist/apps/cli/commands/project/utils/ensureCluster.js.map +1 -0
  131. package/dist/apps/cli/commands/project/utils/ensureNamespace.d.ts +2 -0
  132. package/dist/apps/cli/commands/project/utils/ensureNamespace.js +104 -0
  133. package/dist/apps/cli/commands/project/utils/ensureNamespace.js.map +1 -0
  134. package/dist/apps/cli/commands/project/utils/showProjectBanner.d.ts +2 -0
  135. package/dist/apps/cli/commands/project/utils/showProjectBanner.js +58 -0
  136. package/dist/apps/cli/commands/project/utils/showProjectBanner.js.map +1 -0
  137. package/dist/apps/cli/commands/shared/index.d.ts +3 -0
  138. package/dist/apps/cli/commands/shared/index.js +70 -0
  139. package/dist/apps/cli/commands/shared/index.js.map +1 -0
  140. package/dist/apps/cli/commands/theStuffThatReallyMatters/index.d.ts +3 -0
  141. package/dist/apps/cli/commands/theStuffThatReallyMatters/index.js +101 -0
  142. package/dist/apps/cli/commands/theStuffThatReallyMatters/index.js.map +1 -0
  143. package/dist/apps/cli/config/writeConfig.d.ts +5 -0
  144. package/dist/apps/cli/config/writeConfig.js +109 -0
  145. package/dist/apps/cli/config/writeConfig.js.map +1 -0
  146. package/dist/apps/cli/utils/getGoogleAuthUserNumber.d.ts +1 -0
  147. package/dist/apps/cli/utils/getGoogleAuthUserNumber.js +69 -0
  148. package/dist/apps/cli/utils/getGoogleAuthUserNumber.js.map +1 -0
  149. package/dist/apps/cli/verify/index.d.ts +2 -0
  150. package/dist/apps/cli/verify/index.js +94 -0
  151. package/dist/apps/cli/verify/index.js.map +1 -0
  152. package/dist/apps/cli/verify/migration/fromv2.d.ts +4 -0
  153. package/dist/apps/cli/verify/migration/fromv2.js +347 -0
  154. package/dist/apps/cli/verify/migration/fromv2.js.map +1 -0
  155. package/dist/apps/cli/verify/migration/migrateSecrets.d.ts +4 -0
  156. package/dist/apps/cli/verify/migration/migrateSecrets.js +88 -0
  157. package/dist/apps/cli/verify/migration/migrateSecrets.js.map +1 -0
  158. package/dist/apps/cli/verify/migration/oldGitlabCi.d.ts +18 -0
  159. package/dist/apps/cli/verify/migration/oldGitlabCi.js +30 -0
  160. package/dist/apps/cli/verify/migration/oldGitlabCi.js.map +1 -0
  161. package/dist/catenv.d.ts +1 -0
  162. package/dist/catenv.js +10 -0
  163. package/dist/catenv.js.map +1 -0
  164. package/dist/cli.d.ts +1 -0
  165. package/dist/cli.js +15 -0
  166. package/dist/cli.js.map +1 -0
  167. package/dist/config/constants.d.ts +3 -0
  168. package/dist/config/constants.js +7 -0
  169. package/dist/config/constants.js.map +1 -0
  170. package/dist/config/getProjectConfig.d.ts +24 -0
  171. package/dist/config/getProjectConfig.js +231 -0
  172. package/dist/config/getProjectConfig.js.map +1 -0
  173. package/dist/k8sApi/index.d.ts +8 -0
  174. package/dist/k8sApi/index.js +29 -0
  175. package/dist/k8sApi/index.js.map +1 -0
  176. package/dist/packageInfos.d.ts +2 -0
  177. package/dist/packageInfos.js +6 -0
  178. package/dist/packageInfos.js.map +1 -0
  179. package/dist/tsconfig.tsbuildinfo +1 -0
  180. package/dist/types/types.d.ts +18 -0
  181. package/dist/types/types.js +3 -0
  182. package/dist/types/types.js.map +1 -0
  183. package/dist/utils/cluster.d.ts +3 -0
  184. package/dist/utils/cluster.js +73 -0
  185. package/dist/utils/cluster.js.map +1 -0
  186. package/dist/utils/editAsFile.d.ts +1 -0
  187. package/dist/utils/editAsFile.js +85 -0
  188. package/dist/utils/editAsFile.js.map +1 -0
  189. package/dist/utils/files.d.ts +2 -0
  190. package/dist/utils/files.js +83 -0
  191. package/dist/utils/files.js.map +1 -0
  192. package/dist/utils/getEditor.d.ts +4 -0
  193. package/dist/utils/getEditor.js +70 -0
  194. package/dist/utils/getEditor.js.map +1 -0
  195. package/dist/utils/gitlab.d.ts +21 -0
  196. package/dist/utils/gitlab.js +265 -0
  197. package/dist/utils/gitlab.js.map +1 -0
  198. package/dist/utils/log.d.ts +1 -0
  199. package/dist/utils/log.js +14 -0
  200. package/dist/utils/log.js.map +1 -0
  201. package/dist/utils/passwordstore/index.d.ts +8 -0
  202. package/dist/utils/passwordstore/index.js +378 -0
  203. package/dist/utils/passwordstore/index.js.map +1 -0
  204. package/dist/utils/portForward.d.ts +4 -0
  205. package/dist/utils/portForward.js +116 -0
  206. package/dist/utils/portForward.js.map +1 -0
  207. package/dist/utils/preferences/index.d.ts +3 -0
  208. package/dist/utils/preferences/index.js +119 -0
  209. package/dist/utils/preferences/index.js.map +1 -0
  210. package/dist/utils/projects/index.d.ts +8 -0
  211. package/dist/utils/projects/index.js +153 -0
  212. package/dist/utils/projects/index.js.map +1 -0
  213. package/dist/utils/promise.d.ts +2 -0
  214. package/dist/utils/promise.js +62 -0
  215. package/dist/utils/promise.js.map +1 -0
  216. package/dist/utils/shell.d.ts +1 -0
  217. package/dist/utils/shell.js +81 -0
  218. package/dist/utils/shell.js.map +1 -0
  219. package/package.json +16 -21
  220. package/src/apps/catenv/catenv.ts +48 -27
  221. package/src/apps/{shell/shell.ts → cli/cli.ts} +10 -2
  222. package/src/apps/{shell → cli}/commands/general/index.ts +7 -46
  223. package/src/apps/{shell → cli}/commands/general/namespaceAutoCompletion.ts +0 -0
  224. package/src/apps/{shell → cli}/commands/general/portForward.ts +3 -2
  225. package/src/apps/{shell → cli}/commands/mongodb/index.ts +1 -1
  226. package/src/apps/{shell → cli}/commands/mongodb/projectMongoDestroyMember.ts +18 -18
  227. package/src/apps/{shell → cli}/commands/mongodb/projectMongoGetShell.ts +12 -10
  228. package/src/apps/{shell → cli}/commands/mongodb/projectMongoPortForward.ts +13 -8
  229. package/src/apps/{shell → cli}/commands/mongodb/utils/index.ts +9 -8
  230. package/src/apps/cli/commands/project/commandCloudSqlProxy.ts +75 -0
  231. package/src/apps/cli/commands/project/commandConfigSecrets.ts +216 -0
  232. package/src/apps/{shell → cli}/commands/project/commandCopyDB.ts +24 -26
  233. package/src/apps/{shell → cli}/commands/project/commandDeletePods.ts +10 -10
  234. package/src/apps/{shell → cli}/commands/project/commandDeleteProject.ts +7 -8
  235. package/src/apps/cli/commands/project/commandEnvVars.ts +15 -0
  236. package/src/apps/{shell → cli}/commands/project/commandGetMyTotalWorktime.ts +2 -2
  237. package/src/apps/{shell → cli}/commands/project/commandGetShell.ts +10 -10
  238. package/src/apps/{shell → cli}/commands/project/commandGitlabCi.ts +1 -1
  239. package/src/apps/{shell/commands/project/commandInitProject.ts → cli/commands/project/commandInitProject.old.ts} +14 -6
  240. package/src/apps/cli/commands/project/commandListPods.ts +18 -0
  241. package/src/apps/{shell → cli}/commands/project/commandMigrateHelm3.ts +16 -7
  242. package/src/apps/cli/commands/project/commandNamespace.ts +14 -0
  243. package/src/apps/{shell → cli}/commands/project/commandOpenCostDashboard.ts +10 -7
  244. package/src/apps/cli/commands/project/commandOpenDashboard.ts +48 -0
  245. package/src/apps/cli/commands/project/commandOpenEnv.ts +22 -0
  246. package/src/apps/{shell → cli}/commands/project/commandOpenGit.ts +3 -3
  247. package/src/apps/{shell → cli}/commands/project/commandOpenGrafana.ts +7 -7
  248. package/src/apps/{shell → cli}/commands/project/commandOpenGrafanaPod.ts +9 -10
  249. package/src/apps/cli/commands/project/commandOpenLogs.ts +52 -0
  250. package/src/apps/{shell → cli}/commands/project/commandPauseProject.ts +9 -7
  251. package/src/apps/{shell → cli}/commands/project/commandPortForward.ts +8 -8
  252. package/src/apps/cli/commands/project/commandReloadConfig.ts +12 -0
  253. package/src/apps/cli/commands/project/commandSetup.ts +12 -0
  254. package/src/apps/{shell → cli}/commands/project/commandTriggerCronjob.ts +10 -10
  255. package/src/apps/{shell → cli}/commands/project/index.ts +8 -7
  256. package/src/apps/cli/commands/project/setup/index.ts +42 -0
  257. package/src/apps/cli/commands/project/setup/setupAccessTokens.ts +72 -0
  258. package/src/apps/cli/commands/project/setup/setupContext.ts +37 -0
  259. package/src/apps/cli/commands/project/setup/setupKubernetes.ts +112 -0
  260. package/src/apps/cli/commands/project/utils/autocompletions.ts +26 -0
  261. package/src/apps/cli/commands/project/utils/ensureCluster.ts +42 -0
  262. package/src/apps/cli/commands/project/utils/ensureNamespace.ts +56 -0
  263. package/src/apps/cli/commands/project/utils/showProjectBanner.ts +11 -0
  264. package/src/apps/cli/commands/shared/index.ts +36 -0
  265. package/src/apps/{shell → cli}/commands/theStuffThatReallyMatters/index.ts +7 -26
  266. package/src/apps/cli/config/writeConfig.ts +73 -0
  267. package/src/apps/{shell → cli}/utils/getGoogleAuthUserNumber.ts +0 -0
  268. package/src/apps/cli/verify/index.ts +30 -0
  269. package/src/apps/cli/verify/migration/fromv2.ts +264 -0
  270. package/src/apps/cli/verify/migration/migrateSecrets.ts +37 -0
  271. package/src/apps/cli/verify/migration/oldGitlabCi.ts +48 -0
  272. package/src/catenv.ts +4 -0
  273. package/src/cli.ts +9 -0
  274. package/src/config/constants.ts +0 -1
  275. package/src/config/getProjectConfig.ts +136 -0
  276. package/src/k8sApi/index.ts +22 -6
  277. package/src/types/types.ts +0 -2
  278. package/src/utils/cluster.ts +6 -15
  279. package/src/utils/editAsFile.ts +31 -0
  280. package/src/utils/files.ts +6 -2
  281. package/src/utils/gitlab.ts +136 -34
  282. package/src/utils/passwordstore/index.ts +19 -21
  283. package/src/utils/preferences/index.ts +6 -3
  284. package/src/utils/projects/index.ts +18 -137
  285. package/tsconfig.json +3 -7
  286. package/bin/catenv.sh +0 -1
  287. package/src/apps/shell/commands/project/commandCloudSqlProxy.ts +0 -65
  288. package/src/apps/shell/commands/project/commandConfigSecrets.ts +0 -245
  289. package/src/apps/shell/commands/project/commandEnvVars.ts +0 -17
  290. package/src/apps/shell/commands/project/commandInitGitlab.ts +0 -157
  291. package/src/apps/shell/commands/project/commandListPods.ts +0 -21
  292. package/src/apps/shell/commands/project/commandNamespace.ts +0 -12
  293. package/src/apps/shell/commands/project/commandOpenDashboard.ts +0 -27
  294. package/src/apps/shell/commands/project/commandOpenEnv.ts +0 -18
  295. package/src/apps/shell/commands/project/commandOpenLogs.ts +0 -23
  296. package/src/apps/shell/commands/project/commandVariables.ts +0 -13
  297. package/src/apps/shell/commands/project/utils/autocompletions.ts +0 -7
  298. package/src/apps/shell/commands/project/utils/ensureCluster.ts +0 -31
  299. package/src/apps/shell/commands/project/utils/ensureNamespace.ts +0 -32
  300. package/src/apps/shell/commands/project/utils/monorepo.ts +0 -45
  301. package/src/apps/shell/commands/shared/index.ts +0 -31
  302. package/src/config/clusters.ts +0 -45
  303. package/src/index.ts +0 -17
  304. package/src/types/git-repo-name.d.ts +0 -1
  305. package/src/types/yawn-yaml.d.ts +0 -1
  306. package/src/utils/dashboardToken.ts +0 -20
  307. package/src/utils/formatEnvVars.ts +0 -7
@@ -0,0 +1,73 @@
1
+ import { Config } from "@catladder/pipeline";
2
+ import { spawn, exec } from "child-process-promise";
3
+ import { writeFile } from "fs-extra";
4
+ import { dump } from "js-yaml";
5
+ import { format } from "prettier";
6
+ import { CommandInstance } from "vorpal";
7
+ import { reloadConfig } from "../../../config/getProjectConfig";
8
+ import { getGitRoot } from "../../../utils/projects";
9
+
10
+ export const writeConfig = async (
11
+ vorpal: CommandInstance,
12
+ config: Config,
13
+ options?: {
14
+ endComment?: string;
15
+ }
16
+ ) => {
17
+ const gitRoot = await getGitRoot();
18
+ const TS = "typescript (recommended)";
19
+ const { configType } = await vorpal.prompt({
20
+ type: "list",
21
+ name: "configType",
22
+ choices: [TS, "yaml"],
23
+ message: "In which format do you want the config? 🤔",
24
+ });
25
+ vorpal.log("");
26
+ if (configType === TS) {
27
+ const file = gitRoot + "/catladder.ts";
28
+ const content = format(
29
+ `
30
+ import type { Config } from "@catladder/pipeline";
31
+
32
+ const config: Config = ${JSON.stringify(config)};
33
+
34
+ export default config;
35
+
36
+
37
+ ${options?.endComment ? `/*${options.endComment}*/` : ""}
38
+
39
+ `,
40
+ {
41
+ parser: "babel",
42
+ }
43
+ );
44
+
45
+ await writeFile(file, content, {
46
+ encoding: "utf-8",
47
+ });
48
+ vorpal.log("adding type @catladder/pipeline....");
49
+ await spawn("yarn add --non-interactive @catladder/pipeline -DW", {
50
+ shell: true,
51
+ });
52
+ await exec("git add " + file);
53
+ } else {
54
+ const file = gitRoot + "/catladder.yml";
55
+ const content = dump(config);
56
+
57
+ await writeFile(
58
+ file,
59
+ content +
60
+ "\n\n" +
61
+ (options.endComment
62
+ ? "# " + options.endComment.split("\n").join("\n# ")
63
+ : ""),
64
+ {
65
+ encoding: "utf-8",
66
+ }
67
+ );
68
+ await exec("git add " + file);
69
+ }
70
+ await reloadConfig();
71
+ vorpal.log("done!");
72
+ vorpal.log("");
73
+ };
@@ -0,0 +1,30 @@
1
+ import Vorpal from "vorpal";
2
+ import {
3
+ getGitlabCi,
4
+ getProjectConfig,
5
+ } from "../../../config/getProjectConfig";
6
+ import { hasGitlabToken, setupGitlabToken } from "../../../utils/gitlab";
7
+ import { isV2, migrateV2 } from "./migration/fromv2";
8
+
9
+ export const verify = async (vorpal: Vorpal) => {
10
+ // check if has all settings
11
+
12
+ if (!(await hasGitlabToken())) {
13
+ vorpal.command("setup-gitlab-token").action(async function () {
14
+ await setupGitlabToken(this);
15
+ });
16
+ vorpal.exec("setup-gitlab-token");
17
+ }
18
+
19
+ const projectConfig = await getProjectConfig();
20
+ try {
21
+ const gitlabCi = getGitlabCi();
22
+
23
+ if (gitlabCi && !projectConfig && (await isV2())) {
24
+ vorpal.log("no project config, needs migration");
25
+ await migrateV2(vorpal);
26
+ }
27
+ } catch (e) {
28
+ // no gitroot, ignore
29
+ }
30
+ };
@@ -0,0 +1,264 @@
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 = "web",
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
+ this.log("");
253
+ this.log("You can remove the values*.yml files now.");
254
+
255
+ this.log("-------------------");
256
+ } else {
257
+ this.log(
258
+ "☝ if you want to use catladder in legacy mode, install @panter/catladder globally and invoke catladder-legacy"
259
+ );
260
+ }
261
+ });
262
+
263
+ vorpal.exec("migrate");
264
+ };
@@ -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 containsSecret = String(value)?.includes?.("$CL_");
113
+ if (containsSecret) {
114
+ for (const variable of allVariablesInGitlab) {
115
+ value = value.replace(
116
+ new RegExp("\\$" + variable.key, "g"),
117
+ variable.value
118
+ );
119
+ }
120
+ return [key, value];
121
+ }
122
+ return [key, value];
123
+ })
124
+ );
125
+ };
126
+
127
+ export const getEnvVars = async (
128
+ vorpal: CommandInstance,
129
+ env: string,
130
+ componentName: string
131
+ ) => {
132
+ const envionment = await getEnvironment(env, componentName);
133
+ // in the pipeline the secrets alreadyy exists and bash will expand them
134
+ // but here we need to manually load them
135
+ return resolveSecrets(vorpal, envionment.envVars);
136
+ };
@@ -5,13 +5,29 @@ import {
5
5
  BatchV1beta1Api,
6
6
  } from "@kubernetes/client-node";
7
7
 
8
- const kc = new KubeConfig();
8
+ const getKubeConfig = () => {
9
+ const kc = new KubeConfig();
10
+ kc.loadFromDefault();
11
+ return kc;
12
+ };
13
+ /**
14
+ * get kubernetes client. avoid reusing the instance when context get changed
15
+ * @returns kuberenetes client
16
+ */
17
+ export const getk8sApi = () => {
18
+ const kc = getKubeConfig();
9
19
 
10
- kc.loadFromDefault();
20
+ return kc.makeApiClient(CoreV1Api);
21
+ };
11
22
 
12
- const k8sApi = kc.makeApiClient(CoreV1Api);
23
+ export const getk8sApiBatch = () => {
24
+ const kc = getKubeConfig();
13
25
 
14
- export const k8sApiBatch = kc.makeApiClient(BatchV1Api);
15
- export const k8sApiBatchBeta = kc.makeApiClient(BatchV1beta1Api);
26
+ return kc.makeApiClient(BatchV1Api);
27
+ };
16
28
 
17
- export default k8sApi;
29
+ export const getk8sApiBatchBeta = () => {
30
+ const kc = getKubeConfig();
31
+
32
+ return kc.makeApiClient(BatchV1beta1Api);
33
+ };
@@ -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,12 @@
1
- import { exec } from "child-process-promise";
2
- import { findKey } from "lodash";
3
- import clusters from "../config/clusters";
1
+ import { $ } from "zx";
2
+
4
3
  export const getCurrentContext = async () =>
5
- (await exec("kubectl config current-context")).stdout.trim();
4
+ (await $`kubectl config current-context`).stdout.trim();
6
5
 
7
6
  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];
7
+ return await getCurrentContext();
14
8
  };
15
9
 
16
- export const getAllClusterNames = () => Object.keys(clusters);
17
-
18
- export const connectToCluster = async (clusterName: string) => {
19
- const { connect } = getClusterByName(clusterName);
20
- await connect();
10
+ export const connectToCluster = async (fullname: string) => {
11
+ await $`kubectl config use-context ${fullname}`;
21
12
  };