@catladder/cli 0.0.0-node16-ddfae617 → 0.0.0-refactor-env-context-9e652b63

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 (229) hide show
  1. package/bin/catenv +1 -1
  2. package/bin/catenv-dev +3 -0
  3. package/bin/catladder +1 -1
  4. package/bin/catladder-dev +3 -0
  5. package/dist/apps/catenv/catenv.d.ts +4 -1
  6. package/dist/apps/catenv/catenv.js +28 -20
  7. package/dist/apps/catenv/catenv.js.map +1 -1
  8. package/dist/apps/cli/commands/general/index.d.ts +1 -1
  9. package/dist/apps/cli/commands/general/portForward.d.ts +1 -1
  10. package/dist/apps/cli/commands/mongodb/index.d.ts +1 -1
  11. package/dist/apps/cli/commands/mongodb/projectMongoDestroyMember.d.ts +1 -1
  12. package/dist/apps/cli/commands/mongodb/projectMongoDestroyMember.js +2 -1
  13. package/dist/apps/cli/commands/mongodb/projectMongoDestroyMember.js.map +1 -1
  14. package/dist/apps/cli/commands/mongodb/projectMongoGetShell.d.ts +1 -1
  15. package/dist/apps/cli/commands/mongodb/projectMongoPortForward.d.ts +1 -1
  16. package/dist/apps/cli/commands/mongodb/projectMongoPortForward.js +25 -9
  17. package/dist/apps/cli/commands/mongodb/projectMongoPortForward.js.map +1 -1
  18. package/dist/apps/cli/commands/mongodb/utils/index.js +16 -4
  19. package/dist/apps/cli/commands/mongodb/utils/index.js.map +1 -1
  20. package/dist/apps/cli/commands/project/commandCloudSqlProxy.d.ts +1 -1
  21. package/dist/apps/cli/commands/project/commandConfigSecrets.d.ts +2 -1
  22. package/dist/apps/cli/commands/project/commandConfigSecrets.js +29 -51
  23. package/dist/apps/cli/commands/project/commandConfigSecrets.js.map +1 -1
  24. package/dist/apps/cli/commands/project/commandCopyDB.d.ts +1 -1
  25. package/dist/apps/cli/commands/project/commandCopyDB.js +1 -23
  26. package/dist/apps/cli/commands/project/commandCopyDB.js.map +1 -1
  27. package/dist/apps/cli/commands/project/commandDeletePods.d.ts +1 -1
  28. package/dist/apps/cli/commands/project/commandDeletePods.js +2 -1
  29. package/dist/apps/cli/commands/project/commandDeletePods.js.map +1 -1
  30. package/dist/apps/cli/commands/project/commandDeleteProject.d.ts +1 -1
  31. package/dist/apps/cli/commands/project/commandEnvVars.d.ts +1 -1
  32. package/dist/apps/cli/commands/project/commandGetMyTotalWorktime.d.ts +1 -1
  33. package/dist/apps/cli/commands/project/commandGetShell.d.ts +1 -1
  34. package/dist/apps/cli/commands/project/commandGetShell.js +2 -1
  35. package/dist/apps/cli/commands/project/commandGetShell.js.map +1 -1
  36. package/dist/apps/cli/commands/project/commandGitlabCi.d.ts +1 -1
  37. package/dist/apps/cli/commands/project/commandGitlabCi.js.map +1 -1
  38. package/dist/apps/cli/commands/project/commandInitProject.old.d.ts +1 -1
  39. package/dist/apps/cli/commands/project/commandListPods.d.ts +1 -1
  40. package/dist/apps/cli/commands/project/commandListPods.js +2 -2
  41. package/dist/apps/cli/commands/project/commandListPods.js.map +1 -1
  42. package/dist/apps/cli/commands/project/commandMigrateHelm3.d.ts +1 -1
  43. package/dist/apps/cli/commands/project/commandMigrateHelm3.js +1 -2
  44. package/dist/apps/cli/commands/project/commandMigrateHelm3.js.map +1 -1
  45. package/dist/apps/cli/commands/project/commandNamespace.d.ts +1 -1
  46. package/dist/apps/cli/commands/project/commandOpenCostDashboard.d.ts +1 -1
  47. package/dist/apps/cli/commands/project/commandOpenDashboard.d.ts +1 -1
  48. package/dist/apps/cli/commands/project/commandOpenDashboard.js +19 -20
  49. package/dist/apps/cli/commands/project/commandOpenDashboard.js.map +1 -1
  50. package/dist/apps/cli/commands/project/commandOpenEnv.d.ts +1 -1
  51. package/dist/apps/cli/commands/project/commandOpenGit.d.ts +1 -1
  52. package/dist/apps/cli/commands/project/commandOpenGit.js +2 -7
  53. package/dist/apps/cli/commands/project/commandOpenGit.js.map +1 -1
  54. package/dist/apps/cli/commands/project/commandOpenGrafana.d.ts +1 -1
  55. package/dist/apps/cli/commands/project/commandOpenGrafanaPod.d.ts +1 -1
  56. package/dist/apps/cli/commands/project/commandOpenGrafanaPod.js +2 -1
  57. package/dist/apps/cli/commands/project/commandOpenGrafanaPod.js.map +1 -1
  58. package/dist/apps/cli/commands/project/commandOpenLogs.d.ts +1 -1
  59. package/dist/apps/cli/commands/project/commandOpenLogs.js +7 -20
  60. package/dist/apps/cli/commands/project/commandOpenLogs.js.map +1 -1
  61. package/dist/apps/cli/commands/project/commandPauseProject.d.ts +1 -1
  62. package/dist/apps/cli/commands/project/commandPortForward.d.ts +1 -1
  63. package/dist/apps/cli/commands/project/commandPortForward.js +2 -1
  64. package/dist/apps/cli/commands/project/commandPortForward.js.map +1 -1
  65. package/dist/apps/cli/commands/project/commandSecretsClearBackups.d.ts +5 -0
  66. package/dist/apps/cli/commands/project/commandSecretsClearBackups.js +90 -0
  67. package/dist/apps/cli/commands/project/commandSecretsClearBackups.js.map +1 -0
  68. package/dist/apps/cli/commands/project/commandSetup.d.ts +1 -1
  69. package/dist/apps/cli/commands/project/commandTriggerCronjob.d.ts +1 -1
  70. package/dist/apps/cli/commands/project/commandTriggerCronjob.js.map +1 -1
  71. package/dist/apps/cli/commands/project/index.d.ts +1 -1
  72. package/dist/apps/cli/commands/project/index.js +2 -0
  73. package/dist/apps/cli/commands/project/index.js.map +1 -1
  74. package/dist/apps/cli/commands/project/setup/index.d.ts +1 -1
  75. package/dist/apps/cli/commands/project/setup/setupAccessTokens.d.ts +1 -1
  76. package/dist/apps/cli/commands/project/setup/setupAccessTokens.js +5 -4
  77. package/dist/apps/cli/commands/project/setup/setupAccessTokens.js.map +1 -1
  78. package/dist/apps/cli/commands/project/setup/setupCloudRun.d.ts +3 -0
  79. package/dist/apps/cli/commands/project/setup/setupCloudRun.js +101 -0
  80. package/dist/apps/cli/commands/project/setup/setupCloudRun.js.map +1 -0
  81. package/dist/apps/cli/commands/project/setup/setupCloudSQL.d.ts +3 -0
  82. package/dist/apps/cli/commands/project/setup/setupCloudSQL.js +56 -0
  83. package/dist/apps/cli/commands/project/setup/setupCloudSQL.js.map +1 -0
  84. package/dist/apps/cli/commands/project/setup/setupContext.d.ts +2 -2
  85. package/dist/apps/cli/commands/project/setup/setupContext.js +17 -3
  86. package/dist/apps/cli/commands/project/setup/setupContext.js.map +1 -1
  87. package/dist/apps/cli/commands/project/setup/setupKubernetes.d.ts +2 -2
  88. package/dist/apps/cli/commands/project/setup/setupKubernetes.js +12 -16
  89. package/dist/apps/cli/commands/project/setup/setupKubernetes.js.map +1 -1
  90. package/dist/apps/cli/commands/project/utils/ensureNamespace.d.ts +1 -1
  91. package/dist/apps/cli/commands/project/utils/ensureNamespace.js.map +1 -1
  92. package/dist/apps/cli/commands/project/utils/showProjectBanner.d.ts +1 -1
  93. package/dist/apps/cli/commands/theStuffThatReallyMatters/index.d.ts +1 -1
  94. package/dist/apps/cli/config/writeConfig.d.ts +2 -2
  95. package/dist/apps/cli/verify/index.d.ts +1 -1
  96. package/dist/apps/cli/verify/migration/fromv2.d.ts +1 -1
  97. package/dist/apps/cli/verify/migration/fromv2.js.map +1 -1
  98. package/dist/apps/cli/verify/migration/migrateSecrets.d.ts +3 -3
  99. package/dist/apps/cli/verify/migration/migrateSecrets.js +4 -3
  100. package/dist/apps/cli/verify/migration/migrateSecrets.js.map +1 -1
  101. package/dist/apps/cli/verify/migration/oldGitlabCi.d.ts +1 -1
  102. package/dist/bundles/catenv/index.js +44322 -0
  103. package/dist/bundles/catenv/xdg-open +1066 -0
  104. package/dist/bundles/cli/clipboard_i686.exe +0 -0
  105. package/dist/bundles/cli/clipboard_x86_64.exe +0 -0
  106. package/dist/bundles/cli/exec-child.js +39 -0
  107. package/dist/bundles/cli/index.js +357696 -0
  108. package/dist/bundles/cli/xdg-open +1066 -0
  109. package/dist/bundles/cli/xsel +0 -0
  110. package/dist/catenv.js +3 -3
  111. package/dist/catenv.js.map +1 -1
  112. package/dist/cli.js +0 -7
  113. package/dist/cli.js.map +1 -1
  114. package/dist/config/constants.d.ts +0 -1
  115. package/dist/config/constants.js +1 -2
  116. package/dist/config/constants.js.map +1 -1
  117. package/dist/config/getProjectConfig.d.ts +3 -6
  118. package/dist/config/getProjectConfig.js +12 -7
  119. package/dist/config/getProjectConfig.js.map +1 -1
  120. package/dist/config/parseChoice.d.ts +4 -0
  121. package/dist/config/parseChoice.js +9 -0
  122. package/dist/config/parseChoice.js.map +1 -0
  123. package/dist/gcloud/artifactsRegistry.d.ts +5 -0
  124. package/dist/gcloud/artifactsRegistry.js +59 -0
  125. package/dist/gcloud/artifactsRegistry.js.map +1 -0
  126. package/dist/gcloud/cloudRun/getCloudRunDomainSuffix.d.ts +2 -0
  127. package/dist/gcloud/cloudRun/getCloudRunDomainSuffix.js +67 -0
  128. package/dist/gcloud/cloudRun/getCloudRunDomainSuffix.js.map +1 -0
  129. package/dist/gcloud/cloudRun/openCloudRunDashboards.d.ts +3 -0
  130. package/dist/gcloud/cloudRun/openCloudRunDashboards.js +62 -0
  131. package/dist/gcloud/cloudRun/openCloudRunDashboards.js.map +1 -0
  132. package/dist/gcloud/enableServices.d.ts +3 -0
  133. package/dist/gcloud/enableServices.js +63 -0
  134. package/dist/gcloud/enableServices.js.map +1 -0
  135. package/dist/gcloud/openDashboard.d.ts +2 -0
  136. package/dist/{apps/cli/commands/shared/index.js → gcloud/openDashboard.js} +23 -27
  137. package/dist/gcloud/openDashboard.js.map +1 -0
  138. package/dist/gcloud/serviceAccounts.d.ts +12 -0
  139. package/dist/gcloud/serviceAccounts.js +144 -0
  140. package/dist/gcloud/serviceAccounts.js.map +1 -0
  141. package/dist/kubernetes/index.d.ts +3 -0
  142. package/dist/kubernetes/index.js +88 -0
  143. package/dist/kubernetes/index.js.map +1 -0
  144. package/dist/kubernetes/openKubernetesDashboards.d.ts +4 -0
  145. package/dist/kubernetes/openKubernetesDashboards.js +94 -0
  146. package/dist/kubernetes/openKubernetesDashboards.js.map +1 -0
  147. package/dist/tsconfig.tsbuildinfo +1 -1
  148. package/dist/utils/cluster.js +3 -8
  149. package/dist/utils/cluster.js.map +1 -1
  150. package/dist/utils/gitlab.d.ts +5 -3
  151. package/dist/utils/gitlab.js +165 -46
  152. package/dist/utils/gitlab.js.map +1 -1
  153. package/dist/utils/passwordstore/index.d.ts +0 -1
  154. package/dist/utils/passwordstore/index.js +1 -64
  155. package/dist/utils/passwordstore/index.js.map +1 -1
  156. package/dist/utils/projects/index.d.ts +0 -3
  157. package/dist/utils/projects/index.js +3 -53
  158. package/dist/utils/projects/index.js.map +1 -1
  159. package/package.json +24 -22
  160. package/scripts/bundle +4 -0
  161. package/src/apps/catenv/catenv.ts +15 -8
  162. package/src/apps/cli/commands/general/index.ts +1 -1
  163. package/src/apps/cli/commands/general/portForward.ts +1 -1
  164. package/src/apps/cli/commands/mongodb/index.ts +1 -1
  165. package/src/apps/cli/commands/mongodb/projectMongoDestroyMember.ts +3 -5
  166. package/src/apps/cli/commands/mongodb/projectMongoGetShell.ts +1 -1
  167. package/src/apps/cli/commands/mongodb/projectMongoPortForward.ts +16 -1
  168. package/src/apps/cli/commands/mongodb/utils/index.ts +19 -11
  169. package/src/apps/cli/commands/project/commandCloudSqlProxy.ts +1 -1
  170. package/src/apps/cli/commands/project/commandConfigSecrets.ts +12 -31
  171. package/src/apps/cli/commands/project/commandCopyDB.ts +3 -2
  172. package/src/apps/cli/commands/project/commandDeletePods.ts +3 -5
  173. package/src/apps/cli/commands/project/commandDeleteProject.ts +1 -1
  174. package/src/apps/cli/commands/project/commandEnvVars.ts +1 -1
  175. package/src/apps/cli/commands/project/commandGetMyTotalWorktime.ts +1 -1
  176. package/src/apps/cli/commands/project/commandGetShell.ts +3 -5
  177. package/src/apps/cli/commands/project/commandGitlabCi.ts +2 -1
  178. package/src/apps/cli/commands/project/commandInitProject.old.ts +1 -1
  179. package/src/apps/cli/commands/project/commandListPods.ts +2 -2
  180. package/src/apps/cli/commands/project/commandMigrateHelm3.ts +4 -3
  181. package/src/apps/cli/commands/project/commandNamespace.ts +1 -1
  182. package/src/apps/cli/commands/project/commandOpenCostDashboard.ts +1 -1
  183. package/src/apps/cli/commands/project/commandOpenDashboard.ts +12 -32
  184. package/src/apps/cli/commands/project/commandOpenEnv.ts +1 -1
  185. package/src/apps/cli/commands/project/commandOpenGit.ts +3 -3
  186. package/src/apps/cli/commands/project/commandOpenGrafana.ts +1 -1
  187. package/src/apps/cli/commands/project/commandOpenGrafanaPod.ts +3 -5
  188. package/src/apps/cli/commands/project/commandOpenLogs.ts +4 -35
  189. package/src/apps/cli/commands/project/commandPauseProject.ts +1 -1
  190. package/src/apps/cli/commands/project/commandPortForward.ts +3 -5
  191. package/src/apps/cli/commands/project/commandSecretsClearBackups.ts +27 -0
  192. package/src/apps/cli/commands/project/commandSetup.ts +1 -1
  193. package/src/apps/cli/commands/project/commandTriggerCronjob.ts +3 -2
  194. package/src/apps/cli/commands/project/index.ts +3 -1
  195. package/src/apps/cli/commands/project/setup/index.ts +1 -1
  196. package/src/apps/cli/commands/project/setup/setupAccessTokens.ts +23 -11
  197. package/src/apps/cli/commands/project/setup/setupCloudRun.ts +74 -0
  198. package/src/apps/cli/commands/project/setup/setupCloudSQL.ts +19 -0
  199. package/src/apps/cli/commands/project/setup/setupContext.ts +12 -2
  200. package/src/apps/cli/commands/project/setup/setupKubernetes.ts +34 -27
  201. package/src/apps/cli/commands/project/utils/ensureNamespace.ts +4 -2
  202. package/src/apps/cli/commands/project/utils/showProjectBanner.ts +1 -1
  203. package/src/apps/cli/commands/theStuffThatReallyMatters/index.ts +1 -1
  204. package/src/apps/cli/config/writeConfig.ts +2 -2
  205. package/src/apps/cli/verify/index.ts +1 -1
  206. package/src/apps/cli/verify/migration/fromv2.ts +4 -7
  207. package/src/apps/cli/verify/migration/migrateSecrets.ts +9 -4
  208. package/src/apps/cli/verify/migration/oldGitlabCi.ts +1 -1
  209. package/src/catenv.ts +6 -3
  210. package/src/cli.ts +1 -7
  211. package/src/config/constants.ts +0 -2
  212. package/src/config/getProjectConfig.ts +5 -8
  213. package/src/config/parseChoice.ts +4 -0
  214. package/src/gcloud/artifactsRegistry.ts +16 -0
  215. package/src/gcloud/cloudRun/getCloudRunDomainSuffix.ts +35 -0
  216. package/src/gcloud/cloudRun/openCloudRunDashboards.ts +22 -0
  217. package/src/gcloud/enableServices.ts +14 -0
  218. package/src/gcloud/openDashboard.ts +19 -0
  219. package/src/gcloud/serviceAccounts.ts +101 -0
  220. package/src/kubernetes/index.ts +27 -0
  221. package/src/kubernetes/openKubernetesDashboards.ts +52 -0
  222. package/src/types/child-process-promise.d.ts +36 -1
  223. package/src/utils/cluster.ts +3 -3
  224. package/src/utils/gitlab.ts +137 -26
  225. package/src/utils/passwordstore/index.ts +2 -30
  226. package/src/utils/projects/index.ts +3 -24
  227. package/dist/apps/cli/commands/shared/index.d.ts +0 -3
  228. package/dist/apps/cli/commands/shared/index.js.map +0 -1
  229. package/src/apps/cli/commands/shared/index.ts +0 -36
