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