@catladder/cli 0.0.0-refactor-cli-add-improved-git-utilities-916545cc → 0.0.0-refactor-remove-rails-hosts-60f9538c
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/bundles/catci/index.js +43322 -44345
- package/dist/bundles/catenv/index.js +27564 -43997
- package/dist/bundles/cli/index.js +149115 -143958
- package/dist/cli/src/apps/catenv/catenv.js +1 -1
- package/dist/cli/src/apps/catenv/catenv.js.map +1 -1
- package/dist/cli/src/apps/cli/commands/project/index.js +0 -4
- package/dist/cli/src/apps/cli/commands/project/index.js.map +1 -1
- package/dist/cli/src/apps/cli/commands/project/setup/setupAccessTokens.d.ts +1 -2
- package/dist/cli/src/apps/cli/commands/project/setup/setupAccessTokens.js +3 -11
- package/dist/cli/src/apps/cli/commands/project/setup/setupAccessTokens.js.map +1 -1
- package/dist/cli/src/apps/cli/commands/project/setup/setupCloudRun.js +2 -4
- package/dist/cli/src/apps/cli/commands/project/setup/setupCloudRun.js.map +1 -1
- package/dist/cli/src/apps/cli/commands/project/setup/setupKubernetes.d.ts +1 -2
- package/dist/cli/src/apps/cli/commands/project/setup/setupKubernetes.js +9 -23
- package/dist/cli/src/apps/cli/commands/project/setup/setupKubernetes.js.map +1 -1
- package/dist/cli/src/apps/cli/commands/project/setup/setupTopic.js +4 -6
- package/dist/cli/src/apps/cli/commands/project/setup/setupTopic.js.map +1 -1
- package/dist/cli/src/apps/cli/utils/getGoogleAuthUserNumber.d.ts +1 -1
- package/dist/cli/src/apps/cli/utils/getGoogleAuthUserNumber.js +4 -3
- package/dist/cli/src/apps/cli/utils/getGoogleAuthUserNumber.js.map +1 -1
- package/dist/cli/src/packageInfos.js +0 -1
- package/dist/cli/src/packageInfos.js.map +1 -1
- package/dist/cli/src/utils/gitlab.d.ts +7 -10
- package/dist/cli/src/utils/gitlab.js +45 -67
- package/dist/cli/src/utils/gitlab.js.map +1 -1
- package/dist/cli/src/utils/preferences/index.d.ts +3 -0
- package/dist/cli/src/utils/preferences/index.js +35 -0
- package/dist/cli/src/utils/preferences/index.js.map +1 -0
- package/dist/pipeline/src/build/cache/createJobCache.js +2 -2
- package/dist/pipeline/src/build/cache/createJobCache.js.map +1 -1
- package/dist/pipeline/src/build/sbom.js +2 -2
- package/dist/pipeline/src/build/sbom.js.map +1 -1
- package/dist/pipeline/src/build/types.d.ts +3 -3
- package/dist/pipeline/src/config/readConfig.js +0 -1
- package/dist/pipeline/src/config/readConfig.js.map +1 -1
- package/dist/pipeline/src/context/createComponentContext.js +1 -1
- package/dist/pipeline/src/context/createComponentContext.js.map +1 -1
- package/dist/pipeline/src/context/getEnvironmentVariables.d.ts +1 -1
- package/dist/pipeline/src/context/getEnvironmentVariables.js +1 -5
- package/dist/pipeline/src/context/getEnvironmentVariables.js.map +1 -1
- package/dist/pipeline/src/deploy/base/deploy.js +3 -3
- package/dist/pipeline/src/deploy/base/deploy.js.map +1 -1
- package/dist/pipeline/src/deploy/cloudRun/createJobs/cloudRunJobs.js +2 -10
- package/dist/pipeline/src/deploy/cloudRun/createJobs/cloudRunJobs.js.map +1 -1
- package/dist/pipeline/src/deploy/cloudRun/createJobs/cloudRunServices.js +2 -4
- package/dist/pipeline/src/deploy/cloudRun/createJobs/cloudRunServices.js.map +1 -1
- package/dist/pipeline/src/deploy/types/index.d.ts +3 -3
- package/dist/pipeline/src/pipeline/createMainPipeline.js +13 -7
- package/dist/pipeline/src/pipeline/createMainPipeline.js.map +1 -1
- package/dist/pipeline/src/pipeline/generatePipelineFiles.d.ts +7 -40
- package/dist/pipeline/src/pipeline/generatePipelineFiles.js +69 -42
- package/dist/pipeline/src/pipeline/generatePipelineFiles.js.map +1 -1
- package/dist/pipeline/src/pipeline/gitlab/createGitlabJobs.d.ts +6 -4
- package/dist/pipeline/src/pipeline/gitlab/gitlabReleaseJobs.d.ts +0 -2
- package/dist/pipeline/src/pipeline/gitlab/gitlabReleaseJobs.js +2 -4
- package/dist/pipeline/src/pipeline/gitlab/gitlabReleaseJobs.js.map +1 -1
- package/dist/pipeline/src/pipeline/index.d.ts +0 -1
- package/dist/pipeline/src/pipeline/index.js +0 -1
- package/dist/pipeline/src/pipeline/index.js.map +1 -1
- package/dist/pipeline/src/types/config.d.ts +3 -3
- package/dist/pipeline/src/types/gitlab-types.d.ts +2 -1
- package/dist/pipeline/src/types/pipeline.d.ts +0 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +15 -14
- package/src/apps/catenv/catenv.ts +1 -1
- package/src/apps/cli/commands/project/index.ts +1 -6
- package/src/apps/cli/commands/project/setup/setupAccessTokens.ts +6 -16
- package/src/apps/cli/commands/project/setup/setupCloudRun.ts +2 -4
- package/src/apps/cli/commands/project/setup/setupKubernetes.ts +27 -30
- package/src/apps/cli/commands/project/setup/setupTopic.ts +11 -6
- package/src/apps/cli/utils/getGoogleAuthUserNumber.ts +4 -6
- package/src/packageInfos.ts +0 -1
- package/src/utils/gitlab.ts +101 -99
- package/src/utils/preferences/index.ts +36 -0
- package/dist/cli/src/apps/cli/commands/project/commandMigrateHelm3.d.ts +0 -7
- package/dist/cli/src/apps/cli/commands/project/commandMigrateHelm3.js +0 -46
- package/dist/cli/src/apps/cli/commands/project/commandMigrateHelm3.js.map +0 -1
- package/dist/cli/src/apps/cli/commands/project/commandOpenCostDashboard.d.ts +0 -3
- package/dist/cli/src/apps/cli/commands/project/commandOpenCostDashboard.js +0 -22
- package/dist/cli/src/apps/cli/commands/project/commandOpenCostDashboard.js.map +0 -1
- package/dist/cli/src/apps/cli/commands/project/commandOpenDashboard.d.ts +0 -3
- package/dist/cli/src/apps/cli/commands/project/commandOpenDashboard.js +0 -22
- package/dist/cli/src/apps/cli/commands/project/commandOpenDashboard.js.map +0 -1
- package/dist/cli/src/git/getGitConfigVars.d.ts +0 -4
- package/dist/cli/src/git/getGitConfigVars.js +0 -14
- package/dist/cli/src/git/getGitConfigVars.js.map +0 -1
- package/dist/cli/src/git/getGitRemoteHostAndPath.d.ts +0 -9
- package/dist/cli/src/git/getGitRemoteHostAndPath.js +0 -23
- package/dist/cli/src/git/getGitRemoteHostAndPath.js.map +0 -1
- package/dist/cli/src/git/getProjectRootPath.d.ts +0 -1
- package/dist/cli/src/git/getProjectRootPath.js +0 -10
- package/dist/cli/src/git/getProjectRootPath.js.map +0 -1
- package/dist/cli/src/git/gitConfig.d.ts +0 -23
- package/dist/cli/src/git/gitConfig.js +0 -60
- package/dist/cli/src/git/gitConfig.js.map +0 -1
- package/dist/cli/src/git/index.d.ts +0 -4
- package/dist/cli/src/git/index.js +0 -21
- package/dist/cli/src/git/index.js.map +0 -1
- package/dist/cli/src/gitlab/apiClient.d.ts +0 -5
- package/dist/cli/src/gitlab/apiClient.js +0 -21
- package/dist/cli/src/gitlab/apiClient.js.map +0 -1
- package/dist/cli/src/gitlab/getGitlabProjectId.d.ts +0 -4
- package/dist/cli/src/gitlab/getGitlabProjectId.js +0 -29
- package/dist/cli/src/gitlab/getGitlabProjectId.js.map +0 -1
- package/dist/cli/src/gitlab/gitlabToken.d.ts +0 -10
- package/dist/cli/src/gitlab/gitlabToken.js +0 -42
- package/dist/cli/src/gitlab/gitlabToken.js.map +0 -1
- package/dist/cli/src/gitlab/index.d.ts +0 -3
- package/dist/cli/src/gitlab/index.js +0 -20
- package/dist/cli/src/gitlab/index.js.map +0 -1
- package/dist/cli/src/utils/preferences.d.ts +0 -15
- package/dist/cli/src/utils/preferences.js +0 -61
- package/dist/cli/src/utils/preferences.js.map +0 -1
- package/dist/cli/src/utils/projectPreferences.d.ts +0 -5
- package/dist/cli/src/utils/projectPreferences.js +0 -54
- package/dist/cli/src/utils/projectPreferences.js.map +0 -1
- package/dist/pipeline/src/pipeline/createChildPipeline.d.ts +0 -3
- package/dist/pipeline/src/pipeline/createChildPipeline.js +0 -30
- package/dist/pipeline/src/pipeline/createChildPipeline.js.map +0 -1
- package/dist/pipeline/src/pipeline/gitlab/getPipelineTriggerForGitlabChildPipeline.d.ts +0 -1
- package/dist/pipeline/src/pipeline/gitlab/getPipelineTriggerForGitlabChildPipeline.js +0 -32
- package/dist/pipeline/src/pipeline/gitlab/getPipelineTriggerForGitlabChildPipeline.js.map +0 -1
- package/src/apps/cli/commands/project/commandMigrateHelm3.ts +0 -63
- package/src/apps/cli/commands/project/commandOpenCostDashboard.ts +0 -32
- package/src/apps/cli/commands/project/commandOpenDashboard.ts +0 -28
- package/src/git/getGitConfigVars.ts +0 -11
- package/src/git/getGitRemoteHostAndPath.ts +0 -28
- package/src/git/getProjectRootPath.ts +0 -6
- package/src/git/gitConfig.ts +0 -86
- package/src/git/index.ts +0 -4
- package/src/gitlab/apiClient.ts +0 -23
- package/src/gitlab/getGitlabProjectId.ts +0 -32
- package/src/gitlab/gitlabToken.ts +0 -52
- package/src/gitlab/index.ts +0 -3
- package/src/utils/preferences.ts +0 -85
- package/src/utils/projectPreferences.ts +0 -78
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.upsertProjectPerferences = exports.getProjectPreferences = void 0;
|
|
4
|
-
const promises_1 = require("fs/promises");
|
|
5
|
-
const fs_1 = require("fs");
|
|
6
|
-
const path_1 = require("path");
|
|
7
|
-
const git_1 = require("../git");
|
|
8
|
-
const directory = ".catladder";
|
|
9
|
-
const file = "preferences.json";
|
|
10
|
-
const perfKeys = [
|
|
11
|
-
"gitlabProjectId",
|
|
12
|
-
];
|
|
13
|
-
const fallbackValues = {
|
|
14
|
-
gitlabProjectId: null,
|
|
15
|
-
};
|
|
16
|
-
const perferencesWithParsed = (parsed) => perfKeys.reduce((acc, key) => { var _a, _b; return Object.assign(acc, { [key]: (_b = (_a = parsed[key]) !== null && _a !== void 0 ? _a : fallbackValues[key]) !== null && _b !== void 0 ? _b : null }); }, {});
|
|
17
|
-
const encoding = "utf-8";
|
|
18
|
-
const readPreferences = (filePath) => (0, promises_1.readFile)(filePath, { encoding });
|
|
19
|
-
const writePreferences = (filePath, preferences) => (0, promises_1.writeFile)(filePath, JSON.stringify(preferences, null, 2), {
|
|
20
|
-
encoding,
|
|
21
|
-
mode: 0o600,
|
|
22
|
-
});
|
|
23
|
-
const ensureDir = async (dirPath) => (0, fs_1.existsSync)(dirPath)
|
|
24
|
-
? dirPath
|
|
25
|
-
: (0, promises_1.mkdir)(dirPath, { recursive: true, mode: 0o700 });
|
|
26
|
-
const ensureFile = async (givenFilePath) => {
|
|
27
|
-
if ((givenFilePath === null || givenFilePath === void 0 ? void 0 : givenFilePath.length) && (0, fs_1.existsSync)(givenFilePath)) {
|
|
28
|
-
return givenFilePath;
|
|
29
|
-
}
|
|
30
|
-
const rootPath = await (0, git_1.getProjectRootPath)();
|
|
31
|
-
const dirPath = (0, path_1.join)(rootPath, directory);
|
|
32
|
-
const filePath = (0, path_1.join)(dirPath, file);
|
|
33
|
-
if ((0, fs_1.existsSync)(filePath)) {
|
|
34
|
-
return filePath;
|
|
35
|
-
}
|
|
36
|
-
await ensureDir(dirPath);
|
|
37
|
-
await writePreferences(filePath, perferencesWithParsed({}));
|
|
38
|
-
return filePath;
|
|
39
|
-
};
|
|
40
|
-
const getProjectPreferences = async (givenFilePath) => {
|
|
41
|
-
var _a;
|
|
42
|
-
const filePath = await ensureFile(givenFilePath);
|
|
43
|
-
const fileString = await readPreferences(filePath);
|
|
44
|
-
const fileParsed = (_a = JSON.parse(fileString || "null")) !== null && _a !== void 0 ? _a : {};
|
|
45
|
-
return perferencesWithParsed(fileParsed);
|
|
46
|
-
};
|
|
47
|
-
exports.getProjectPreferences = getProjectPreferences;
|
|
48
|
-
const upsertProjectPerferences = async (newPerfs = {}, givenFilePath) => {
|
|
49
|
-
const filePath = await ensureFile(givenFilePath);
|
|
50
|
-
const currentPerfs = await (0, exports.getProjectPreferences)(filePath);
|
|
51
|
-
return writePreferences(filePath, { ...currentPerfs, ...newPerfs });
|
|
52
|
-
};
|
|
53
|
-
exports.upsertProjectPerferences = upsertProjectPerferences;
|
|
54
|
-
//# sourceMappingURL=projectPreferences.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"projectPreferences.js","sourceRoot":"","sources":["../../../../src/utils/projectPreferences.ts"],"names":[],"mappings":"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"}
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createChildPipeline = void 0;
|
|
4
|
-
const rules_1 = require("../rules");
|
|
5
|
-
const createAllJobs_1 = require("./createAllJobs");
|
|
6
|
-
const getPipelineStages_1 = require("./getPipelineStages");
|
|
7
|
-
const createGitlabJobs_1 = require("./gitlab/createGitlabJobs");
|
|
8
|
-
const createGitlabPipeline_1 = require("./gitlab/createGitlabPipeline");
|
|
9
|
-
const createChildPipeline = async (pipelineType, trigger, config) => {
|
|
10
|
-
const jobs = await (0, createAllJobs_1.createAllJobs)({
|
|
11
|
-
config,
|
|
12
|
-
trigger,
|
|
13
|
-
pipelineType,
|
|
14
|
-
});
|
|
15
|
-
const stages = (0, getPipelineStages_1.getPipelineStages)(config);
|
|
16
|
-
if (pipelineType === "gitlab") {
|
|
17
|
-
const gitlabJobs = await (0, createGitlabJobs_1.createGitlabJobs)(jobs);
|
|
18
|
-
return (0, createGitlabPipeline_1.createGitlabPipelineWithDefaults)({
|
|
19
|
-
workflow: {
|
|
20
|
-
rules: rules_1.RULES_ALWAYS,
|
|
21
|
-
},
|
|
22
|
-
stages,
|
|
23
|
-
jobs: Object.fromEntries(gitlabJobs.map(({ gitlabJob, name }) => [name, gitlabJob])),
|
|
24
|
-
variables: config.runnerVariables,
|
|
25
|
-
});
|
|
26
|
-
}
|
|
27
|
-
throw new Error(`${pipelineType} is not supported`);
|
|
28
|
-
};
|
|
29
|
-
exports.createChildPipeline = createChildPipeline;
|
|
30
|
-
//# sourceMappingURL=createChildPipeline.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"createChildPipeline.js","sourceRoot":"","sources":["../../../../../pipeline/src/pipeline/createChildPipeline.ts"],"names":[],"mappings":";;;AAAA,oCAAwC;AAIxC,mDAAgD;AAChD,2DAAwD;AACxD,gEAA6D;AAC7D,wEAAiF;AAE1E,MAAM,mBAAmB,GAAG,KAAK,EACtC,YAAe,EACf,OAAwB,EACxB,MAAc,EACQ,EAAE;IACxB,MAAM,IAAI,GAAG,MAAM,IAAA,6BAAa,EAAC;QAC/B,MAAM;QACN,OAAO;QACP,YAAY;KACb,CAAC,CAAC;IAEH,MAAM,MAAM,GAAG,IAAA,qCAAiB,EAAC,MAAM,CAAC,CAAC;IAEzC,IAAI,YAAY,KAAK,QAAQ,EAAE,CAAC;QAC9B,MAAM,UAAU,GAAG,MAAM,IAAA,mCAAgB,EAAC,IAAI,CAAC,CAAC;QAChD,OAAO,IAAA,uDAAgC,EAAC;YACtC,QAAQ,EAAE;gBACR,KAAK,EAAE,oBAAY;aACpB;YACD,MAAM;YACN,IAAI,EAAE,MAAM,CAAC,WAAW,CACtB,UAAU,CAAC,GAAG,CAAC,CAAC,EAAE,SAAS,EAAE,IAAI,EAAE,EAAE,EAAE,CAAC,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC,CAC3D;YACD,SAAS,EAAE,MAAM,CAAC,eAAe;SAClC,CAAgB,CAAC;IACpB,CAAC;IACD,MAAM,IAAI,KAAK,CAAC,GAAG,YAAY,mBAAmB,CAAC,CAAC;AACtD,CAAC,CAAC;AA3BW,QAAA,mBAAmB,uBA2B9B"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function getPipelineTriggerForGitlabChildPipeline(): "mainBranch" | "mr" | "taggedRelease";
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getPipelineTriggerForGitlabChildPipeline = void 0;
|
|
4
|
-
const constants_1 = require("../../constants");
|
|
5
|
-
function getPipelineTriggerForGitlabChildPipeline() {
|
|
6
|
-
const { CI_MERGE_REQUEST_ID, CI_COMMIT_TAG, CI_COMMIT_BRANCH, CI_DEFAULT_BRANCH, } = process.env;
|
|
7
|
-
const isDefaultBranch = Boolean(CI_DEFAULT_BRANCH) && CI_COMMIT_BRANCH === CI_DEFAULT_BRANCH;
|
|
8
|
-
const isHotfixBranch = CI_COMMIT_BRANCH
|
|
9
|
-
? /^[0-9]+\.([0-9]+|x)\.x$/.test(CI_COMMIT_BRANCH)
|
|
10
|
-
: false;
|
|
11
|
-
const isMergeRequest = Boolean(CI_MERGE_REQUEST_ID);
|
|
12
|
-
const isTaggedRelease = Boolean(CI_COMMIT_TAG);
|
|
13
|
-
console.info(`catladder version ${constants_1.PIPELINE_IMAGE_TAG}`);
|
|
14
|
-
const trigger = isMergeRequest || isHotfixBranch
|
|
15
|
-
? "mr"
|
|
16
|
-
: isDefaultBranch
|
|
17
|
-
? "mainBranch"
|
|
18
|
-
: isTaggedRelease
|
|
19
|
-
? "taggedRelease"
|
|
20
|
-
: null;
|
|
21
|
-
if (!trigger) {
|
|
22
|
-
throw new Error("no matching trigger: " +
|
|
23
|
-
JSON.stringify({
|
|
24
|
-
isMergeRequest,
|
|
25
|
-
isDefaultBranch,
|
|
26
|
-
isTaggedRelease,
|
|
27
|
-
}, null, 2));
|
|
28
|
-
}
|
|
29
|
-
return trigger;
|
|
30
|
-
}
|
|
31
|
-
exports.getPipelineTriggerForGitlabChildPipeline = getPipelineTriggerForGitlabChildPipeline;
|
|
32
|
-
//# sourceMappingURL=getPipelineTriggerForGitlabChildPipeline.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"getPipelineTriggerForGitlabChildPipeline.js","sourceRoot":"","sources":["../../../../../../pipeline/src/pipeline/gitlab/getPipelineTriggerForGitlabChildPipeline.ts"],"names":[],"mappings":";;;AACA,+CAAqD;AAErD,SAAgB,wCAAwC;IACtD,MAAM,EACJ,mBAAmB,EACnB,aAAa,EACb,gBAAgB,EAChB,iBAAiB,GAClB,GAAG,OAAO,CAAC,GAAG,CAAC;IAEhB,MAAM,eAAe,GACnB,OAAO,CAAC,iBAAiB,CAAC,IAAI,gBAAgB,KAAK,iBAAiB,CAAC;IACvE,MAAM,cAAc,GAAG,gBAAgB;QACrC,CAAC,CAAC,yBAAyB,CAAC,IAAI,CAAC,gBAAgB,CAAC;QAClD,CAAC,CAAC,KAAK,CAAC;IACV,MAAM,cAAc,GAAG,OAAO,CAAC,mBAAmB,CAAC,CAAC;IACpD,MAAM,eAAe,GAAG,OAAO,CAAC,aAAa,CAAC,CAAC;IAE/C,OAAO,CAAC,IAAI,CAAC,qBAAqB,8BAAkB,EAAE,CAAC,CAAC;IAExD,MAAM,OAAO,GACX,cAAc,IAAI,cAAc;QAC9B,CAAC,CAAC,IAAI;QACN,CAAC,CAAC,eAAe;YACf,CAAC,CAAC,YAAY;YACd,CAAC,CAAC,eAAe;gBACf,CAAC,CAAC,eAAe;gBACjB,CAAC,CAAC,IAAI,CAAC;IAEf,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,MAAM,IAAI,KAAK,CACb,uBAAuB;YACrB,IAAI,CAAC,SAAS,CACZ;gBACE,cAAc;gBACd,eAAe;gBACf,eAAe;aAChB,EACD,IAAI,EACJ,CAAC,CACF,CACJ,CAAC;IACJ,CAAC;IACD,OAAO,OAAO,CAAC;AACjB,CAAC;AA1CD,4FA0CC"}
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
import { exec } from "child-process-promise";
|
|
2
|
-
import type Vorpal from "vorpal";
|
|
3
|
-
import {
|
|
4
|
-
getEnvironment,
|
|
5
|
-
parseChoice,
|
|
6
|
-
} from "../../../../config/getProjectConfig";
|
|
7
|
-
import { logError } from "../../../../utils/log";
|
|
8
|
-
|
|
9
|
-
import { envAndComponents } from "./utils/autocompletions";
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Error: rendered manifests contain a resource that already exists.
|
|
13
|
-
* Unable to continue with install: ConfigMap "web-app-env" in namespace "pvl-bike2school-dev" exists and cannot be imported into the current release: invalid ownership metadata; label validation error: missing key "app.kubernetes.io/managed-by": must be set to "Helm"; annotation validation error: missing key "meta.helm.sh/release-name": must be set to "pvl-bike2school-dev-web"; annotation validation error: missing key "meta.helm.sh/release-namespace": must be set to "pvl-bike2school-dev"
|
|
14
|
-
*/
|
|
15
|
-
export default async (vorpal: Vorpal) =>
|
|
16
|
-
vorpal
|
|
17
|
-
.command(
|
|
18
|
-
"project-migrate-helm3 <envComponent>",
|
|
19
|
-
"Do manual step for helm2 to helm3 migration",
|
|
20
|
-
)
|
|
21
|
-
.autocomplete(
|
|
22
|
-
(await envAndComponents()).filter(
|
|
23
|
-
(e) => !e.startsWith("local") && !e.startsWith("review"),
|
|
24
|
-
),
|
|
25
|
-
)
|
|
26
|
-
.action(async function ({ envComponent }) {
|
|
27
|
-
try {
|
|
28
|
-
const { env, componentName } = parseChoice(envComponent);
|
|
29
|
-
const result = await exec("helm version --short");
|
|
30
|
-
const version = result.stdout as string;
|
|
31
|
-
this.log(`your helm version: ${version}`);
|
|
32
|
-
if (!version.startsWith("v3")) {
|
|
33
|
-
throw new Error("no helm3");
|
|
34
|
-
}
|
|
35
|
-
try {
|
|
36
|
-
await exec(
|
|
37
|
-
"helm plugin install https://github.com/helm/helm-2to3.git",
|
|
38
|
-
);
|
|
39
|
-
this.log(
|
|
40
|
-
"successfully installed plugin https://github.com/helm/helm-2to3.git",
|
|
41
|
-
);
|
|
42
|
-
} catch (e) {
|
|
43
|
-
// ignore
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
// we use the app full name as the release name
|
|
47
|
-
const releaseName = (await getEnvironment(env, componentName)).fullName;
|
|
48
|
-
|
|
49
|
-
this.log(`helm release name: ${releaseName}`);
|
|
50
|
-
this.log("");
|
|
51
|
-
this.log("migrating now... 😼. This may take a moment");
|
|
52
|
-
this.log("");
|
|
53
|
-
const r = await exec(
|
|
54
|
-
`helm 2to3 convert --delete-v2-releases ${releaseName}`,
|
|
55
|
-
);
|
|
56
|
-
this.log(r);
|
|
57
|
-
} catch (e) {
|
|
58
|
-
logError(this, e.message);
|
|
59
|
-
this.log("make sure that you have installed latest helm3 locally");
|
|
60
|
-
this.log("(e.g. brew upgrade helm)");
|
|
61
|
-
this.log("");
|
|
62
|
-
}
|
|
63
|
-
});
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import open from "open";
|
|
2
|
-
import type Vorpal from "vorpal";
|
|
3
|
-
import {
|
|
4
|
-
GRAFANA_PROXY_LOCAL_PORT,
|
|
5
|
-
GRAFANA_PROXY_TARGET_PORT,
|
|
6
|
-
} from "../../../../config/constants";
|
|
7
|
-
|
|
8
|
-
import { startKubePortForward } from "../../../../kubernetes/portForward";
|
|
9
|
-
|
|
10
|
-
import { getProjectNamespace } from "../../../../utils/projects";
|
|
11
|
-
|
|
12
|
-
import { envAndComponents } from "./utils/autocompletions";
|
|
13
|
-
import ensureCluster from "./utils/ensureCluster";
|
|
14
|
-
export default async (vorpal: Vorpal) =>
|
|
15
|
-
vorpal
|
|
16
|
-
.command(
|
|
17
|
-
"project-check-costs <envComponent>",
|
|
18
|
-
"Shows you how much you're spending",
|
|
19
|
-
)
|
|
20
|
-
.autocomplete(await envAndComponents())
|
|
21
|
-
.action(async function ({ envComponent }) {
|
|
22
|
-
await ensureCluster.call(this, envComponent);
|
|
23
|
-
const namespace = await getProjectNamespace(envComponent);
|
|
24
|
-
const url = `http://localhost:${GRAFANA_PROXY_LOCAL_PORT}/namespace.html?name=${namespace}`;
|
|
25
|
-
await startKubePortForward(
|
|
26
|
-
"deployment/kubecost-cost-analyzer",
|
|
27
|
-
GRAFANA_PROXY_LOCAL_PORT,
|
|
28
|
-
GRAFANA_PROXY_TARGET_PORT,
|
|
29
|
-
"kubecost",
|
|
30
|
-
);
|
|
31
|
-
open(url);
|
|
32
|
-
});
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { isOfDeployType } from "@catladder/pipeline";
|
|
2
|
-
import type Vorpal from "vorpal";
|
|
3
|
-
import {
|
|
4
|
-
getPipelineContextByChoice,
|
|
5
|
-
parseChoice,
|
|
6
|
-
} from "../../../../config/getProjectConfig";
|
|
7
|
-
import { openGoogleCloudRunDashboard } from "../../../../gcloud/cloudRun/openCloudRunDashboards";
|
|
8
|
-
import { openGoogleCloudKubernetesDashboard } from "../../../../kubernetes/openKubernetesDashboards";
|
|
9
|
-
|
|
10
|
-
import { envAndComponents } from "./utils/autocompletions";
|
|
11
|
-
|
|
12
|
-
export default async (vorpal: Vorpal) =>
|
|
13
|
-
vorpal
|
|
14
|
-
.command(
|
|
15
|
-
"project-open-dashboard <envComponent>",
|
|
16
|
-
"open an apps dashboard (kubernetes or cloudrun)",
|
|
17
|
-
)
|
|
18
|
-
.autocomplete(await envAndComponents())
|
|
19
|
-
.action(async function ({ envComponent }) {
|
|
20
|
-
const { env, componentName } = parseChoice(envComponent);
|
|
21
|
-
const context = await getPipelineContextByChoice(env, componentName);
|
|
22
|
-
if (isOfDeployType(context.deploy?.config, "kubernetes")) {
|
|
23
|
-
await openGoogleCloudKubernetesDashboard(this, context);
|
|
24
|
-
}
|
|
25
|
-
if (isOfDeployType(context.deploy?.config, "google-cloudrun")) {
|
|
26
|
-
await openGoogleCloudRunDashboard(this, context);
|
|
27
|
-
}
|
|
28
|
-
});
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { getGitRemoteHostAndPath } from "./getGitRemoteHostAndPath";
|
|
2
|
-
import { getProjectRootPath } from "./getProjectRootPath";
|
|
3
|
-
|
|
4
|
-
export const getGitConfigVars = async () => {
|
|
5
|
-
const [{ gitRemoteHost: GIT_REMOTE_HOST }, PROJECT_ROOT_PATH] =
|
|
6
|
-
await Promise.all([getGitRemoteHostAndPath(), getProjectRootPath()]);
|
|
7
|
-
return {
|
|
8
|
-
PROJECT_ROOT_PATH,
|
|
9
|
-
GIT_REMOTE_HOST,
|
|
10
|
-
};
|
|
11
|
-
};
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { gitConfigGet } from "./gitConfig";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Gets the git remote host and path from cat-cli config or else from the git config.
|
|
5
|
-
*
|
|
6
|
-
* Writes the values to the cat-cli config file.
|
|
7
|
-
*/
|
|
8
|
-
export async function getGitRemoteHostAndPath(): Promise<{
|
|
9
|
-
gitRemoteHost: string;
|
|
10
|
-
gitRemotePath: string;
|
|
11
|
-
}> {
|
|
12
|
-
const gitRemoteOriginUrl = await gitConfigGet("remote.origin.url");
|
|
13
|
-
const match = gitRemoteOriginUrl.match(
|
|
14
|
-
/(https:\/\/|git@)([^:/]+)[:/]([^.]*)(\.git)?/,
|
|
15
|
-
);
|
|
16
|
-
if (!match || !match.length) {
|
|
17
|
-
throw new Error(
|
|
18
|
-
`Could not find gitlab instance url from git! ${gitRemoteOriginUrl}`,
|
|
19
|
-
);
|
|
20
|
-
}
|
|
21
|
-
const [, , gitRemoteHost, gitRemotePath] = match;
|
|
22
|
-
if (!gitRemoteHost?.length || !gitRemotePath?.length) {
|
|
23
|
-
throw new Error(
|
|
24
|
-
`Could not get gitlab hostname and project path from git config! ${gitRemoteOriginUrl}`,
|
|
25
|
-
);
|
|
26
|
-
}
|
|
27
|
-
return { gitRemoteHost, gitRemotePath };
|
|
28
|
-
}
|
package/src/git/gitConfig.ts
DELETED
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
import { exec } from "child-process-promise";
|
|
2
|
-
|
|
3
|
-
const scopes = ["global", "local", "system", "worktree"] as const;
|
|
4
|
-
type LocationScope = (typeof scopes)[number];
|
|
5
|
-
|
|
6
|
-
type LocationOption = {
|
|
7
|
-
location?: LocationScope;
|
|
8
|
-
};
|
|
9
|
-
|
|
10
|
-
export async function gitConfigGet(key: string, options: LocationOption = {}) {
|
|
11
|
-
const optArgs = [options.location ? `--${options.location}` : undefined]
|
|
12
|
-
.filter(Boolean)
|
|
13
|
-
.join(" ");
|
|
14
|
-
const execResult = await exec(`git config get ${optArgs} ${key}`);
|
|
15
|
-
return execResult.stdout.trim();
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
type CommentOption = { comment?: string };
|
|
19
|
-
|
|
20
|
-
export function gitConfigSet(
|
|
21
|
-
key: string,
|
|
22
|
-
value: string,
|
|
23
|
-
options: LocationOption & CommentOption = {},
|
|
24
|
-
) {
|
|
25
|
-
const optArgs = [
|
|
26
|
-
options.location ? `--${options.location}` : undefined,
|
|
27
|
-
options.comment ? `--comment=${options.comment}` : undefined,
|
|
28
|
-
]
|
|
29
|
-
.filter(Boolean)
|
|
30
|
-
.join(" ");
|
|
31
|
-
return exec(`git config set ${optArgs} ${key} ${value}`);
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
const reduceScopelessConfigList = (configList: string[]) =>
|
|
35
|
-
configList.reduce(
|
|
36
|
-
(acc, line) => {
|
|
37
|
-
const [key, value] = line.split("=");
|
|
38
|
-
if (!key?.length) {
|
|
39
|
-
return acc;
|
|
40
|
-
}
|
|
41
|
-
return { ...acc, [key]: value };
|
|
42
|
-
},
|
|
43
|
-
{} as Record<string, string>,
|
|
44
|
-
);
|
|
45
|
-
|
|
46
|
-
type ByScope = { [scope in LocationScope]?: Record<string, string> };
|
|
47
|
-
|
|
48
|
-
const reduceScopedConfigList = (configList: string[]) =>
|
|
49
|
-
configList.reduce((acc, line) => {
|
|
50
|
-
const [scopeSplit, key_val] = line.split("\t");
|
|
51
|
-
const scope = scopeSplit.trim() as LocationScope;
|
|
52
|
-
if (!key_val?.length || !scope?.length) {
|
|
53
|
-
return acc;
|
|
54
|
-
}
|
|
55
|
-
const [key, value] = key_val.split("=");
|
|
56
|
-
if (!key?.length) {
|
|
57
|
-
return acc;
|
|
58
|
-
}
|
|
59
|
-
acc[scope] = acc[scope] || {};
|
|
60
|
-
acc[scope][key] = value;
|
|
61
|
-
return acc;
|
|
62
|
-
}, {} as ByScope);
|
|
63
|
-
|
|
64
|
-
export async function gitConfigList({
|
|
65
|
-
byScope = false,
|
|
66
|
-
location,
|
|
67
|
-
}: {
|
|
68
|
-
/**
|
|
69
|
-
* Returns the config values by location scope.
|
|
70
|
-
* Only has an effect if the location is set.
|
|
71
|
-
*/
|
|
72
|
-
byScope?: boolean;
|
|
73
|
-
} & LocationOption = {}): Promise<Record<string, string> | ByScope> {
|
|
74
|
-
const showScope = !location && byScope;
|
|
75
|
-
const optArgs = [
|
|
76
|
-
location ? `--${location}` : undefined,
|
|
77
|
-
showScope ? "--show-scope" : undefined,
|
|
78
|
-
]
|
|
79
|
-
.filter(Boolean)
|
|
80
|
-
.join(" ");
|
|
81
|
-
const configListOutput = await exec(`git config list ${optArgs}`);
|
|
82
|
-
const configList = configListOutput.stdout.trim().split("\n");
|
|
83
|
-
return showScope
|
|
84
|
-
? reduceScopedConfigList(configList)
|
|
85
|
-
: reduceScopelessConfigList(configList);
|
|
86
|
-
}
|
package/src/git/index.ts
DELETED
package/src/gitlab/apiClient.ts
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { Gitlab } from "@gitbeaker/rest";
|
|
2
|
-
import { getGitlabToken } from "./gitlabToken";
|
|
3
|
-
|
|
4
|
-
export type GitlabRestClient = InstanceType<typeof Gitlab<false>>;
|
|
5
|
-
|
|
6
|
-
export const gitlabApiClient = async ({
|
|
7
|
-
gitlabHost,
|
|
8
|
-
}: {
|
|
9
|
-
gitlabHost?: string;
|
|
10
|
-
} = {}): Promise<GitlabRestClient> => {
|
|
11
|
-
const { token, gitRemoteHost } = await getGitlabToken(gitlabHost);
|
|
12
|
-
if (typeof token !== "string") {
|
|
13
|
-
throw new Error("Gitlab personal access token is missing!");
|
|
14
|
-
}
|
|
15
|
-
if (!gitRemoteHost) {
|
|
16
|
-
throw new Error("no gitlab host found");
|
|
17
|
-
}
|
|
18
|
-
return new Gitlab({
|
|
19
|
-
token,
|
|
20
|
-
host: `https://${gitRemoteHost}`,
|
|
21
|
-
camelize: false,
|
|
22
|
-
});
|
|
23
|
-
};
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import type { ProjectSchema } from "@gitbeaker/rest";
|
|
2
|
-
import { getGitRemoteHostAndPath } from "../git/getGitRemoteHostAndPath";
|
|
3
|
-
import type { GitlabRestClient } from "./apiClient";
|
|
4
|
-
import { gitlabApiClient } from "./apiClient";
|
|
5
|
-
import {
|
|
6
|
-
upsertProjectPerferences,
|
|
7
|
-
getProjectPreferences,
|
|
8
|
-
} from "../utils/projectPreferences";
|
|
9
|
-
|
|
10
|
-
export const getGitlabProjectInfo = async (
|
|
11
|
-
existingInstance?: GitlabRestClient,
|
|
12
|
-
): Promise<ProjectSchema> => {
|
|
13
|
-
const api = existingInstance ?? (await gitlabApiClient());
|
|
14
|
-
const { gitRemotePath } = await getGitRemoteHostAndPath();
|
|
15
|
-
const projectInfo = await api.Projects.show(gitRemotePath, {
|
|
16
|
-
statistics: false,
|
|
17
|
-
withCustomAttributes: false,
|
|
18
|
-
license: false,
|
|
19
|
-
});
|
|
20
|
-
// write unawaited intentionally
|
|
21
|
-
upsertProjectPerferences({ gitlabProjectId: projectInfo.id });
|
|
22
|
-
return projectInfo;
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
export const getGitlabProjectId = async (): Promise<number> => {
|
|
26
|
-
const { gitlabProjectId } = await getProjectPreferences();
|
|
27
|
-
if (gitlabProjectId) {
|
|
28
|
-
return gitlabProjectId;
|
|
29
|
-
}
|
|
30
|
-
const projectInfo = await getGitlabProjectInfo();
|
|
31
|
-
return projectInfo.id;
|
|
32
|
-
};
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
import { getGitRemoteHostAndPath } from "../git";
|
|
2
|
-
import {
|
|
3
|
-
getPreference,
|
|
4
|
-
getPreferences,
|
|
5
|
-
setPreference,
|
|
6
|
-
} from "../utils/preferences";
|
|
7
|
-
|
|
8
|
-
export async function getGitlabToken(hostname?: string) {
|
|
9
|
-
const [{ gitRemoteHost }, preferences] = await Promise.all([
|
|
10
|
-
hostname?.length
|
|
11
|
-
? Promise.resolve({ gitRemoteHost: hostname })
|
|
12
|
-
: getGitRemoteHostAndPath(),
|
|
13
|
-
getPreferences(),
|
|
14
|
-
]);
|
|
15
|
-
const gitlabTokens = preferences.gitlabTokens ?? {};
|
|
16
|
-
const currentPerferencesToken = gitlabTokens[gitRemoteHost];
|
|
17
|
-
const token =
|
|
18
|
-
currentPerferencesToken ??
|
|
19
|
-
preferences["gitlab-personal-access-token"] ??
|
|
20
|
-
process.env.GITLAB_TOKEN;
|
|
21
|
-
if (
|
|
22
|
-
(preferences["gitlab-personal-access-token"]?.length ||
|
|
23
|
-
process.env.GITLAB_TOKEN?.length) &&
|
|
24
|
-
!currentPerferencesToken?.length
|
|
25
|
-
) {
|
|
26
|
-
await setGitlabToken(token, {
|
|
27
|
-
hostname: gitRemoteHost,
|
|
28
|
-
currentTokens: gitlabTokens,
|
|
29
|
-
});
|
|
30
|
-
}
|
|
31
|
-
return { token, gitRemoteHost };
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
export async function setGitlabToken(
|
|
35
|
-
token: string,
|
|
36
|
-
{
|
|
37
|
-
hostname,
|
|
38
|
-
currentTokens,
|
|
39
|
-
}: { hostname?: string; currentTokens?: { [host in string]?: string } } = {},
|
|
40
|
-
) {
|
|
41
|
-
const [{ gitRemoteHost }, storedTokens] = await Promise.all([
|
|
42
|
-
hostname?.length
|
|
43
|
-
? Promise.resolve({ gitRemoteHost: hostname })
|
|
44
|
-
: getGitRemoteHostAndPath(),
|
|
45
|
-
currentTokens
|
|
46
|
-
? Promise.resolve(currentTokens)
|
|
47
|
-
: getPreference("gitlabTokens"),
|
|
48
|
-
]);
|
|
49
|
-
const gitlabTokens = { ...(storedTokens ?? {}), [gitRemoteHost]: token };
|
|
50
|
-
await setPreference("gitlabTokens", gitlabTokens);
|
|
51
|
-
return gitlabTokens[gitRemoteHost];
|
|
52
|
-
}
|
package/src/gitlab/index.ts
DELETED
package/src/utils/preferences.ts
DELETED
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
import { writeFile, readFile, mkdir } from "fs/promises";
|
|
2
|
-
import { existsSync } from "fs";
|
|
3
|
-
import { homedir } from "os";
|
|
4
|
-
import { parse, stringify } from "yaml";
|
|
5
|
-
import { join } from "path";
|
|
6
|
-
|
|
7
|
-
const directory = join(homedir(), ".catladder");
|
|
8
|
-
const file = join(directory, "preferences.yml");
|
|
9
|
-
|
|
10
|
-
export type CatladderCliPreferences = {
|
|
11
|
-
"gitlab-personal-access-token": string | null;
|
|
12
|
-
googleAuthUserNumber: number | null;
|
|
13
|
-
gitlabTokens: { [hostname in string]?: string };
|
|
14
|
-
};
|
|
15
|
-
type PreferenceKey = keyof CatladderCliPreferences;
|
|
16
|
-
const perfKeys = [
|
|
17
|
-
"gitlab-personal-access-token",
|
|
18
|
-
"googleAuthUserNumber",
|
|
19
|
-
"gitlabTokens",
|
|
20
|
-
] as const satisfies readonly PreferenceKey[];
|
|
21
|
-
|
|
22
|
-
const fallbackValues = {
|
|
23
|
-
"gitlab-personal-access-token": null,
|
|
24
|
-
gitlabTokens: {},
|
|
25
|
-
googleAuthUserNumber: null,
|
|
26
|
-
} satisfies CatladderCliPreferences;
|
|
27
|
-
|
|
28
|
-
const perferencesWithParsed = (
|
|
29
|
-
parsed: Partial<CatladderCliPreferences>,
|
|
30
|
-
): CatladderCliPreferences =>
|
|
31
|
-
perfKeys.reduce(
|
|
32
|
-
(acc, key) =>
|
|
33
|
-
Object.assign(acc, { [key]: parsed[key] ?? fallbackValues[key] }),
|
|
34
|
-
{} as CatladderCliPreferences,
|
|
35
|
-
);
|
|
36
|
-
|
|
37
|
-
const encoding = "utf-8";
|
|
38
|
-
|
|
39
|
-
const readPreferences = () => readFile(file, { encoding });
|
|
40
|
-
|
|
41
|
-
const writePreferences = (preferences: CatladderCliPreferences) =>
|
|
42
|
-
writeFile(file, stringify(preferences), { encoding, mode: 0o600 });
|
|
43
|
-
|
|
44
|
-
const ensureDir = async () =>
|
|
45
|
-
existsSync(directory)
|
|
46
|
-
? directory
|
|
47
|
-
: mkdir(directory, { recursive: true, mode: 0o700 });
|
|
48
|
-
|
|
49
|
-
const ensureFile = async () => {
|
|
50
|
-
if (existsSync(file)) {
|
|
51
|
-
return file;
|
|
52
|
-
}
|
|
53
|
-
await ensureDir();
|
|
54
|
-
return writePreferences(perferencesWithParsed({}));
|
|
55
|
-
};
|
|
56
|
-
|
|
57
|
-
export const getPreferences = async (): Promise<CatladderCliPreferences> => {
|
|
58
|
-
await ensureFile();
|
|
59
|
-
const fileString = await readPreferences();
|
|
60
|
-
const fileParsed = parse(fileString || "---\nnull") ?? {};
|
|
61
|
-
return perferencesWithParsed(fileParsed);
|
|
62
|
-
};
|
|
63
|
-
|
|
64
|
-
export const hasPreference = async (key: PreferenceKey) => {
|
|
65
|
-
const preferences = await getPreferences();
|
|
66
|
-
return preferences[key] !== null && preferences[key] !== undefined;
|
|
67
|
-
};
|
|
68
|
-
|
|
69
|
-
export const getPreference = async <K extends PreferenceKey>(
|
|
70
|
-
key: K,
|
|
71
|
-
): Promise<CatladderCliPreferences[K] | null> => {
|
|
72
|
-
const preferences = await getPreferences();
|
|
73
|
-
if (key in preferences) {
|
|
74
|
-
return preferences[key] as CatladderCliPreferences[K];
|
|
75
|
-
}
|
|
76
|
-
return null;
|
|
77
|
-
};
|
|
78
|
-
|
|
79
|
-
export const setPreference = async (
|
|
80
|
-
key: PreferenceKey,
|
|
81
|
-
value: CatladderCliPreferences[typeof key],
|
|
82
|
-
) => {
|
|
83
|
-
const preferences = await getPreferences();
|
|
84
|
-
return writePreferences({ ...preferences, [key]: value });
|
|
85
|
-
};
|