@@ -1,14 +1,10 @@
1
- import Vorpal from "vorpal";
1
+ import type Vorpal from "vorpal";
2
2
  import {
3
3
  getPipelineContextByChoice,
4
4
  parseChoice,
5
5
  } from "../../../../config/getProjectConfig";
6
- import { getCurrentConnectedClusterName } from "../../../../utils/cluster";
7
- import { getProjectNamespace } from "../../../../utils/projects";
8
- import { getGoogleAuthUserNumber } from "../../utils/getGoogleAuthUserNumber";
9
- import { openGoogleCloudLogs } from "../shared";
6
+ import { openGoogleCloudLogs } from "../../../../kubernetes/openKubernetesDashboards";
10
7
  import { envAndComponents } from "./utils/autocompletions";
11
- import ensureCluster from "./utils/ensureCluster";
12
8
 
13
9
  export default async (vorpal: Vorpal) =>
14
10
  vorpal
@@ -19,34 +15,7 @@ export default async (vorpal: Vorpal) =>
19
15
  .autocomplete(await envAndComponents())
20
16
  .action(async function ({ envComponent }) {
21
17
  const { env, componentName } = parseChoice(envComponent);
22
- const { componentConfig, environment } = await getPipelineContextByChoice(
23
- env,
24
- componentName
25
- );
18
+ const context = await getPipelineContextByChoice(env, componentName);
26
19
 
27
- if (
28
- !componentConfig.deploy ||
29
- componentConfig.deploy.type !== "kubernetes"
30
- ) {
31
- throw new Error(
32
- "only kubernetes deployments are supported at the moment"
33
- );
34
- }
35
-
36
- if (
37
- !componentConfig.deploy.cluster ||
38
- componentConfig.deploy.cluster.type !== "gcloud"
39
- ) {
40
- throw new Error("no gcloud custer configured");
41
- }
42
- // currently only supports kubernetes
43
- const namespace = environment.envVars.KUBE_NAMESPACE;
44
-
45
- const authGoogleNumber = await getGoogleAuthUserNumber.call(this, vorpal);
46
-
47
- await openGoogleCloudLogs(
48
- componentConfig.deploy.cluster,
49
- namespace,
50
- authGoogleNumber
51
- );
20
+ await openGoogleCloudLogs(this, context);
52
21
  });
