@catladder/cli 0.0.0-main-3b6d4049 → 0.0.0-main-5f142cf2
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/dist/apps/catenv/catenv.js +15 -12
- package/dist/apps/catenv/catenv.js.map +1 -1
- package/dist/apps/shell/commands/mongodb/projectMongoDestroyMember.js +6 -6
- package/dist/apps/shell/commands/mongodb/projectMongoDestroyMember.js.map +1 -1
- package/dist/apps/shell/commands/mongodb/projectMongoGetShell.js +6 -6
- package/dist/apps/shell/commands/mongodb/projectMongoGetShell.js.map +1 -1
- package/dist/apps/shell/commands/mongodb/projectMongoPortForward.js +5 -5
- package/dist/apps/shell/commands/mongodb/projectMongoPortForward.js.map +1 -1
- package/dist/apps/shell/commands/mongodb/utils/index.d.ts +3 -4
- package/dist/apps/shell/commands/mongodb/utils/index.js +6 -6
- package/dist/apps/shell/commands/mongodb/utils/index.js.map +1 -1
- package/dist/apps/shell/commands/project/commandCloudSqlProxy.js +10 -7
- package/dist/apps/shell/commands/project/commandCloudSqlProxy.js.map +1 -1
- package/dist/apps/shell/commands/project/commandConfigSecrets.js +46 -176
- package/dist/apps/shell/commands/project/commandConfigSecrets.js.map +1 -1
- package/dist/apps/shell/commands/project/commandCopyDB.js +1 -1
- package/dist/apps/shell/commands/project/commandCopyDB.js.map +1 -1
- package/dist/apps/shell/commands/project/commandDeletePods.js +5 -5
- package/dist/apps/shell/commands/project/commandDeletePods.js.map +1 -1
- package/dist/apps/shell/commands/project/commandDeleteProject.js +3 -3
- package/dist/apps/shell/commands/project/commandDeleteProject.js.map +1 -1
- package/dist/apps/shell/commands/project/commandGetShell.js +6 -6
- package/dist/apps/shell/commands/project/commandGetShell.js.map +1 -1
- package/dist/apps/shell/commands/project/commandInitGitlab.js +64 -38
- package/dist/apps/shell/commands/project/commandInitGitlab.js.map +1 -1
- package/dist/apps/shell/commands/project/commandInitProject.js +138 -129
- package/dist/apps/shell/commands/project/commandInitProject.js.map +1 -1
- package/dist/apps/shell/commands/project/commandListPods.js +5 -5
- package/dist/apps/shell/commands/project/commandListPods.js.map +1 -1
- package/dist/apps/shell/commands/project/commandMigrateHelm3.js +1 -1
- package/dist/apps/shell/commands/project/commandMigrateHelm3.js.map +1 -1
- package/dist/apps/shell/commands/project/commandNamespace.js +3 -3
- package/dist/apps/shell/commands/project/commandNamespace.js.map +1 -1
- package/dist/apps/shell/commands/project/commandOpenCostDashboard.js +4 -4
- package/dist/apps/shell/commands/project/commandOpenCostDashboard.js.map +1 -1
- package/dist/apps/shell/commands/project/commandOpenDashboard.js +11 -5
- package/dist/apps/shell/commands/project/commandOpenDashboard.js.map +1 -1
- package/dist/apps/shell/commands/project/commandOpenEnv.js +1 -1
- package/dist/apps/shell/commands/project/commandOpenEnv.js.map +1 -1
- package/dist/apps/shell/commands/project/commandOpenGrafana.js +4 -4
- package/dist/apps/shell/commands/project/commandOpenGrafana.js.map +1 -1
- package/dist/apps/shell/commands/project/commandOpenGrafanaPod.js +5 -5
- package/dist/apps/shell/commands/project/commandOpenGrafanaPod.js.map +1 -1
- package/dist/apps/shell/commands/project/commandOpenLogs.js +4 -4
- package/dist/apps/shell/commands/project/commandOpenLogs.js.map +1 -1
- package/dist/apps/shell/commands/project/commandPauseProject.js +3 -3
- package/dist/apps/shell/commands/project/commandPauseProject.js.map +1 -1
- package/dist/apps/shell/commands/project/commandPortForward.js +5 -5
- package/dist/apps/shell/commands/project/commandPortForward.js.map +1 -1
- package/dist/apps/shell/commands/project/commandTriggerCronjob.js +4 -4
- package/dist/apps/shell/commands/project/commandTriggerCronjob.js.map +1 -1
- package/dist/apps/shell/commands/project/index.js +0 -2
- package/dist/apps/shell/commands/project/index.js.map +1 -1
- package/dist/apps/shell/commands/project/utils/ensureCluster.d.ts +1 -1
- package/dist/apps/shell/commands/project/utils/ensureCluster.js +12 -10
- package/dist/apps/shell/commands/project/utils/ensureCluster.js.map +1 -1
- package/dist/apps/shell/commands/project/utils/ensureNamespace.d.ts +1 -2
- package/dist/apps/shell/commands/project/utils/ensureNamespace.js +2 -2
- package/dist/apps/shell/commands/project/utils/ensureNamespace.js.map +1 -1
- package/dist/config/getProjectConfig.d.ts +7 -4
- package/dist/config/getProjectConfig.js +35 -11
- package/dist/config/getProjectConfig.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/types/types.d.ts +0 -1
- package/dist/utils/cluster.d.ts +7 -0
- package/dist/utils/cluster.js +15 -3
- package/dist/utils/cluster.js.map +1 -1
- package/dist/utils/editAsFile.d.ts +1 -0
- package/dist/utils/editAsFile.js +22 -0
- package/dist/utils/editAsFile.js.map +1 -0
- package/dist/utils/gitlab.d.ts +2 -1
- package/dist/utils/gitlab.js +29 -3
- package/dist/utils/gitlab.js.map +1 -1
- package/dist/utils/projects/index.d.ts +4 -15
- package/dist/utils/projects/index.js +10 -78
- package/dist/utils/projects/index.js.map +1 -1
- package/package.json +1 -1
- package/src/apps/catenv/catenv.ts +36 -26
- package/src/apps/shell/commands/mongodb/projectMongoDestroyMember.ts +6 -6
- package/src/apps/shell/commands/mongodb/projectMongoGetShell.ts +9 -7
- package/src/apps/shell/commands/mongodb/projectMongoPortForward.ts +10 -5
- package/src/apps/shell/commands/mongodb/utils/index.ts +9 -8
- package/src/apps/shell/commands/project/commandCloudSqlProxy.ts +14 -7
- package/src/apps/shell/commands/project/commandConfigSecrets.ts +37 -172
- package/src/apps/shell/commands/project/commandCopyDB.ts +2 -1
- package/src/apps/shell/commands/project/commandDeletePods.ts +5 -6
- package/src/apps/shell/commands/project/commandDeleteProject.ts +4 -5
- package/src/apps/shell/commands/project/commandGetShell.ts +7 -7
- package/src/apps/shell/commands/project/commandInitGitlab.ts +97 -51
- package/src/apps/shell/commands/project/commandInitProject.ts +8 -0
- package/src/apps/shell/commands/project/commandListPods.ts +5 -6
- package/src/apps/shell/commands/project/commandMigrateHelm3.ts +1 -1
- package/src/apps/shell/commands/project/commandNamespace.ts +6 -4
- package/src/apps/shell/commands/project/commandOpenCostDashboard.ts +7 -4
- package/src/apps/shell/commands/project/commandOpenDashboard.ts +18 -6
- package/src/apps/shell/commands/project/commandOpenEnv.ts +1 -1
- package/src/apps/shell/commands/project/commandOpenGrafana.ts +4 -4
- package/src/apps/shell/commands/project/commandOpenGrafanaPod.ts +5 -5
- package/src/apps/shell/commands/project/commandOpenLogs.ts +4 -4
- package/src/apps/shell/commands/project/commandPauseProject.ts +6 -4
- package/src/apps/shell/commands/project/commandPortForward.ts +5 -5
- package/src/apps/shell/commands/project/commandTriggerCronjob.ts +4 -4
- package/src/apps/shell/commands/project/index.ts +1 -2
- package/src/apps/shell/commands/project/utils/ensureCluster.ts +12 -10
- package/src/apps/shell/commands/project/utils/ensureNamespace.ts +2 -3
- package/src/config/getProjectConfig.ts +40 -11
- package/src/types/types.ts +0 -2
- package/src/utils/cluster.ts +15 -2
- package/src/utils/editAsFile.ts +21 -0
- package/src/utils/gitlab.ts +56 -4
- package/src/utils/projects/index.ts +10 -93
- package/dist/apps/shell/commands/project/commandVariables.d.ts +0 -3
- package/dist/apps/shell/commands/project/commandVariables.js +0 -16
- package/dist/apps/shell/commands/project/commandVariables.js.map +0 -1
- package/dist/apps/shell/commands/project/utils/monorepo.d.ts +0 -10
- package/dist/apps/shell/commands/project/utils/monorepo.js +0 -25
- package/dist/apps/shell/commands/project/utils/monorepo.js.map +0 -1
- package/src/apps/shell/commands/project/commandVariables.ts +0 -13
- package/src/apps/shell/commands/project/utils/monorepo.ts +0 -23
|
@@ -1,22 +1,34 @@
|
|
|
1
1
|
import Vorpal from "vorpal";
|
|
2
|
+
import { getPipelineContextByChoice } from "../../../../config/getProjectConfig";
|
|
2
3
|
import { getCurrentConnectedClusterName } from "../../../../utils/cluster";
|
|
3
|
-
import { getProjectNamespace } from "../../../../utils/projects";
|
|
4
4
|
import { getGoogleAuthUserNumber } from "../../utils/getGoogleAuthUserNumber";
|
|
5
5
|
import { openGoogleCloudKubernetesDashboard } from "../shared";
|
|
6
6
|
import { envAutocompletion } from "./utils/autocompletions";
|
|
7
7
|
import ensureCluster from "./utils/ensureCluster";
|
|
8
|
-
|
|
9
8
|
export default (vorpal: Vorpal) =>
|
|
10
9
|
vorpal
|
|
11
10
|
.command(
|
|
12
|
-
"project-open-dashboard <
|
|
11
|
+
"project-open-dashboard <envComponent>",
|
|
13
12
|
"open kubernetes dashboard on google"
|
|
14
13
|
)
|
|
15
14
|
.autocomplete(envAutocompletion)
|
|
16
|
-
.action(async function ({
|
|
17
|
-
|
|
15
|
+
.action(async function ({ envComponent }) {
|
|
16
|
+
const { componentConfig, environment } =
|
|
17
|
+
getPipelineContextByChoice(envComponent);
|
|
18
|
+
|
|
19
|
+
if (
|
|
20
|
+
!componentConfig.deploy ||
|
|
21
|
+
componentConfig.deploy.type !== "kubernetes"
|
|
22
|
+
) {
|
|
23
|
+
throw new Error(
|
|
24
|
+
"only kubernetes deployments are supported at the moment"
|
|
25
|
+
);
|
|
26
|
+
}
|
|
27
|
+
// currently only supports kubernetes
|
|
28
|
+
const namespace = environment.envVars.KUBE_NAMESPACE;
|
|
29
|
+
await ensureCluster.call(this, envComponent); // TODO: implement
|
|
18
30
|
const clustername = await getCurrentConnectedClusterName();
|
|
19
|
-
|
|
31
|
+
|
|
20
32
|
const authGoogleNumber = await getGoogleAuthUserNumber.call(this, vorpal);
|
|
21
33
|
|
|
22
34
|
openGoogleCloudKubernetesDashboard(
|
|
@@ -10,7 +10,7 @@ export default (vorpal: Vorpal) =>
|
|
|
10
10
|
.command("project-open-env <envComponent>", "open the live environment")
|
|
11
11
|
.autocomplete(envAutocompletion)
|
|
12
12
|
.action(async function ({ envComponent }) {
|
|
13
|
-
await ensureCluster.call(this);
|
|
13
|
+
await ensureCluster.call(this, envComponent);
|
|
14
14
|
const environment = getEnvironmentByChoice(envComponent);
|
|
15
15
|
const url = environment.url;
|
|
16
16
|
|
|
@@ -13,13 +13,13 @@ import ensureCluster from "./utils/ensureCluster";
|
|
|
13
13
|
export default (vorpal: Vorpal) =>
|
|
14
14
|
vorpal
|
|
15
15
|
.command(
|
|
16
|
-
"project-open-grafana <
|
|
16
|
+
"project-open-grafana <envComponent>",
|
|
17
17
|
"open Grafana dashboard for your namespace"
|
|
18
18
|
)
|
|
19
19
|
.autocomplete(envAutocompletion)
|
|
20
|
-
.action(async function ({
|
|
21
|
-
await ensureCluster.call(this);
|
|
22
|
-
const namespace = await getProjectNamespace(
|
|
20
|
+
.action(async function ({ envComponent }) {
|
|
21
|
+
await ensureCluster.call(this, envComponent);
|
|
22
|
+
const namespace = await getProjectNamespace(envComponent);
|
|
23
23
|
const url = `http://localhost:${GRAFANA_PROXY_LOCAL_PORT}/grafana/d/at-cost-analysis-namespace2/namespace-utilization-metrics?var-namespace=${namespace}`;
|
|
24
24
|
await startPortForward(
|
|
25
25
|
"deployment/kubecost-cost-analyzer",
|
|
@@ -17,13 +17,13 @@ import ensureCluster from "./utils/ensureCluster";
|
|
|
17
17
|
export default (vorpal: Vorpal) =>
|
|
18
18
|
vorpal
|
|
19
19
|
.command(
|
|
20
|
-
"project-open-grafana-pod <
|
|
20
|
+
"project-open-grafana-pod <envComponent>",
|
|
21
21
|
"open Grafana dashboard for a specific pod"
|
|
22
22
|
)
|
|
23
23
|
.autocomplete(envAutocompletion)
|
|
24
|
-
.action(async function ({
|
|
25
|
-
await ensureCluster.call(this);
|
|
26
|
-
const podNames = await getProjectPodNames(
|
|
24
|
+
.action(async function ({ envComponent }) {
|
|
25
|
+
await ensureCluster.call(this, envComponent);
|
|
26
|
+
const podNames = await getProjectPodNames(envComponent);
|
|
27
27
|
if (podNames.length === 0) {
|
|
28
28
|
logError(this, "sorry, no pods found");
|
|
29
29
|
return;
|
|
@@ -34,7 +34,7 @@ export default (vorpal: Vorpal) =>
|
|
|
34
34
|
choices: podNames,
|
|
35
35
|
message: "Which pod? 🤔",
|
|
36
36
|
});
|
|
37
|
-
const namespace = await getProjectNamespace(
|
|
37
|
+
const namespace = await getProjectNamespace(envComponent);
|
|
38
38
|
const url = `http://localhost:${GRAFANA_PROXY_LOCAL_PORT}/grafana/d/at-cost-analysis-pod/pod-cost-and-utilization-metrics?var-namespace=${namespace}&var-pod=${podName}`;
|
|
39
39
|
await startPortForward(
|
|
40
40
|
"deployment/kubecost-cost-analyzer",
|
|
@@ -9,14 +9,14 @@ import ensureCluster from "./utils/ensureCluster";
|
|
|
9
9
|
export default (vorpal: Vorpal) =>
|
|
10
10
|
vorpal
|
|
11
11
|
.command(
|
|
12
|
-
"project-open-logs <
|
|
12
|
+
"project-open-logs <envComponent>",
|
|
13
13
|
"open google cloud logs (stackdriver logs)"
|
|
14
14
|
)
|
|
15
15
|
.autocomplete(envAutocompletion)
|
|
16
|
-
.action(async function ({
|
|
17
|
-
await ensureCluster.call(this);
|
|
16
|
+
.action(async function ({ envComponent }) {
|
|
17
|
+
await ensureCluster.call(this, envComponent);
|
|
18
18
|
const clustername = await getCurrentConnectedClusterName();
|
|
19
|
-
const namespace = await getProjectNamespace(
|
|
19
|
+
const namespace = await getProjectNamespace(envComponent);
|
|
20
20
|
const authGoogleNumber = await getGoogleAuthUserNumber.call(this, vorpal);
|
|
21
21
|
|
|
22
22
|
await openGoogleCloudLogs(authGoogleNumber, clustername, namespace);
|
|
@@ -1,15 +1,17 @@
|
|
|
1
1
|
import Vorpal from "vorpal";
|
|
2
2
|
import { exec } from "child-process-promise";
|
|
3
|
-
import { Env } from "../../../../types/types";
|
|
4
3
|
import { getProjectNamespace } from "../../../../utils/projects";
|
|
5
4
|
import { envAutocompletion } from "./utils/autocompletions";
|
|
6
5
|
|
|
7
6
|
export default (vorpal: Vorpal) =>
|
|
8
7
|
vorpal
|
|
9
|
-
.command(
|
|
8
|
+
.command(
|
|
9
|
+
"project-pause <envComponent>",
|
|
10
|
+
"halts all running pods (scales to 0)"
|
|
11
|
+
)
|
|
10
12
|
.autocomplete(envAutocompletion)
|
|
11
|
-
.action(async function ({
|
|
12
|
-
const namespace = await getProjectNamespace(
|
|
13
|
+
.action(async function ({ envComponent }) {
|
|
14
|
+
const namespace = await getProjectNamespace(envComponent);
|
|
13
15
|
const { shouldContinue } = await this.prompt({
|
|
14
16
|
type: "confirm",
|
|
15
17
|
name: "shouldContinue",
|
|
@@ -10,12 +10,12 @@ import ensureCluster from "./utils/ensureCluster";
|
|
|
10
10
|
|
|
11
11
|
export default (vorpal: Vorpal) =>
|
|
12
12
|
vorpal
|
|
13
|
-
.command("project-port-forward <
|
|
13
|
+
.command("project-port-forward <envComponent>", "start port-forwarding")
|
|
14
14
|
.autocomplete(envAutocompletion)
|
|
15
|
-
.action(async function ({
|
|
16
|
-
await ensureCluster.call(this);
|
|
17
|
-
const namespace = await getProjectNamespace(
|
|
18
|
-
const podNames = await getProjectPodNames(
|
|
15
|
+
.action(async function ({ envComponent }) {
|
|
16
|
+
await ensureCluster.call(this, envComponent);
|
|
17
|
+
const namespace = await getProjectNamespace(envComponent);
|
|
18
|
+
const podNames = await getProjectPodNames(envComponent);
|
|
19
19
|
if (podNames.length === 0) {
|
|
20
20
|
logError(this, "sorry, no pods found");
|
|
21
21
|
return;
|
|
@@ -51,11 +51,11 @@ export default (vorpal: Vorpal) => {
|
|
|
51
51
|
await triggerCronjob.call(this, namespace);
|
|
52
52
|
});
|
|
53
53
|
vorpal
|
|
54
|
-
.command("project-trigger-cronjob <
|
|
54
|
+
.command("project-trigger-cronjob <envComponent>", "trigger cronjob")
|
|
55
55
|
.autocomplete(envAutocompletion)
|
|
56
|
-
.action(async function ({
|
|
57
|
-
await ensureCluster.call(this);
|
|
58
|
-
const namespace = await getProjectNamespace(
|
|
56
|
+
.action(async function ({ envComponent }) {
|
|
57
|
+
await ensureCluster.call(this, envComponent);
|
|
58
|
+
const namespace = await getProjectNamespace(envComponent);
|
|
59
59
|
await triggerCronjob.call(this, namespace);
|
|
60
60
|
});
|
|
61
61
|
};
|
|
@@ -22,7 +22,7 @@ import commandPauseProject from "./commandPauseProject";
|
|
|
22
22
|
import commandOpenGrafana from "./commandOpenGrafana";
|
|
23
23
|
import commandPortForward from "./commandPortForward";
|
|
24
24
|
import commandTriggerCronjob from "./commandTriggerCronjob";
|
|
25
|
-
|
|
25
|
+
|
|
26
26
|
import commandOpenGrafanaPod from "./commandOpenGrafanaPod";
|
|
27
27
|
|
|
28
28
|
export default (vorpal: Vorpal) => {
|
|
@@ -30,7 +30,6 @@ export default (vorpal: Vorpal) => {
|
|
|
30
30
|
commandInitGitlab(vorpal);
|
|
31
31
|
commandEnvVars(vorpal);
|
|
32
32
|
|
|
33
|
-
commandVariables(vorpal);
|
|
34
33
|
commandNamespace(vorpal);
|
|
35
34
|
commandListPods(vorpal);
|
|
36
35
|
commandPauseProject(vorpal);
|
|
@@ -1,31 +1,33 @@
|
|
|
1
|
+
import { isOfDeployType } from "@catladder/pipeline";
|
|
2
|
+
import { getPipelineContextByChoice } from "../../../../../config/getProjectConfig";
|
|
1
3
|
import {
|
|
2
4
|
connectToCluster,
|
|
3
5
|
getCurrentConnectedClusterName,
|
|
4
6
|
} from "../../../../../utils/cluster";
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
throw new Error("no CLUSTER_NAME configured in current project");
|
|
7
|
+
export default async function (envComponent: string) {
|
|
8
|
+
const context = getPipelineContextByChoice(envComponent);
|
|
9
|
+
if (!isOfDeployType(context.componentConfig.deploy, "kubernetes")) {
|
|
10
|
+
throw new Error("can't ensure cluster for non-kubernetes deployments");
|
|
10
11
|
}
|
|
12
|
+
const cluster = context.componentConfig.deploy.cluster || "production";
|
|
11
13
|
const connectedClusterName = await getCurrentConnectedClusterName();
|
|
12
14
|
|
|
13
|
-
if (
|
|
15
|
+
if (cluster !== connectedClusterName) {
|
|
14
16
|
this.log(
|
|
15
17
|
`you are currently connected to cluster '${connectedClusterName}'`
|
|
16
18
|
);
|
|
17
|
-
this.log(`but the project requires cluster '${
|
|
19
|
+
this.log(`but the project requires cluster '${cluster}'`);
|
|
18
20
|
const { shouldContinue } = await this.prompt({
|
|
19
21
|
type: "confirm",
|
|
20
22
|
name: "shouldContinue",
|
|
21
23
|
default: true,
|
|
22
|
-
message: `Do you want to connect to '${
|
|
24
|
+
message: `Do you want to connect to '${cluster}'?`,
|
|
23
25
|
});
|
|
24
26
|
if (!shouldContinue) {
|
|
25
27
|
this.log("abort");
|
|
26
28
|
} else {
|
|
27
|
-
await connectToCluster(
|
|
28
|
-
this.log(`connected to cluster '${
|
|
29
|
+
await connectToCluster(cluster);
|
|
30
|
+
this.log(`connected to cluster '${cluster}'`);
|
|
29
31
|
}
|
|
30
32
|
}
|
|
31
33
|
}
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import { V1Namespace, V1ObjectMeta } from "@kubernetes/client-node";
|
|
2
2
|
import k8sApi from "../../../../../k8sApi";
|
|
3
|
-
import { Env } from "../../../../../types/types";
|
|
4
3
|
import { getProjectNamespace } from "../../../../../utils/projects/index";
|
|
5
4
|
|
|
6
|
-
export default async function (
|
|
7
|
-
const namespace = await getProjectNamespace(
|
|
5
|
+
export default async function (envComponent: string) {
|
|
6
|
+
const namespace = await getProjectNamespace(envComponent);
|
|
8
7
|
try {
|
|
9
8
|
await k8sApi.readNamespace(namespace);
|
|
10
9
|
} catch (e) {
|
|
@@ -2,6 +2,7 @@ import {
|
|
|
2
2
|
readConfigSync,
|
|
3
3
|
getAllEnvs,
|
|
4
4
|
getEnvironment as _getEnvironment,
|
|
5
|
+
createContext,
|
|
5
6
|
} from "@catladder/pipeline";
|
|
6
7
|
|
|
7
8
|
import { CommandInstance } from "vorpal";
|
|
@@ -24,30 +25,54 @@ export const getEnvComponentChoices = () => {
|
|
|
24
25
|
return Object.keys(config.components).reduce<string[]>(
|
|
25
26
|
(acc, componentName) => [
|
|
26
27
|
...acc,
|
|
27
|
-
...getAllEnvs(config, componentName).map((e) =>
|
|
28
|
+
...getAllEnvs(config, componentName).map((e) => e + ":" + componentName),
|
|
28
29
|
],
|
|
29
30
|
[]
|
|
30
31
|
);
|
|
31
32
|
};
|
|
32
33
|
|
|
34
|
+
export const parseChoice = (envComponent: string) => {
|
|
35
|
+
const [env, componentName] = envComponent.split(":");
|
|
36
|
+
return { env, componentName };
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
export const getPipelineContextByChoice = (envComponent: string) => {
|
|
40
|
+
const { env, componentName } = parseChoice(envComponent);
|
|
41
|
+
const config = getProjectConfig();
|
|
42
|
+
return createContext(config, componentName, env);
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
export const getAllPipelineContexts = () => {
|
|
46
|
+
const envComponents = getEnvComponentChoices();
|
|
47
|
+
return envComponents.map(getPipelineContextByChoice);
|
|
48
|
+
};
|
|
49
|
+
|
|
33
50
|
export const getEnvironmentByChoice = (envComponent: string) => {
|
|
34
|
-
const
|
|
51
|
+
const { env, componentName } = parseChoice(envComponent);
|
|
35
52
|
const config = getProjectConfig();
|
|
36
53
|
return _getEnvironment(config, componentName, env);
|
|
37
54
|
};
|
|
38
55
|
|
|
39
|
-
|
|
56
|
+
const resolveSecrets = async (
|
|
40
57
|
vorpal: CommandInstance,
|
|
41
|
-
|
|
58
|
+
allEnvVars: Record<string, string>,
|
|
59
|
+
secretEnvVarKeys: string[]
|
|
42
60
|
) => {
|
|
43
61
|
const allVariablesInGitlab = await getAllVariables(vorpal);
|
|
44
|
-
|
|
62
|
+
console.log("resolveSecrets", { allVariablesInGitlab, allEnvVars });
|
|
45
63
|
return Object.fromEntries(
|
|
46
|
-
Object.entries(
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
if (
|
|
50
|
-
|
|
64
|
+
Object.entries(allEnvVars).map(([key, value]) => {
|
|
65
|
+
const isSecret = secretEnvVarKeys.includes(key);
|
|
66
|
+
console.log({ key, value, isSecret, allVariablesInGitlab });
|
|
67
|
+
if (isSecret) {
|
|
68
|
+
// secrets have CL_XXXX structure
|
|
69
|
+
const found = allVariablesInGitlab.find((v) => "$" + v.key === value);
|
|
70
|
+
console.log({ found });
|
|
71
|
+
if (found) {
|
|
72
|
+
return [key, found.value];
|
|
73
|
+
} else {
|
|
74
|
+
return [key, ""];
|
|
75
|
+
}
|
|
51
76
|
}
|
|
52
77
|
return [key, value];
|
|
53
78
|
})
|
|
@@ -59,5 +84,9 @@ export const getEnvVars = async (
|
|
|
59
84
|
envComponent: string
|
|
60
85
|
) => {
|
|
61
86
|
const envionment = getEnvironmentByChoice(envComponent);
|
|
62
|
-
return resolveSecrets(
|
|
87
|
+
return resolveSecrets(
|
|
88
|
+
vorpal,
|
|
89
|
+
envionment.envVars,
|
|
90
|
+
envionment.secretEnvVarKeys
|
|
91
|
+
);
|
|
63
92
|
};
|
package/src/types/types.ts
CHANGED
package/src/utils/cluster.ts
CHANGED
|
@@ -9,8 +9,21 @@ export const getCurrentConnectedClusterName = async () => {
|
|
|
9
9
|
return findKey(clusters, { fullName: currentContext });
|
|
10
10
|
};
|
|
11
11
|
|
|
12
|
-
export const
|
|
13
|
-
|
|
12
|
+
export const getClusterByFullName = (fullName: string) => {
|
|
13
|
+
const found = Object.entries(getAllClusters()).find(
|
|
14
|
+
([, config]) => config.fullName === fullName
|
|
15
|
+
);
|
|
16
|
+
if (found) {
|
|
17
|
+
return { name: found[0], cluster: found[1] };
|
|
18
|
+
} else {
|
|
19
|
+
return null;
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export const getClusterByName = (name: string) => getAllClusters()[name];
|
|
24
|
+
|
|
25
|
+
export const getAllClusters = () => {
|
|
26
|
+
return clusters;
|
|
14
27
|
};
|
|
15
28
|
|
|
16
29
|
export const getAllClusterNames = () => Object.keys(clusters);
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { withFile } from "tmp-promise";
|
|
2
|
+
import yaml from "js-yaml";
|
|
3
|
+
|
|
4
|
+
import { readFile, writeFile } from "fs-extra";
|
|
5
|
+
import getEditor from "./getEditor";
|
|
6
|
+
|
|
7
|
+
export const editAsFile = async <T>(inObject: T): Promise<T> => {
|
|
8
|
+
const asString = yaml.safeDump(inObject);
|
|
9
|
+
let newContent;
|
|
10
|
+
|
|
11
|
+
await withFile(
|
|
12
|
+
async ({ path: tmpFilePath }) => {
|
|
13
|
+
await writeFile(tmpFilePath, asString);
|
|
14
|
+
await (await getEditor()).open(tmpFilePath);
|
|
15
|
+
newContent = yaml.load((await readFile(tmpFilePath)).toString("utf-8"));
|
|
16
|
+
},
|
|
17
|
+
{ postfix: ".yml" }
|
|
18
|
+
);
|
|
19
|
+
|
|
20
|
+
return newContent;
|
|
21
|
+
};
|
package/src/utils/gitlab.ts
CHANGED
|
@@ -39,14 +39,18 @@ export const getGitlabToken = async (vorpal: CommandInstance) => {
|
|
|
39
39
|
return getPreference(TOKEN_KEY);
|
|
40
40
|
};
|
|
41
41
|
|
|
42
|
-
export const doGitlabRequest = async (
|
|
42
|
+
export const doGitlabRequest = async <T = any>(
|
|
43
43
|
vorpal: CommandInstance,
|
|
44
44
|
path: string,
|
|
45
|
-
data
|
|
46
|
-
|
|
45
|
+
data: any = undefined,
|
|
46
|
+
update?: boolean
|
|
47
|
+
): Promise<T> => {
|
|
47
48
|
const rootToken = await getGitlabToken(vorpal);
|
|
49
|
+
|
|
50
|
+
const method = data ? (update ? "PUT" : "POST") : "GET";
|
|
51
|
+
|
|
48
52
|
const result = await fetch(`https://git.panter.ch/api/v4/${path}`, {
|
|
49
|
-
method
|
|
53
|
+
method,
|
|
50
54
|
headers: {
|
|
51
55
|
"Content-Type": "application/json",
|
|
52
56
|
"Private-Token": rootToken,
|
|
@@ -95,3 +99,51 @@ export const getAllVariables = async (
|
|
|
95
99
|
const { id } = await getProjectInfo(vorpal);
|
|
96
100
|
return await doGitlabRequest(this, `projects/${id}/variables`);
|
|
97
101
|
};
|
|
102
|
+
|
|
103
|
+
const createVariable = async (
|
|
104
|
+
vorpal: CommandInstance,
|
|
105
|
+
projectId: string,
|
|
106
|
+
key: string,
|
|
107
|
+
value: string
|
|
108
|
+
) => {
|
|
109
|
+
return await doGitlabRequest(this, `projects/${projectId}/variables`, {
|
|
110
|
+
key,
|
|
111
|
+
value,
|
|
112
|
+
});
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
const updateVariable = async (
|
|
116
|
+
vorpal: CommandInstance,
|
|
117
|
+
projectId: string,
|
|
118
|
+
key: string,
|
|
119
|
+
value: string
|
|
120
|
+
) => {
|
|
121
|
+
return await doGitlabRequest(
|
|
122
|
+
this,
|
|
123
|
+
`projects/${projectId}/variables/${key}`,
|
|
124
|
+
{
|
|
125
|
+
value,
|
|
126
|
+
},
|
|
127
|
+
true
|
|
128
|
+
);
|
|
129
|
+
};
|
|
130
|
+
export const upsertAllVariables = async (
|
|
131
|
+
vorpal: CommandInstance,
|
|
132
|
+
variables: Record<string, string>,
|
|
133
|
+
env: string,
|
|
134
|
+
componentName: string
|
|
135
|
+
): Promise<void> => {
|
|
136
|
+
const { id } = await getProjectInfo(vorpal);
|
|
137
|
+
|
|
138
|
+
console.log("upsertAllVariables", variables);
|
|
139
|
+
|
|
140
|
+
for (const [key, value] of Object.entries(variables ?? {})) {
|
|
141
|
+
const fullKey = "CL_" + env + "_" + componentName + "_" + key;
|
|
142
|
+
|
|
143
|
+
try {
|
|
144
|
+
await updateVariable(vorpal, id, fullKey, value);
|
|
145
|
+
} catch (e) {
|
|
146
|
+
await createVariable(vorpal, id, fullKey, value);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
};
|
|
@@ -1,17 +1,8 @@
|
|
|
1
1
|
import { exec } from "child-process-promise";
|
|
2
2
|
import { join } from "path";
|
|
3
|
+
import { getProjectConfig, parseChoice } from "../../config/getProjectConfig";
|
|
3
4
|
import k8sApi from "../../k8sApi";
|
|
4
|
-
import {
|
|
5
|
-
import { readFileOrError, readYaml } from "../files";
|
|
6
|
-
import formatEnvVars from "../formatEnvVars";
|
|
7
|
-
import { hasBitwarden, readPassEnvVars, syncBitwarden } from "../passwordstore";
|
|
8
|
-
import { filter } from "../promise";
|
|
9
|
-
|
|
10
|
-
import { merge } from "lodash";
|
|
11
|
-
import { getProjectConfig } from "../../config/getProjectConfig";
|
|
12
|
-
|
|
13
|
-
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
14
|
-
const YAWN = require("yawn-yaml/cjs");
|
|
5
|
+
import { readFileOrError } from "../files";
|
|
15
6
|
|
|
16
7
|
export const getGitRoot = async () => {
|
|
17
8
|
return (await exec("git rev-parse --show-toplevel")).stdout?.trim();
|
|
@@ -33,101 +24,27 @@ export const hasGitlabCiFile = async () => {
|
|
|
33
24
|
return true;
|
|
34
25
|
};
|
|
35
26
|
|
|
36
|
-
export const getProjectNamespace = async (
|
|
27
|
+
export const getProjectNamespace = async (envComponent: string) => {
|
|
28
|
+
const { env } = parseChoice(envComponent);
|
|
37
29
|
const config = getProjectConfig();
|
|
38
30
|
return `${config.customerName}-${config.appName}-${env}`;
|
|
39
31
|
};
|
|
40
32
|
|
|
41
|
-
export const getProjectPods = async (
|
|
42
|
-
const namespace = await getProjectNamespace(
|
|
33
|
+
export const getProjectPods = async (envComponent: string) => {
|
|
34
|
+
const namespace = await getProjectNamespace(envComponent);
|
|
43
35
|
const res = await k8sApi.listNamespacedPod(namespace);
|
|
44
36
|
|
|
45
37
|
return res.body.items;
|
|
46
38
|
};
|
|
47
39
|
|
|
48
|
-
export const getProjectPvcs = async (
|
|
49
|
-
const namespace = await getProjectNamespace(
|
|
40
|
+
export const getProjectPvcs = async (envComponent: string) => {
|
|
41
|
+
const namespace = await getProjectNamespace(envComponent);
|
|
50
42
|
const res = await k8sApi.listNamespacedPersistentVolumeClaim(namespace);
|
|
51
43
|
|
|
52
44
|
return res.body.items;
|
|
53
45
|
};
|
|
54
46
|
|
|
55
|
-
export const getProjectPodNames = async (
|
|
56
|
-
const pods = await getProjectPods(
|
|
47
|
+
export const getProjectPodNames = async (envComponent: string) => {
|
|
48
|
+
const pods = await getProjectPods(envComponent);
|
|
57
49
|
return pods.map((n) => n.metadata.name);
|
|
58
50
|
};
|
|
59
|
-
|
|
60
|
-
export const getPassPath = async (env: Env) => {
|
|
61
|
-
const { CUSTOMER_NAME, APP_NAME } = await getLocalProjectVariables();
|
|
62
|
-
return `${CUSTOMER_NAME}/${APP_NAME}/${env}/secrets.yml`;
|
|
63
|
-
};
|
|
64
|
-
|
|
65
|
-
export const getProjectValuesFiles = async (env: Env, subApp?: string) => {
|
|
66
|
-
const gitRoot = await getGitRoot();
|
|
67
|
-
const possibleFiles = ["values.yml", `values-${env}.yml`].map((file) =>
|
|
68
|
-
subApp ? join(gitRoot, subApp, file) : join(gitRoot, file)
|
|
69
|
-
);
|
|
70
|
-
return filter(possibleFiles, async (file) => {
|
|
71
|
-
const [error] = await readFileOrError(file);
|
|
72
|
-
return !error;
|
|
73
|
-
});
|
|
74
|
-
};
|
|
75
|
-
|
|
76
|
-
export const getAllValues = async (env: Env, subApp?: string) => {
|
|
77
|
-
const valuesFilePaths = await getProjectValuesFiles(env, subApp);
|
|
78
|
-
return Promise.all(
|
|
79
|
-
valuesFilePaths.map(async (file) => (await readYaml(file)) as IValueFile)
|
|
80
|
-
);
|
|
81
|
-
};
|
|
82
|
-
|
|
83
|
-
export const getProjectValues = async (env: Env, subApp?: string) => {
|
|
84
|
-
const values = await getAllValues(env, subApp);
|
|
85
|
-
return merge({}, ...values) as IValueFile;
|
|
86
|
-
};
|
|
87
|
-
|
|
88
|
-
export const getAllPublicEnvVars = async (env: Env, subApp?: string) => {
|
|
89
|
-
return formatEnvVars(
|
|
90
|
-
(await getAllValues(env, subApp)).reduce<ISecrets>((acc, value) => {
|
|
91
|
-
if (value.env && value.env.public) {
|
|
92
|
-
return {
|
|
93
|
-
...acc,
|
|
94
|
-
...value.env.public,
|
|
95
|
-
};
|
|
96
|
-
}
|
|
97
|
-
return acc;
|
|
98
|
-
}, {})
|
|
99
|
-
);
|
|
100
|
-
};
|
|
101
|
-
export const getAllSecretsEnvVarsMapping = async (
|
|
102
|
-
env: Env,
|
|
103
|
-
subApp?: string
|
|
104
|
-
) => {
|
|
105
|
-
return (await getAllValues(env, subApp)).reduce<ISecrets>((acc, value) => {
|
|
106
|
-
if (value.env && value.env.secret) {
|
|
107
|
-
return {
|
|
108
|
-
...acc,
|
|
109
|
-
...value.env.secret,
|
|
110
|
-
};
|
|
111
|
-
}
|
|
112
|
-
return acc;
|
|
113
|
-
}, {});
|
|
114
|
-
};
|
|
115
|
-
|
|
116
|
-
export const hasSecrets = async (env: Env, subApp?: string) => {
|
|
117
|
-
return Object.keys(await getAllSecretsEnvVarsMapping(env, subApp)).length > 0;
|
|
118
|
-
};
|
|
119
|
-
|
|
120
|
-
export const getAllEnvVars = async (
|
|
121
|
-
env: Env,
|
|
122
|
-
subApp?: string
|
|
123
|
-
): Promise<Record<string, string>> => {
|
|
124
|
-
throw new Error("needs to be re-implemented");
|
|
125
|
-
};
|
|
126
|
-
|
|
127
|
-
export const getAllSecretEnvVars = async (env: Env, subApp?: string) => {
|
|
128
|
-
throw new Error("needs to be re-implemented");
|
|
129
|
-
};
|
|
130
|
-
|
|
131
|
-
export const getLocalProjectVariables = () => {
|
|
132
|
-
throw new Error("use getProjectConfig");
|
|
133
|
-
};
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const js_yaml_1 = __importDefault(require("js-yaml"));
|
|
7
|
-
const projects_1 = require("../../../../utils/projects");
|
|
8
|
-
exports.default = (vorpal) => vorpal
|
|
9
|
-
.command("project-variables", "get local project variables")
|
|
10
|
-
.action(async function () {
|
|
11
|
-
const variables = await (0, projects_1.getLocalProjectVariables)();
|
|
12
|
-
this.log("");
|
|
13
|
-
this.log(js_yaml_1.default.safeDump(variables));
|
|
14
|
-
this.log("");
|
|
15
|
-
});
|
|
16
|
-
//# sourceMappingURL=commandVariables.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"commandVariables.js","sourceRoot":"","sources":["../../../../../src/apps/shell/commands/project/commandVariables.ts"],"names":[],"mappings":";;;;;AAAA,sDAA2B;AAE3B,yDAAsE;AAEtE,kBAAe,CAAC,MAAc,EAAE,EAAE,CAChC,MAAM;KACH,OAAO,CAAC,mBAAmB,EAAE,6BAA6B,CAAC;KAC3D,MAAM,CAAC,KAAK;IACX,MAAM,SAAS,GAAG,MAAM,IAAA,mCAAwB,GAAE,CAAC;IACnD,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;IACb,IAAI,CAAC,GAAG,CAAC,iBAAI,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC,CAAC;IACnC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;AACf,CAAC,CAAC,CAAC"}
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getCurrentSubApp = exports.getSubAppsInMonoRepo = void 0;
|
|
4
|
-
const fs_extra_1 = require("fs-extra");
|
|
5
|
-
const path_1 = require("path");
|
|
6
|
-
const projects_1 = require("../../../../../utils/projects");
|
|
7
|
-
const getSubAppsInMonoRepo = async () => {
|
|
8
|
-
const gitRoot = await (0, projects_1.getGitRoot)();
|
|
9
|
-
return (0, fs_extra_1.readdirSync)(gitRoot)
|
|
10
|
-
.map((dir) => ({
|
|
11
|
-
componentName: dir,
|
|
12
|
-
ci: (0, path_1.join)(gitRoot, dir, ".gitlab-ci.yml"),
|
|
13
|
-
path: (0, path_1.join)(gitRoot, dir),
|
|
14
|
-
}))
|
|
15
|
-
.filter(({ ci }) => (0, fs_extra_1.existsSync)(ci));
|
|
16
|
-
};
|
|
17
|
-
exports.getSubAppsInMonoRepo = getSubAppsInMonoRepo;
|
|
18
|
-
const getCurrentSubApp = async () => {
|
|
19
|
-
const gitRoot = await (0, projects_1.getGitRoot)();
|
|
20
|
-
const subApps = await (0, exports.getSubAppsInMonoRepo)();
|
|
21
|
-
const currentDir = process.cwd();
|
|
22
|
-
return subApps.find((a) => currentDir.startsWith((0, path_1.join)(gitRoot, a.componentName)));
|
|
23
|
-
};
|
|
24
|
-
exports.getCurrentSubApp = getCurrentSubApp;
|
|
25
|
-
//# sourceMappingURL=monorepo.js.map
|