@catladder/cli 0.0.0-test7 → 0.0.0-waitfor-deploy-e64a33ba
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.
- package/.nvmrc +1 -1
- package/README.md +6 -3
- package/bin/catenv +3 -0
- package/bin/catladder +1 -1
- package/dist/apps/catenv/catenv.d.ts +5 -0
- package/dist/apps/catenv/catenv.js +143 -0
- package/dist/apps/catenv/catenv.js.map +1 -0
- package/dist/apps/cli/cli.d.ts +2 -0
- package/dist/apps/cli/cli.js +81 -0
- package/dist/apps/cli/cli.js.map +1 -0
- package/dist/apps/cli/commands/general/index.d.ts +4 -0
- package/dist/apps/cli/commands/general/index.js +216 -0
- package/dist/apps/cli/commands/general/index.js.map +1 -0
- package/dist/apps/cli/commands/general/namespaceAutoCompletion.d.ts +3 -0
- package/dist/apps/cli/commands/general/namespaceAutoCompletion.js +56 -0
- package/dist/apps/cli/commands/general/namespaceAutoCompletion.js.map +1 -0
- package/dist/apps/cli/commands/general/portForward.d.ts +3 -0
- package/dist/apps/cli/commands/general/portForward.js +97 -0
- package/dist/apps/cli/commands/general/portForward.js.map +1 -0
- package/dist/apps/cli/commands/mongodb/index.d.ts +3 -0
- package/dist/apps/cli/commands/mongodb/index.js +53 -0
- package/dist/apps/cli/commands/mongodb/index.js.map +1 -0
- package/dist/apps/cli/commands/mongodb/projectMongoDestroyMember.d.ts +3 -0
- package/dist/apps/cli/commands/mongodb/projectMongoDestroyMember.js +190 -0
- package/dist/apps/cli/commands/mongodb/projectMongoDestroyMember.js.map +1 -0
- package/dist/apps/cli/commands/mongodb/projectMongoGetShell.d.ts +3 -0
- package/dist/apps/cli/commands/mongodb/projectMongoGetShell.js +96 -0
- package/dist/apps/cli/commands/mongodb/projectMongoGetShell.js.map +1 -0
- package/dist/apps/cli/commands/mongodb/projectMongoPortForward.d.ts +3 -0
- package/dist/apps/cli/commands/mongodb/projectMongoPortForward.js +105 -0
- package/dist/apps/cli/commands/mongodb/projectMongoPortForward.js.map +1 -0
- package/dist/apps/cli/commands/mongodb/utils/index.d.ts +13 -0
- package/dist/apps/cli/commands/mongodb/utils/index.js +167 -0
- package/dist/apps/cli/commands/mongodb/utils/index.js.map +1 -0
- package/dist/apps/cli/commands/project/commandCloudSqlProxy.d.ts +3 -0
- package/dist/apps/cli/commands/project/commandCloudSqlProxy.js +137 -0
- package/dist/apps/cli/commands/project/commandCloudSqlProxy.js.map +1 -0
- package/dist/apps/cli/commands/project/commandConfigSecrets.d.ts +4 -0
- package/dist/apps/cli/commands/project/commandConfigSecrets.js +320 -0
- package/dist/apps/cli/commands/project/commandConfigSecrets.js.map +1 -0
- package/dist/apps/cli/commands/project/commandCopyDB.d.ts +3 -0
- package/dist/apps/cli/commands/project/commandCopyDB.js +102 -0
- package/dist/apps/cli/commands/project/commandCopyDB.js.map +1 -0
- package/dist/apps/cli/commands/project/commandDeletePods.d.ts +3 -0
- package/dist/apps/cli/commands/project/commandDeletePods.js +120 -0
- package/dist/apps/cli/commands/project/commandDeletePods.js.map +1 -0
- package/dist/apps/cli/commands/project/commandDeleteProject.d.ts +3 -0
- package/dist/apps/cli/commands/project/commandDeleteProject.js +97 -0
- package/dist/apps/cli/commands/project/commandDeleteProject.js.map +1 -0
- package/dist/apps/cli/commands/project/commandEnvVars.d.ts +3 -0
- package/dist/apps/cli/commands/project/commandEnvVars.js +74 -0
- package/dist/apps/cli/commands/project/commandEnvVars.js.map +1 -0
- package/dist/apps/cli/commands/project/commandGetMyTotalWorktime.d.ts +3 -0
- package/dist/apps/cli/commands/project/commandGetMyTotalWorktime.js +58 -0
- package/dist/apps/cli/commands/project/commandGetMyTotalWorktime.js.map +1 -0
- package/dist/apps/cli/commands/project/commandGetShell.d.ts +3 -0
- package/dist/apps/cli/commands/project/commandGetShell.js +92 -0
- package/dist/apps/cli/commands/project/commandGetShell.js.map +1 -0
- package/dist/apps/cli/commands/project/commandGitlabCi.d.ts +3 -0
- package/dist/apps/cli/commands/project/commandGitlabCi.js +185 -0
- package/dist/apps/cli/commands/project/commandGitlabCi.js.map +1 -0
- package/dist/apps/cli/commands/project/commandInitProject.old.d.ts +3 -0
- package/dist/apps/cli/commands/project/commandInitProject.old.js +345 -0
- package/dist/apps/cli/commands/project/commandInitProject.old.js.map +1 -0
- package/dist/apps/cli/commands/project/commandListPods.d.ts +3 -0
- package/dist/apps/cli/commands/project/commandListPods.js +78 -0
- package/dist/apps/cli/commands/project/commandListPods.js.map +1 -0
- package/dist/apps/cli/commands/project/commandMigrateHelm3.d.ts +7 -0
- package/dist/apps/cli/commands/project/commandMigrateHelm3.js +113 -0
- package/dist/apps/cli/commands/project/commandMigrateHelm3.js.map +1 -0
- package/dist/apps/cli/commands/project/commandNamespace.d.ts +3 -0
- package/dist/apps/cli/commands/project/commandNamespace.js +70 -0
- package/dist/apps/cli/commands/project/commandNamespace.js.map +1 -0
- package/dist/apps/cli/commands/project/commandOpenCostDashboard.d.ts +3 -0
- package/dist/apps/cli/commands/project/commandOpenCostDashboard.js +83 -0
- package/dist/apps/cli/commands/project/commandOpenCostDashboard.js.map +1 -0
- package/dist/apps/cli/commands/project/commandOpenDashboard.d.ts +3 -0
- package/dist/apps/cli/commands/project/commandOpenDashboard.js +85 -0
- package/dist/apps/cli/commands/project/commandOpenDashboard.js.map +1 -0
- package/dist/apps/cli/commands/project/commandOpenEnv.d.ts +3 -0
- package/dist/apps/cli/commands/project/commandOpenEnv.js +80 -0
- package/dist/apps/cli/commands/project/commandOpenEnv.js.map +1 -0
- package/dist/apps/cli/commands/project/commandOpenGit.d.ts +3 -0
- package/dist/apps/cli/commands/project/commandOpenGit.js +61 -0
- package/dist/apps/cli/commands/project/commandOpenGit.js.map +1 -0
- package/dist/apps/cli/commands/project/commandOpenGrafana.d.ts +3 -0
- package/dist/apps/cli/commands/project/commandOpenGrafana.js +83 -0
- package/dist/apps/cli/commands/project/commandOpenGrafana.js.map +1 -0
- package/dist/apps/cli/commands/project/commandOpenGrafanaPod.d.ts +3 -0
- package/dist/apps/cli/commands/project/commandOpenGrafanaPod.js +99 -0
- package/dist/apps/cli/commands/project/commandOpenGrafanaPod.js.map +1 -0
- package/dist/apps/cli/commands/project/commandOpenLogs.d.ts +3 -0
- package/dist/apps/cli/commands/project/commandOpenLogs.js +87 -0
- package/dist/apps/cli/commands/project/commandOpenLogs.js.map +1 -0
- package/dist/apps/cli/commands/project/commandPauseProject.d.ts +3 -0
- package/dist/apps/cli/commands/project/commandPauseProject.js +97 -0
- package/dist/apps/cli/commands/project/commandPauseProject.js.map +1 -0
- package/dist/apps/cli/commands/project/commandPortForward.d.ts +3 -0
- package/dist/apps/cli/commands/project/commandPortForward.js +106 -0
- package/dist/apps/cli/commands/project/commandPortForward.js.map +1 -0
- package/dist/apps/cli/commands/project/commandSetup.d.ts +3 -0
- package/dist/apps/cli/commands/project/commandSetup.js +58 -0
- package/dist/apps/cli/commands/project/commandSetup.js.map +1 -0
- package/dist/apps/cli/commands/project/commandTriggerCronjob.d.ts +3 -0
- package/dist/apps/cli/commands/project/commandTriggerCronjob.js +144 -0
- package/dist/apps/cli/commands/project/commandTriggerCronjob.js.map +1 -0
- package/dist/apps/cli/commands/project/index.d.ts +3 -0
- package/dist/apps/cli/commands/project/index.js +94 -0
- package/dist/apps/cli/commands/project/index.js.map +1 -0
- package/dist/apps/cli/commands/project/setup/index.d.ts +2 -0
- package/dist/apps/cli/commands/project/setup/index.js +103 -0
- package/dist/apps/cli/commands/project/setup/index.js.map +1 -0
- package/dist/apps/cli/commands/project/setup/setupAccessTokens.d.ts +2 -0
- package/dist/apps/cli/commands/project/setup/setupAccessTokens.js +115 -0
- package/dist/apps/cli/commands/project/setup/setupAccessTokens.js.map +1 -0
- package/dist/apps/cli/commands/project/setup/setupContext.d.ts +3 -0
- package/dist/apps/cli/commands/project/setup/setupContext.js +74 -0
- package/dist/apps/cli/commands/project/setup/setupContext.js.map +1 -0
- package/dist/apps/cli/commands/project/setup/setupKubernetes.d.ts +3 -0
- package/dist/apps/cli/commands/project/setup/setupKubernetes.js +132 -0
- package/dist/apps/cli/commands/project/setup/setupKubernetes.js.map +1 -0
- package/dist/apps/cli/commands/project/utils/autocompletions.d.ts +3 -0
- package/dist/apps/cli/commands/project/utils/autocompletions.js +96 -0
- package/dist/apps/cli/commands/project/utils/autocompletions.js.map +1 -0
- package/dist/apps/cli/commands/project/utils/ensureCluster.d.ts +1 -0
- package/dist/apps/cli/commands/project/utils/ensureCluster.js +84 -0
- package/dist/apps/cli/commands/project/utils/ensureCluster.js.map +1 -0
- package/dist/apps/cli/commands/project/utils/ensureNamespace.d.ts +2 -0
- package/dist/apps/cli/commands/project/utils/ensureNamespace.js +104 -0
- package/dist/apps/cli/commands/project/utils/ensureNamespace.js.map +1 -0
- package/dist/apps/cli/commands/project/utils/showProjectBanner.d.ts +2 -0
- package/dist/apps/cli/commands/project/utils/showProjectBanner.js +58 -0
- package/dist/apps/cli/commands/project/utils/showProjectBanner.js.map +1 -0
- package/dist/apps/cli/commands/shared/index.d.ts +3 -0
- package/dist/apps/cli/commands/shared/index.js +70 -0
- package/dist/apps/cli/commands/shared/index.js.map +1 -0
- package/dist/apps/cli/commands/theStuffThatReallyMatters/index.d.ts +3 -0
- package/dist/apps/cli/commands/theStuffThatReallyMatters/index.js +101 -0
- package/dist/apps/cli/commands/theStuffThatReallyMatters/index.js.map +1 -0
- package/dist/apps/cli/config/writeConfig.d.ts +5 -0
- package/dist/apps/cli/config/writeConfig.js +106 -0
- package/dist/apps/cli/config/writeConfig.js.map +1 -0
- package/dist/apps/cli/utils/getGoogleAuthUserNumber.d.ts +1 -0
- package/dist/apps/cli/utils/getGoogleAuthUserNumber.js +69 -0
- package/dist/apps/cli/utils/getGoogleAuthUserNumber.js.map +1 -0
- package/dist/apps/cli/verify/index.d.ts +2 -0
- package/dist/apps/cli/verify/index.js +94 -0
- package/dist/apps/cli/verify/index.js.map +1 -0
- package/dist/apps/cli/verify/migration/fromv2.d.ts +4 -0
- package/dist/apps/cli/verify/migration/fromv2.js +347 -0
- package/dist/apps/cli/verify/migration/fromv2.js.map +1 -0
- package/dist/apps/cli/verify/migration/migrateSecrets.d.ts +4 -0
- package/dist/apps/cli/verify/migration/migrateSecrets.js +88 -0
- package/dist/apps/cli/verify/migration/migrateSecrets.js.map +1 -0
- package/dist/apps/cli/verify/migration/oldGitlabCi.d.ts +18 -0
- package/dist/apps/cli/verify/migration/oldGitlabCi.js +30 -0
- package/dist/apps/cli/verify/migration/oldGitlabCi.js.map +1 -0
- package/dist/catenv.d.ts +1 -0
- package/dist/catenv.js +15 -0
- package/dist/catenv.js.map +1 -0
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +15 -0
- package/dist/cli.js.map +1 -0
- package/dist/config/constants.d.ts +3 -0
- package/dist/config/constants.js +7 -0
- package/dist/config/constants.js.map +1 -0
- package/dist/config/getProjectConfig.d.ts +24 -0
- package/dist/config/getProjectConfig.js +259 -0
- package/dist/config/getProjectConfig.js.map +1 -0
- package/dist/k8sApi/index.d.ts +8 -0
- package/dist/k8sApi/index.js +29 -0
- package/dist/k8sApi/index.js.map +1 -0
- package/dist/packageInfos.d.ts +2 -0
- package/dist/packageInfos.js +6 -0
- package/dist/packageInfos.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/dist/types/types.d.ts +18 -0
- package/dist/types/types.js +3 -0
- package/dist/types/types.js.map +1 -0
- package/dist/utils/cluster.d.ts +3 -0
- package/dist/utils/cluster.js +73 -0
- package/dist/utils/cluster.js.map +1 -0
- package/dist/utils/editAsFile.d.ts +1 -0
- package/dist/utils/editAsFile.js +85 -0
- package/dist/utils/editAsFile.js.map +1 -0
- package/dist/utils/files.d.ts +2 -0
- package/dist/utils/files.js +83 -0
- package/dist/utils/files.js.map +1 -0
- package/dist/utils/getEditor.d.ts +4 -0
- package/dist/utils/getEditor.js +70 -0
- package/dist/utils/getEditor.js.map +1 -0
- package/dist/utils/gitlab.d.ts +22 -0
- package/dist/utils/gitlab.js +278 -0
- package/dist/utils/gitlab.js.map +1 -0
- package/dist/utils/log.d.ts +1 -0
- package/dist/utils/log.js +14 -0
- package/dist/utils/log.js.map +1 -0
- package/dist/utils/passwordstore/index.d.ts +8 -0
- package/dist/utils/passwordstore/index.js +378 -0
- package/dist/utils/passwordstore/index.js.map +1 -0
- package/dist/utils/portForward.d.ts +4 -0
- package/dist/utils/portForward.js +116 -0
- package/dist/utils/portForward.js.map +1 -0
- package/dist/utils/preferences/index.d.ts +3 -0
- package/dist/utils/preferences/index.js +119 -0
- package/dist/utils/preferences/index.js.map +1 -0
- package/dist/utils/projects/index.d.ts +8 -0
- package/dist/utils/projects/index.js +153 -0
- package/dist/utils/projects/index.js.map +1 -0
- package/dist/utils/promise.d.ts +2 -0
- package/dist/utils/promise.js +62 -0
- package/dist/utils/promise.js.map +1 -0
- package/dist/utils/shell.d.ts +1 -0
- package/dist/utils/shell.js +81 -0
- package/dist/utils/shell.js.map +1 -0
- package/package.json +16 -21
- package/src/apps/catenv/catenv.ts +55 -27
- package/src/apps/{shell/shell.ts → cli/cli.ts} +10 -2
- package/src/apps/{shell → cli}/commands/general/index.ts +7 -46
- package/src/apps/{shell → cli}/commands/general/namespaceAutoCompletion.ts +0 -0
- package/src/apps/{shell → cli}/commands/general/portForward.ts +3 -2
- package/src/apps/{shell → cli}/commands/mongodb/index.ts +1 -1
- package/src/apps/{shell → cli}/commands/mongodb/projectMongoDestroyMember.ts +18 -18
- package/src/apps/{shell → cli}/commands/mongodb/projectMongoGetShell.ts +12 -10
- package/src/apps/{shell → cli}/commands/mongodb/projectMongoPortForward.ts +13 -8
- package/src/apps/{shell → cli}/commands/mongodb/utils/index.ts +9 -8
- package/src/apps/cli/commands/project/commandCloudSqlProxy.ts +88 -0
- package/src/apps/cli/commands/project/commandConfigSecrets.ts +220 -0
- package/src/apps/{shell → cli}/commands/project/commandCopyDB.ts +24 -26
- package/src/apps/{shell → cli}/commands/project/commandDeletePods.ts +10 -10
- package/src/apps/{shell → cli}/commands/project/commandDeleteProject.ts +7 -8
- package/src/apps/cli/commands/project/commandEnvVars.ts +15 -0
- package/src/apps/{shell → cli}/commands/project/commandGetMyTotalWorktime.ts +2 -2
- package/src/apps/{shell → cli}/commands/project/commandGetShell.ts +10 -10
- package/src/apps/{shell → cli}/commands/project/commandGitlabCi.ts +1 -1
- package/src/apps/{shell/commands/project/commandInitProject.ts → cli/commands/project/commandInitProject.old.ts} +14 -6
- package/src/apps/cli/commands/project/commandListPods.ts +18 -0
- package/src/apps/{shell → cli}/commands/project/commandMigrateHelm3.ts +16 -7
- package/src/apps/cli/commands/project/commandNamespace.ts +14 -0
- package/src/apps/{shell → cli}/commands/project/commandOpenCostDashboard.ts +10 -7
- package/src/apps/cli/commands/project/commandOpenDashboard.ts +48 -0
- package/src/apps/cli/commands/project/commandOpenEnv.ts +22 -0
- package/src/apps/{shell → cli}/commands/project/commandOpenGit.ts +3 -3
- package/src/apps/{shell → cli}/commands/project/commandOpenGrafana.ts +7 -7
- package/src/apps/{shell → cli}/commands/project/commandOpenGrafanaPod.ts +9 -10
- package/src/apps/cli/commands/project/commandOpenLogs.ts +52 -0
- package/src/apps/{shell → cli}/commands/project/commandPauseProject.ts +9 -7
- package/src/apps/{shell → cli}/commands/project/commandPortForward.ts +8 -8
- package/src/apps/cli/commands/project/commandSetup.ts +12 -0
- package/src/apps/{shell → cli}/commands/project/commandTriggerCronjob.ts +10 -10
- package/src/apps/{shell → cli}/commands/project/index.ts +6 -7
- package/src/apps/cli/commands/project/setup/index.ts +42 -0
- package/src/apps/cli/commands/project/setup/setupAccessTokens.ts +72 -0
- package/src/apps/cli/commands/project/setup/setupContext.ts +37 -0
- package/src/apps/cli/commands/project/setup/setupKubernetes.ts +112 -0
- package/src/apps/cli/commands/project/utils/autocompletions.ts +26 -0
- package/src/apps/cli/commands/project/utils/ensureCluster.ts +42 -0
- package/src/apps/cli/commands/project/utils/ensureNamespace.ts +56 -0
- package/src/apps/cli/commands/project/utils/showProjectBanner.ts +11 -0
- package/src/apps/cli/commands/shared/index.ts +36 -0
- package/src/apps/{shell → cli}/commands/theStuffThatReallyMatters/index.ts +7 -26
- package/src/apps/cli/config/writeConfig.ts +71 -0
- package/src/apps/{shell → cli}/utils/getGoogleAuthUserNumber.ts +0 -0
- package/src/apps/cli/verify/index.ts +30 -0
- package/src/apps/cli/verify/migration/fromv2.ts +264 -0
- package/src/apps/cli/verify/migration/migrateSecrets.ts +37 -0
- package/src/apps/cli/verify/migration/oldGitlabCi.ts +48 -0
- package/src/catenv.ts +11 -0
- package/src/cli.ts +9 -0
- package/src/config/constants.ts +0 -1
- package/src/config/getProjectConfig.ts +160 -0
- package/src/k8sApi/index.ts +22 -6
- package/src/types/types.ts +0 -2
- package/src/utils/cluster.ts +6 -15
- package/src/utils/editAsFile.ts +31 -0
- package/src/utils/files.ts +6 -2
- package/src/utils/gitlab.ts +144 -34
- package/src/utils/passwordstore/index.ts +19 -21
- package/src/utils/preferences/index.ts +6 -3
- package/src/utils/projects/index.ts +18 -137
- package/tsconfig.json +3 -7
- package/bin/catenv.sh +0 -1
- package/src/apps/shell/commands/project/commandCloudSqlProxy.ts +0 -65
- package/src/apps/shell/commands/project/commandConfigSecrets.ts +0 -245
- package/src/apps/shell/commands/project/commandEnvVars.ts +0 -17
- package/src/apps/shell/commands/project/commandInitGitlab.ts +0 -157
- package/src/apps/shell/commands/project/commandListPods.ts +0 -21
- package/src/apps/shell/commands/project/commandNamespace.ts +0 -12
- package/src/apps/shell/commands/project/commandOpenDashboard.ts +0 -27
- package/src/apps/shell/commands/project/commandOpenEnv.ts +0 -18
- package/src/apps/shell/commands/project/commandOpenLogs.ts +0 -23
- package/src/apps/shell/commands/project/commandVariables.ts +0 -13
- package/src/apps/shell/commands/project/utils/autocompletions.ts +0 -7
- package/src/apps/shell/commands/project/utils/ensureCluster.ts +0 -31
- package/src/apps/shell/commands/project/utils/ensureNamespace.ts +0 -32
- package/src/apps/shell/commands/project/utils/monorepo.ts +0 -45
- package/src/apps/shell/commands/shared/index.ts +0 -31
- package/src/config/clusters.ts +0 -45
- package/src/index.ts +0 -17
- package/src/types/git-repo-name.d.ts +0 -1
- package/src/types/yawn-yaml.d.ts +0 -1
- package/src/utils/dashboardToken.ts +0 -20
- package/src/utils/formatEnvVars.ts +0 -7
|
@@ -0,0 +1,71 @@
|
|
|
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 { getGitRoot } from "../../../utils/projects";
|
|
8
|
+
|
|
9
|
+
export const writeConfig = async (
|
|
10
|
+
vorpal: CommandInstance,
|
|
11
|
+
config: Config,
|
|
12
|
+
options?: {
|
|
13
|
+
endComment?: string;
|
|
14
|
+
}
|
|
15
|
+
) => {
|
|
16
|
+
const gitRoot = await getGitRoot();
|
|
17
|
+
const TS = "typescript (recommended)";
|
|
18
|
+
const { configType } = await vorpal.prompt({
|
|
19
|
+
type: "list",
|
|
20
|
+
name: "configType",
|
|
21
|
+
choices: [TS, "yaml"],
|
|
22
|
+
message: "In which format do you want the config? 🤔",
|
|
23
|
+
});
|
|
24
|
+
vorpal.log("");
|
|
25
|
+
if (configType === TS) {
|
|
26
|
+
const file = gitRoot + "/catladder.ts";
|
|
27
|
+
const content = format(
|
|
28
|
+
`
|
|
29
|
+
import type { Config } from "@catladder/pipeline";
|
|
30
|
+
|
|
31
|
+
const config: Config = ${JSON.stringify(config)};
|
|
32
|
+
|
|
33
|
+
export default config;
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
${options?.endComment ? `/*${options.endComment}*/` : ""}
|
|
37
|
+
|
|
38
|
+
`,
|
|
39
|
+
{
|
|
40
|
+
parser: "babel",
|
|
41
|
+
}
|
|
42
|
+
);
|
|
43
|
+
|
|
44
|
+
await writeFile(file, content, {
|
|
45
|
+
encoding: "utf-8",
|
|
46
|
+
});
|
|
47
|
+
vorpal.log("adding type @catladder/pipeline....");
|
|
48
|
+
await spawn("yarn add --non-interactive @catladder/pipeline -DW", {
|
|
49
|
+
shell: true,
|
|
50
|
+
});
|
|
51
|
+
await exec("git add " + file);
|
|
52
|
+
} else {
|
|
53
|
+
const file = gitRoot + "/catladder.yml";
|
|
54
|
+
const content = dump(config);
|
|
55
|
+
|
|
56
|
+
await writeFile(
|
|
57
|
+
file,
|
|
58
|
+
content +
|
|
59
|
+
"\n\n" +
|
|
60
|
+
(options.endComment
|
|
61
|
+
? "# " + options.endComment.split("\n").join("\n# ")
|
|
62
|
+
: ""),
|
|
63
|
+
{
|
|
64
|
+
encoding: "utf-8",
|
|
65
|
+
}
|
|
66
|
+
);
|
|
67
|
+
await exec("git add " + file);
|
|
68
|
+
}
|
|
69
|
+
vorpal.log("done!");
|
|
70
|
+
vorpal.log("");
|
|
71
|
+
};
|
|
File without changes
|
|
@@ -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,11 @@
|
|
|
1
|
+
import catenv from "./apps/catenv/catenv";
|
|
2
|
+
import { $, argv } from "zx";
|
|
3
|
+
import { parseChoice } from "./config/getProjectConfig";
|
|
4
|
+
|
|
5
|
+
const choice = argv._[0] ? parseChoice(argv._[0]) : null;
|
|
6
|
+
|
|
7
|
+
$.verbose = false;
|
|
8
|
+
catenv(choice).then(() => {
|
|
9
|
+
// we have to exit manually, because we have some file watches
|
|
10
|
+
process.exit();
|
|
11
|
+
});
|
package/src/cli.ts
ADDED
package/src/config/constants.ts
CHANGED
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
import {
|
|
2
|
+
readConfigSync,
|
|
3
|
+
getAllEnvs,
|
|
4
|
+
getEnvironment as _getEnvironment,
|
|
5
|
+
createContext,
|
|
6
|
+
getSecretVarName,
|
|
7
|
+
Config,
|
|
8
|
+
} from "@catladder/pipeline";
|
|
9
|
+
|
|
10
|
+
import { CommandInstance } from "vorpal";
|
|
11
|
+
import { getAllVariables, getVariableValueByRawName } from "../utils/gitlab";
|
|
12
|
+
|
|
13
|
+
import { getGitRoot } from "../utils/projects";
|
|
14
|
+
import { readYaml } from "../utils/files";
|
|
15
|
+
import { watch } from "fs";
|
|
16
|
+
|
|
17
|
+
let currentConfig: Config = null;
|
|
18
|
+
|
|
19
|
+
// reload the config on change
|
|
20
|
+
const reloadConfigAndObserve = async () => {
|
|
21
|
+
const gitRoot = await getGitRoot();
|
|
22
|
+
const result = readConfigSync(gitRoot);
|
|
23
|
+
if (!result) {
|
|
24
|
+
// can't do anything, there is no config
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
const { config, path } = result;
|
|
28
|
+
const watcher = watch(path, () => {
|
|
29
|
+
watcher.close();
|
|
30
|
+
reloadConfigAndObserve();
|
|
31
|
+
});
|
|
32
|
+
currentConfig = config;
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
export const getProjectConfig = async () => {
|
|
36
|
+
if (!currentConfig) {
|
|
37
|
+
// initially
|
|
38
|
+
await reloadConfigAndObserve();
|
|
39
|
+
}
|
|
40
|
+
return currentConfig;
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
export const getGitlabCiFilePath = async () => {
|
|
44
|
+
const gitRoot = await getGitRoot();
|
|
45
|
+
return gitRoot + "/.gitlab-ci.yml";
|
|
46
|
+
};
|
|
47
|
+
export const getGitlabCi = async <T = Record<string, any>>() => {
|
|
48
|
+
try {
|
|
49
|
+
return readYaml(await getGitlabCiFilePath()) as Promise<T>;
|
|
50
|
+
} catch (e) {
|
|
51
|
+
// ignore
|
|
52
|
+
return null;
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
export const getProjectComponents = async () => {
|
|
57
|
+
const config = await getProjectConfig();
|
|
58
|
+
if (!config) return [];
|
|
59
|
+
return Object.keys(config.components);
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
export const parseChoice = (envComponent: string) => {
|
|
63
|
+
const [env, componentName] = envComponent.split(":").map((x) => x || null);
|
|
64
|
+
return { env, componentName };
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
export const getPipelineContextByChoice = async (
|
|
68
|
+
env: string,
|
|
69
|
+
componentName: string
|
|
70
|
+
) => {
|
|
71
|
+
const config = await getProjectConfig();
|
|
72
|
+
return createContext(config, componentName, env);
|
|
73
|
+
};
|
|
74
|
+
export const getAllComponentsWithAllEnvsFlat = async (): Promise<
|
|
75
|
+
Array<{ env: string; componentName: string }>
|
|
76
|
+
> => {
|
|
77
|
+
const config = await getProjectConfig();
|
|
78
|
+
if (!config) {
|
|
79
|
+
return [];
|
|
80
|
+
}
|
|
81
|
+
return Object.keys(config.components).flatMap((componentName) =>
|
|
82
|
+
getAllEnvs(config, componentName).map((env) => ({ env, componentName }))
|
|
83
|
+
);
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
export const getAllComponentsWithAllEnvsHierarchical = async (): Promise<{
|
|
87
|
+
[componentName: string]: string[];
|
|
88
|
+
}> => {
|
|
89
|
+
const config = await getProjectConfig();
|
|
90
|
+
if (!config) {
|
|
91
|
+
return {};
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
return Object.fromEntries(
|
|
95
|
+
Object.keys(config.components).map((componentName) => [
|
|
96
|
+
componentName,
|
|
97
|
+
getAllEnvs(config, componentName),
|
|
98
|
+
])
|
|
99
|
+
);
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
export const getAllPipelineContexts = async () => {
|
|
103
|
+
return Promise.all(
|
|
104
|
+
(await getAllComponentsWithAllEnvsFlat())
|
|
105
|
+
.filter((c) => c.env !== "local")
|
|
106
|
+
.map(({ env, componentName }) =>
|
|
107
|
+
getPipelineContextByChoice(env, componentName)
|
|
108
|
+
)
|
|
109
|
+
);
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
export const getEnvironment = async (env: string, componentName: string) => {
|
|
113
|
+
const config = await getProjectConfig();
|
|
114
|
+
|
|
115
|
+
return _getEnvironment(config, componentName, env);
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
export const getGitlabVar = async (
|
|
119
|
+
vorpal: CommandInstance,
|
|
120
|
+
env: string,
|
|
121
|
+
componentName: string,
|
|
122
|
+
variableName: string
|
|
123
|
+
) => {
|
|
124
|
+
const rawVariableName = getSecretVarName(env, componentName, variableName);
|
|
125
|
+
return await getVariableValueByRawName(vorpal, rawVariableName);
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
const resolveSecrets = async (
|
|
129
|
+
vorpal: CommandInstance,
|
|
130
|
+
allEnvVars: Record<string, string>
|
|
131
|
+
) => {
|
|
132
|
+
const allVariablesInGitlab = await getAllVariables(vorpal);
|
|
133
|
+
|
|
134
|
+
return Object.fromEntries(
|
|
135
|
+
Object.entries(allEnvVars).map(([key, value]) => {
|
|
136
|
+
const containsSecret = String(value)?.includes?.("$CL_");
|
|
137
|
+
if (containsSecret) {
|
|
138
|
+
for (const variable of allVariablesInGitlab) {
|
|
139
|
+
value = value.replace(
|
|
140
|
+
new RegExp("\\$" + variable.key, "g"),
|
|
141
|
+
variable.value
|
|
142
|
+
);
|
|
143
|
+
}
|
|
144
|
+
return [key, value];
|
|
145
|
+
}
|
|
146
|
+
return [key, value];
|
|
147
|
+
})
|
|
148
|
+
);
|
|
149
|
+
};
|
|
150
|
+
|
|
151
|
+
export const getEnvVars = async (
|
|
152
|
+
vorpal: CommandInstance,
|
|
153
|
+
env: string,
|
|
154
|
+
componentName: string
|
|
155
|
+
) => {
|
|
156
|
+
const envionment = await getEnvironment(env, componentName);
|
|
157
|
+
// in the pipeline the secrets alreadyy exists and bash will expand them
|
|
158
|
+
// but here we need to manually load them
|
|
159
|
+
return resolveSecrets(vorpal, envionment.envVars);
|
|
160
|
+
};
|
package/src/k8sApi/index.ts
CHANGED
|
@@ -5,13 +5,29 @@ import {
|
|
|
5
5
|
BatchV1beta1Api,
|
|
6
6
|
} from "@kubernetes/client-node";
|
|
7
7
|
|
|
8
|
-
const
|
|
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.
|
|
20
|
+
return kc.makeApiClient(CoreV1Api);
|
|
21
|
+
};
|
|
11
22
|
|
|
12
|
-
const
|
|
23
|
+
export const getk8sApiBatch = () => {
|
|
24
|
+
const kc = getKubeConfig();
|
|
13
25
|
|
|
14
|
-
|
|
15
|
-
|
|
26
|
+
return kc.makeApiClient(BatchV1Api);
|
|
27
|
+
};
|
|
16
28
|
|
|
17
|
-
export
|
|
29
|
+
export const getk8sApiBatchBeta = () => {
|
|
30
|
+
const kc = getKubeConfig();
|
|
31
|
+
|
|
32
|
+
return kc.makeApiClient(BatchV1beta1Api);
|
|
33
|
+
};
|