@@ -1,4 +1,4 @@
1
- import Vorpal from "vorpal";
1
+ import type Vorpal from "vorpal";
2
2
  import { exec } from "child-process-promise";
3
3
  import { getProjectNamespace } from "../../../../utils/projects";
4
4
  import { envAndComponents } from "./utils/autocompletions";
@@ -1,10 +1,8 @@
1
- import Vorpal from "vorpal";
1
+ import type Vorpal from "vorpal";
2
+ import { getProjectPodNames } from "../../../../kubernetes";
2
3
  import { logError } from "../../../../utils/log";
3
4
  import { startPortForward } from "../../../../utils/portForward";
4
- import {
5
- getProjectNamespace,
6
- getProjectPodNames,
7
- } from "../../../../utils/projects";
5
+ import { getProjectNamespace } from "../../../../utils/projects";
8
6
  import { envAndComponents } from "./utils/autocompletions";
9
7
  import ensureCluster from "./utils/ensureCluster";
10
8
 
@@ -0,0 +1,27 @@
1
+ /* eslint-disable no-constant-condition */
2
+ import type Vorpal from "vorpal";
3
+ import type { CommandInstance } from "vorpal";
4
+ import { clearBackups } from "../../../../utils/gitlab";
5
+ import { allEnvsAndAllComponents } from "./utils/autocompletions";
6
+
7
+ export const projectSecretsClearBackups = async (
8
+ vorpal: CommandInstance,
9
+ keep = 3
10
+ ) => {
11
+ await clearBackups(vorpal, keep);
12
+ };
13
+
14
+ export default async (vorpal: Vorpal) => {
15
+ vorpal
16
+ .command("project-secrets-clear-backups", "clears all backups")
17
+ .autocomplete(await allEnvsAndAllComponents())
18
+ .action(async function () {
19
+ const { keep } = await this.prompt({
20
+ type: "number",
21
+ name: "keep",
22
+ default: 1,
23
+ message: "How many backups should we keep? 🤔",
24
+ });
25
+ return await projectSecretsClearBackups(this, keep);
26
+ });
27
+ };
@@ -1,4 +1,4 @@
1
- import Vorpal from "vorpal";
1
+ import type Vorpal from "vorpal";
2
2
  import { setupProject } from "./setup";
3
3
 
4
4
  export default async (vorpal: Vorpal) =>
@@ -1,6 +1,7 @@
1
- import { V1Job, V1ObjectMeta } from "@kubernetes/client-node";
1
+ import type { V1ObjectMeta } from "@kubernetes/client-node";
2
+ import { V1Job } from "@kubernetes/client-node";
2
3
 
3
- import Vorpal from "vorpal";
4
+ import type Vorpal from "vorpal";
4
5
  import { getk8sApiBatch, getk8sApiBatchBeta } from "../../../../k8sApi";
5
6
  import { logError } from "../../../../utils/log";
6
7
  import { namespaceAutoCompletion } from "../general/namespaceAutoCompletion";
@@ -1,4 +1,4 @@
1
- import Vorpal from "vorpal";
1
+ import type Vorpal from "vorpal";
2
2
  import commandCloudSqlProxy from "./commandCloudSqlProxy";
3
3
  import commandConfigSecrets from "./commandConfigSecrets";
4
4
  import commandCopyDB from "./commandCopyDB";
@@ -24,6 +24,7 @@ import commandPortForward from "./commandPortForward";
24
24
  import commandTriggerCronjob from "./commandTriggerCronjob";
25
25
 
26
26
  import commandOpenGrafanaPod from "./commandOpenGrafanaPod";
27
+ import commandSecretsClearBackups from "./commandSecretsClearBackups";
27
28
 
28
29
  export default async (vorpal: Vorpal) => {
29
30
  commandSetup(vorpal);
@@ -48,6 +49,7 @@ export default async (vorpal: Vorpal) => {
48
49
  commandOpenEnv(vorpal);
49
50
  commandTriggerCronjob(vorpal);
50
51
  commandConfigSecrets(vorpal);
52
+ commandSecretsClearBackups(vorpal);
51
53
  commandDeletePods(vorpal);
52
54
  commandCopyDB(vorpal);
53
55
 
@@ -1,4 +1,4 @@
1
- import { CommandInstance } from "vorpal";
1
+ import type { CommandInstance } from "vorpal";
2
2
  import { getAllPipelineContexts } from "../../../../../config/getProjectConfig";
3
3
  import { projectConfigSecrets } from "../commandConfigSecrets";
4
4
  import { setupAccessTokens } from "./setupAccessTokens";
@@ -1,5 +1,5 @@
1
1
  import open from "open";
2
- import { CommandInstance } from "vorpal";
2
+ import type { CommandInstance } from "vorpal";
3
3
  import { doGitlabRequest, getProjectInfo } from "../../../../../utils/gitlab";
4
4
 
5
5
  export const setupAccessTokens = async (instance: CommandInstance) => {
@@ -18,7 +18,7 @@ export const setupAccessTokens = async (instance: CommandInstance) => {
18
18
  "I need add a GL_TOKEN to the project, so that semantic release will work\n"
19
19
  );
20
20
  instance.log(
21
- "👉 Please please create a project access token in gitlab and copy its value into clipboard\n\n - name: something like 'semantic-release'\n - expires: leave empty\n - scopes: api, read_repository"
21
+ "👉 Please please create a project access token in gitlab and copy its value into clipboard\n\n - name: something like 'semantic-release'\n - expires: leave empty\n - role: maintainer - scopes: api, read_repository"
22
22
  );
23
23
  instance.log("\n");
24
24
 
@@ -43,10 +43,17 @@ export const setupAccessTokens = async (instance: CommandInstance) => {
43
43
  name: "GL_TOKEN",
44
44
  message: "Access Token: ",
45
45
  });
46
- await doGitlabRequest(instance, `projects/${projectId}/variables`, {
47
- key: "GL_TOKEN",
48
- value: GL_TOKEN,
49
- });
46
+
47
+ await doGitlabRequest(
48
+ instance,
49
+ `projects/${projectId}/variables`,
50
+ {
51
+ key: "GL_TOKEN",
52
+ value: GL_TOKEN,
53
+ masked: true,
54
+ },
55
+ "POST"
56
+ );
50
57
  }
51
58
 
52
59
  const deploy_tokens = await doGitlabRequest(
@@ -63,10 +70,15 @@ export const setupAccessTokens = async (instance: CommandInstance) => {
63
70
  "I will setup the 'GitLab Deploy Token', so Kubernetes can pull images from this project."
64
71
  );
65
72
 
66
- await doGitlabRequest(instance, `projects/${projectId}/deploy_tokens`, {
67
- id: projectId,
68
- name: "gitlab-deploy-token",
69
- scopes: ["read_registry"],
70
- });
73
+ await doGitlabRequest(
74
+ instance,
75
+ `projects/${projectId}/deploy_tokens`,
76
+ {
77
+ id: projectId,
78
+ name: "gitlab-deploy-token",
79
+ scopes: ["read_registry"],
80
+ },
81
+ "POST"
82
+ );
71
83
  }
72
84
  };
@@ -0,0 +1,74 @@
1
+ import type { Context } from "@catladder/pipeline";
2
+ import {
3
+ GCLOUD_DEPLOY_CREDENTIALS_KEY,
4
+ GCLOUD_RUN_CANONICAL_HOST_SUFFIX,
5
+ isOfDeployType,
6
+ } from "@catladder/pipeline";
7
+
8
+ import type { CommandInstance } from "vorpal";
9
+ import { upsertGcloudArtifactsRegistry } from "../../../../../gcloud/artifactsRegistry";
10
+ import { getCloudRunDomainSuffix } from "../../../../../gcloud/cloudRun/getCloudRunDomainSuffix";
11
+ import { enableGCloudServices } from "../../../../../gcloud/enableServices";
12
+ import { upsertGcloudServiceAccountAndSaveSecret } from "../../../../../gcloud/serviceAccounts";
13
+ import { upsertAllVariables } from "../../../../../utils/gitlab";
14
+
15
+ export const setupCloudRun = async (
16
+ instance: CommandInstance,
17
+ context: Context
18
+ ) => {
19
+ if (!isOfDeployType(context.componentConfig.deploy, "google-cloudrun")) {
20
+ throw new Error("deploy config is not of type 'google-cloudrun'");
21
+ }
22
+
23
+ const config = context.componentConfig.deploy;
24
+
25
+ // enable services
26
+
27
+ instance.log("enable required servies...");
28
+ await enableGCloudServices(
29
+ ["run.googleapis.com", "artifactregistry.googleapis.com"],
30
+ config
31
+ );
32
+ instance.log("upsert artifacts registry...");
33
+ await upsertGcloudArtifactsRegistry(config);
34
+
35
+ instance.log("upsert deploy service account...");
36
+ await upsertGcloudServiceAccountAndSaveSecret(
37
+ instance,
38
+ context,
39
+ {
40
+ projectId: config.projectId,
41
+ displayName: "Catladder gcloud deploy",
42
+ description: "This service account deploys to google cloud",
43
+ name: "cl-d",
44
+ // TODO: run.admin is a bit much, would be better to follow https://stackoverflow.com/questions/55788714/deploying-to-cloud-run-with-a-custom-service-account-failed-with-iam-serviceacco
45
+ roles: [
46
+ "roles/artifactregistry.repoAdmin",
47
+ "roles/run.admin",
48
+ "roles/iam.serviceAccountUser",
49
+ ],
50
+ },
51
+ GCLOUD_DEPLOY_CREDENTIALS_KEY
52
+ );
53
+
54
+ // gcloud run automatically gives us a hostname
55
+ // but the pipeline need to know it before deployment
56
+ // so we get this through some magic and add this as a ci/cd variable
57
+ // the pipeline than can use this to construct the canonical host
58
+ instance.log(
59
+ "get service domain suffix... that might take a while initially"
60
+ );
61
+ const suffix = await getCloudRunDomainSuffix(config);
62
+ instance.log("domain suffix: " + suffix);
63
+
64
+ await upsertAllVariables(
65
+ instance,
66
+ {
67
+ [GCLOUD_RUN_CANONICAL_HOST_SUFFIX]: suffix,
68
+ },
69
+ context.environment.shortName,
70
+ context.componentName,
71
+ false, // backup
72
+ false // masked
73
+ );
74
+ };
@@ -0,0 +1,19 @@
1
+ import type { Context } from "@catladder/pipeline";
2
+ import { getCloudSQLConfig, hasCloudSQL } from "@catladder/pipeline";
3
+ import type { CommandInstance } from "vorpal";
4
+
5
+ export const setupCloudSQL = async (
6
+ instance: CommandInstance,
7
+ context: Context
8
+ ) => {
9
+ if (!hasCloudSQL(context)) {
10
+ throw new Error("cannot setup cloudsql, as it has none");
11
+ }
12
+ const config = getCloudSQLConfig(context);
13
+ instance.log("");
14
+ instance.log(
15
+ "! make sure to provide cloudsqlProxyCredentials for the cloud sql service account in " +
16
+ config.projectId
17
+ );
18
+ instance.log("");
19
+ };
@@ -1,5 +1,8 @@
1
- import { Context, isOfDeployType } from "@catladder/pipeline";
2
- import { CommandInstance } from "vorpal";
1
+ import type { Context } from "@catladder/pipeline";
2
+ import { isOfDeployType, hasCloudSQL } from "@catladder/pipeline";
3
+ import type { CommandInstance } from "vorpal";
4
+ import { setupCloudRun } from "./setupCloudRun";
5
+ import { setupCloudSQL } from "./setupCloudSQL";
3
6
  import { setupKubernetes } from "./setupKubernetes";
4
7
 
5
8
  export const setupContext = async (
@@ -19,6 +22,13 @@ export const setupContext = async (
19
22
  "..."
20
23
  );
21
24
  instance.log("");
25
+ if (isOfDeployType(context.componentConfig.deploy, "google-cloudrun")) {
26
+ await setupCloudRun(instance, context);
27
+ }
28
+ if (hasCloudSQL(context)) {
29
+ await setupCloudSQL(instance, context);
30
+ }
31
+
22
32
  const deployConfig = context.componentConfig.deploy;
23
33
  if (isOfDeployType(deployConfig, "kubernetes")) {
24
34
  await setupKubernetes(instance, context);
@@ -1,10 +1,10 @@
1
+ import type { Context } from "@catladder/pipeline";
1
2
  import {
2
- Context,
3
3
  getFullKubernetesClusterName,
4
4
  isOfDeployType,
5
5
  } from "@catladder/pipeline";
6
- import { CommandInstance } from "vorpal";
7
- import { $ } from "zx";
6
+ import type { CommandInstance } from "vorpal";
7
+ import { exec } from "child-process-promise";
8
8
  import { connectToCluster } from "../../../../../utils/cluster";
9
9
  import { upsertAllVariables } from "../../../../../utils/gitlab";
10
10
  import ensureNamespace from "../utils/ensureNamespace";
@@ -33,34 +33,41 @@ export const setupKubernetes = async (
33
33
  // we currently create one per component to better separate them
34
34
  instance.log("ensuring service accounts...");
35
35
  const serviceAccountName = `cl-${context.componentName}-deploy`;
36
- const KUBE_URL =
37
- await $`TERM=dumb kubectl cluster-info | grep -E 'Kubernetes master|Kubernetes control plane' | awk '/http/ {print $NF}'`.then(
38
- (s) => s.stdout.trim()
39
- );
36
+ const KUBE_URL = await exec(
37
+ `TERM=dumb kubectl cluster-info | grep -E 'Kubernetes master|Kubernetes control plane' | awk '/http/ {print $NF}'`
38
+ ).then((s) => s.stdout.trim());
40
39
 
41
40
  // first upsert service acount in the ns
42
41
  try {
43
- await $`kubectl delete serviceaccount --namespace ${namespace} ${serviceAccountName}`;
44
- await $`kubectl delete rolebinding --namespace ${namespace} ${serviceAccountName}`;
45
- await $`kubectl delete role --namespace ${namespace} ${serviceAccountName}`;
42
+ await exec(
43
+ `kubectl delete serviceaccount --namespace ${namespace} ${serviceAccountName}`
44
+ );
45
+ await exec(
46
+ `kubectl delete rolebinding --namespace ${namespace} ${serviceAccountName}`
47
+ );
48
+ await exec(
49
+ `kubectl delete role --namespace ${namespace} ${serviceAccountName}`
50
+ );
46
51
  } catch (e) {
47
52
  // ignore
48
53
  }
49
54
 
50
- await $`kubectl create serviceaccount --namespace ${namespace} ${serviceAccountName}`;
55
+ await exec(
56
+ `kubectl create serviceaccount --namespace ${namespace} ${serviceAccountName}`
57
+ );
51
58
 
52
59
  // upsert role in the ns
53
60
 
54
- await $`cat <<EOF | kubectl apply -f -
61
+ await exec(`cat <<EOF | kubectl apply -f -
55
62
  kind: Role
56
63
  apiVersion: rbac.authorization.k8s.io/v1
57
64
  metadata:
58
65
  namespace: ${namespace}
59
66
  name: ${serviceAccountName}
60
67
  rules:
61
- - apiGroups: ["", "extensions", "apps", "networking.k8s.io", "batch", "autoscaling"]
62
- resources: ["deployments", "replicasets", "statefulsets", "pods", "secrets", "configmaps", "services", "ingresses", "serviceaccounts", "jobs", "cronjobs", "horizontalpodautoscalers"]
63
- verbs: ["get", "list", "watch", "create", "update", "patch", "delete"] # You can also use ["*"]
68
+ - apiGroups: ["", "extensions", "apps", "networking.k8s.io", "batch", "autoscaling", "rbac.authorization.k8s.io","snapshot.storage.k8s.io"]
69
+ resources: ["deployments", "replicasets", "statefulsets", "pods", "secrets", "configmaps", "services", "ingresses", "serviceaccounts", "roles", "rolebindings", "jobs", "cronjobs", "horizontalpodautoscalers", "persistentvolumeclaims", "volumesnapshots"]
70
+ verbs: ["*"]
64
71
  ---
65
72
  kind: RoleBinding
66
73
  apiVersion: rbac.authorization.k8s.io/v1
@@ -76,20 +83,19 @@ roleRef:
76
83
  name: ${serviceAccountName}
77
84
  apiGroup: rbac.authorization.k8s.io
78
85
  EOF
79
- `;
86
+ `);
80
87
 
81
88
  // get token name
82
- const tokenName =
83
- await $`kubectl get serviceaccount --namespace ${namespace} ${serviceAccountName} -o jsonpath='{.secrets[0].name}'`;
89
+ const tokenName = await exec(
90
+ `kubectl get serviceaccount --namespace ${namespace} ${serviceAccountName} -o jsonpath='{.secrets[0].name}'`
91
+ ).then((c) => c.stdout.trim());
84
92
 
85
- const KUBE_CA_PEM =
86
- await $`kubectl get secret ${tokenName} --namespace ${namespace} -o jsonpath="{['data']['ca\\.crt']}"`.then(
87
- (c) => c.stdout.trim()
88
- );
89
- const KUBE_TOKEN =
90
- await $`kubectl get secret ${tokenName} --namespace ${namespace} -o jsonpath="{['data']['token']}" | base64 --decode`.then(
91
- (c) => c.stdout.trim()
92
- );
93
+ const KUBE_CA_PEM = await exec(
94
+ `kubectl get secret ${tokenName} --namespace ${namespace} -o jsonpath="{['data']['ca\\.crt']}"`
95
+ ).then((c) => c.stdout.trim());
96
+ const KUBE_TOKEN = await exec(
97
+ `kubectl get secret ${tokenName} --namespace ${namespace} -o jsonpath="{['data']['token']}" | base64 --decode`
98
+ ).then((c) => c.stdout.trim());
93
99
 
94
100
  const vars = {
95
101
  KUBE_TOKEN,
@@ -106,7 +112,8 @@ EOF
106
112
  instance,
107
113
  vars,
108
114
  context.environment.shortName,
109
- context.componentName
115
+ context.componentName,
116
+ false // no backup
110
117
  );
111
118
  instance.log("done!");
112
119
  };
@@ -1,5 +1,7 @@
1
- import { Context, getKubernetesNamespace } from "@catladder/pipeline";
2
- import { V1Namespace, V1ObjectMeta } from "@kubernetes/client-node";
1
+ import type { Context} from "@catladder/pipeline";
2
+ import { getKubernetesNamespace } from "@catladder/pipeline";
3
+ import type { V1ObjectMeta } from "@kubernetes/client-node";
4
+ import { V1Namespace } from "@kubernetes/client-node";
3
5
  import { getk8sApi } from "../../../../../k8sApi";
4
6
 
5
7
  export default async function (context: Context) {
@@ -1,4 +1,4 @@
1
- import Vorpal from "vorpal";
1
+ import type Vorpal from "vorpal";
2
2
  import { getProjectConfig } from "../../../../../config/getProjectConfig";
3
3
 
4
4
  export const showProjectBanner = async (vorpal: Vorpal) => {
@@ -1,6 +1,6 @@
1
1
  import { spawn } from "child-process-promise";
2
2
  import fetch from "node-fetch";
3
- import Vorpal from "vorpal";
3
+ import type Vorpal from "vorpal";
4
4
 
5
5
  export default async (vorpal: Vorpal) => {
6
6
  vorpal.command("dadjoke", "something for jonas.").action(async function () {
@@ -1,9 +1,9 @@
1
- import { Config } from "@catladder/pipeline";
1
+ import type { Config } from "@catladder/pipeline";
2
2
  import { spawn, exec } from "child-process-promise";
3
3
  import { writeFile } from "fs-extra";
4
4
  import { dump } from "js-yaml";
5
5
  import { format } from "prettier";
6
- import { CommandInstance } from "vorpal";
6
+ import type { CommandInstance } from "vorpal";
7
7
  import { getGitRoot } from "../../../utils/projects";
8
8
 
9
9
  export const writeConfig = async (
@@ -1,4 +1,4 @@
1
- import Vorpal from "vorpal";
1
+ import type Vorpal from "vorpal";
2
2
  import {
3
3
  getGitlabCi,
4
4
  getProjectConfig,
@@ -1,4 +1,4 @@
1
- import {
1
+ import type {
2
2
  BuildConfig,
3
3
  ComponentConfig,
4
4
  Config,
@@ -14,7 +14,7 @@ import {
14
14
  } from "fs-extra";
15
15
  import { isEmpty } from "lodash";
16
16
  import { join } from "path";
17
- import Vorpal from "vorpal";
17
+ import type Vorpal from "vorpal";
18
18
  import {
19
19
  getGitlabCi,
20
20
  getGitlabCiFilePath,
@@ -24,11 +24,8 @@ import { syncBitwarden } from "../../../../utils/passwordstore";
24
24
  import { getGitRoot } from "../../../../utils/projects";
25
25
  import { writeConfig } from "../../config/writeConfig";
26
26
  import { migrateSecrets } from "./migrateSecrets";
27
- import {
28
- detectBuildConfig,
29
- isOldInclude,
30
- OldGitlabCiFile,
31
- } from "./oldGitlabCi";
27
+ import type { OldGitlabCiFile } from "./oldGitlabCi";
28
+ import { detectBuildConfig, isOldInclude } from "./oldGitlabCi";
32
29
  export const LEGACY_ENVS = [
33
30
  "dev-local",
34
31
  "dev",
@@ -1,10 +1,11 @@
1
- import { Config, getEnvironment } from "@catladder/pipeline";
1
+ import type { Config } from "@catladder/pipeline";
2
+ import { getEnvironment } from "@catladder/pipeline";
2
3
  import { load } from "js-yaml";
3
4
  import { pick } from "lodash";
4
- import { CommandInstance } from "vorpal";
5
+ import type { CommandInstance } from "vorpal";
5
6
  import { upsertAllVariables } from "../../../../utils/gitlab";
6
7
  import { readPass, trashItem } from "../../../../utils/passwordstore";
7
- import { LEGACY_ENVS } from "./fromv2";
8
+ import type { LEGACY_ENVS } from "./fromv2";
8
9
 
9
10
  const getPassPath = (newConfig: Config, env: string) => {
10
11
  return `${newConfig.customerName}/${newConfig.appName}/${env}/secrets.yml`;
@@ -22,7 +23,11 @@ export const migrateSecrets = async (
22
23
  const secrets = load(yamlstring);
23
24
 
24
25
  Object.keys(newConfig.components).forEach(async (componentName) => {
25
- const environment = getEnvironment(newConfig, componentName, newEnv);
26
+ const environment = await getEnvironment(
27
+ newConfig,
28
+ componentName,
29
+ newEnv
30
+ );
26
31
  await upsertAllVariables(
27
32
  vorpal,
28
33
  pick(secrets, environment.secretEnvVarKeys),
@@ -1,4 +1,4 @@
1
- import { BuildConfig } from "@catladder/pipeline";
1
+ import type { BuildConfig } from "@catladder/pipeline";
2
2
 
3
3
  export type OldGitlabCiFile = {
4
4
  variables: {
package/src/catenv.ts CHANGED
@@ -1,7 +1,10 @@
1
1
  import catenv from "./apps/catenv/catenv";
2
- import { $ } from "zx";
3
- $.verbose = false;
4
- catenv().then(() => {
2
+
3
+ import { parseChoice } from "./config/parseChoice";
4
+
5
+ const choice = process.argv[2] ? parseChoice(process.argv[2]) : null;
6
+
7
+ catenv(choice).then(() => {
5
8
  // we have to exit manually, because we have some file watches
6
9
  process.exit();
7
10
  });
package/src/cli.ts CHANGED
@@ -1,9 +1,3 @@
1
- import updateNotifier from "update-notifier";
2
1
  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();
2
+
9
3
  cli();
@@ -1,4 +1,2 @@
1
1
  export const GRAFANA_PROXY_LOCAL_PORT = 9090;
2
2
  export const GRAFANA_PROXY_TARGET_PORT = 9090;
3
-
4
- export const GOOGLE_CLOUD_SQL_PASS_PATH = "cloud-sql-proxy-credentials";
@@ -1,19 +1,21 @@
1
+ import type { Config } from "@catladder/pipeline";
1
2
  import {
2
3
  readConfigSync,
3
4
  getAllEnvs,
4
5
  getEnvironment as _getEnvironment,
5
6
  createContext,
6
7
  getSecretVarName,
7
- Config,
8
8
  } from "@catladder/pipeline";
9
9
 
10
- import { CommandInstance } from "vorpal";
10
+ import type { CommandInstance } from "vorpal";
11
11
  import { getAllVariables, getVariableValueByRawName } from "../utils/gitlab";
12
12
 
13
13
  import { getGitRoot } from "../utils/projects";
14
14
  import { readYaml } from "../utils/files";
15
15
  import { watch } from "fs";
16
16
 
17
+ export { parseChoice } from "./parseChoice";
18
+
17
19
  let currentConfig: Config = null;
18
20
 
19
21
  // reload the config on change
@@ -59,17 +61,12 @@ export const getProjectComponents = async () => {
59
61
  return Object.keys(config.components);
60
62
  };
61
63
 
62
- export const parseChoice = (envComponent: string) => {
63
- const [env, componentName] = envComponent.split(":");
64
- return { env, componentName };
65
- };
66
-
67
64
  export const getPipelineContextByChoice = async (
68
65
  env: string,
69
66
  componentName: string
70
67
  ) => {
71
68
  const config = await getProjectConfig();
72
- return createContext(config, componentName, env);
69
+ return await createContext(config, componentName, env);
73
70
  };
74
71
  export const getAllComponentsWithAllEnvsFlat = async (): Promise<
75
72
  Array<{ env: string; componentName: string }>
@@ -0,0 +1,4 @@
1
+ export const parseChoice = (envComponent: string) => {
2
+ const [env, componentName] = envComponent.split(":").map((x) => x || null);
3
+ return { env, componentName };
4
+ };
@@ -0,0 +1,16 @@
1
+ import type { Gcloudregion } from "@catladder/pipeline";
2
+ import { exec } from "child-process-promise";
3
+
4
+ export const upsertGcloudArtifactsRegistry = async (config: {
5
+ projectId: string;
6
+ region: Gcloudregion;
7
+ }) => {
8
+ try {
9
+ await exec(
10
+ `gcloud artifacts repositories create catladder-deploy --project="${config.projectId}" --repository-format=docker --location=${config.region}`
11
+ );
12
+ } catch (e) {
13
+ // probably already exists
14
+ //
15
+ }
16
+ };