@topgroup/diginext
Version:
A BUILD SERVER & CLI to deploy apps to any Kubernetes clusters.
117 lines (116 loc) • 4.16 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.execConfig = exports.saveCliConfig = exports.getCliConfig = exports.getContainerResourceBySize = exports.containerResources = exports.getContainerResource = exports.containerMemories = exports.containerCpus = exports.cliOpts = void 0;
const log_1 = require("diginext-utils/dist/xconsole/log");
const fs_1 = require("fs");
const app_config_1 = require("../app.config");
const plugins_1 = require("../plugins");
const const_1 = require("./const");
// export const cliOpts: execa.Options = isWin() ? {} : { shell: "bash" };
exports.cliOpts = {};
const originalCPU = 50;
const originalMemory = 128;
exports.containerCpus = ["50m", "100m", "200m", "400m", "600m", "1000m", "2000m", "4000m", "8000m", "16000m"];
exports.containerMemories = ["128Mi", "256Mi", "512Mi", "1024Mi", "2048Mi", "4096Mi", "8192Mi", "16384Mi", "32768Mi", "65536Mi"];
function getContainerResource(cpu, memory) {
const resource = {
requests: { cpu, memory },
limits: { cpu, memory },
};
return resource;
}
exports.getContainerResource = getContainerResource;
exports.containerResources = {
none: {
requests: { cpu: null, memory: null },
limits: { cpu: null, memory: null },
},
"1x": {
requests: { cpu: "50m", memory: "128Mi" },
limits: { cpu: "50m", memory: "128Mi" },
},
"2x": {
requests: { cpu: "100m", memory: "256Mi" },
limits: { cpu: "100m", memory: "256Mi" },
},
"3x": {
requests: { cpu: "200m", memory: "512Mi" },
limits: { cpu: "200m", memory: "512Mi" },
},
"4x": {
requests: { cpu: "400m", memory: "1024Mi" },
limits: { cpu: "400m", memory: "1024Mi" },
},
"5x": {
requests: { cpu: "600m", memory: "2048Mi" },
limits: { cpu: "600m", memory: "2048Mi" },
},
"6x": {
requests: { cpu: "1000m", memory: "4096Mi" },
limits: { cpu: "1000m", memory: "4096Mi" },
},
"7x": {
requests: { cpu: "2000m", memory: "8192Mi" },
limits: { cpu: "2000m", memory: "8192Mi" },
},
"8x": {
requests: { cpu: "4000m", memory: "16384Mi" },
limits: { cpu: "4000m", memory: "16384Mi" },
},
"9x": {
requests: { cpu: "8000m", memory: "32768Mi" },
limits: { cpu: "8000m", memory: "32768Mi" },
},
"10x": {
requests: { cpu: "16000m", memory: "65536Mi" },
limits: { cpu: "16000m", memory: "65536Mi" },
},
};
// function getQuotaByScale(origin: number, scale: number) {
// let result = origin;
// for (let i = 1; i < scale; i++) result *= 2;
// return result;
// }
const getContainerResourceBySize = (size) => {
return exports.containerResources[size];
};
exports.getContainerResourceBySize = getContainerResourceBySize;
/**
* Get local CLI config
*/
const getCliConfig = () => {
// Create new config file if it's not existed
if (!(0, fs_1.existsSync)(const_1.CLI_CONFIG_DIR))
(0, fs_1.mkdirSync)(const_1.CLI_CONFIG_DIR, { recursive: true });
if (!(0, fs_1.existsSync)(const_1.CLI_CONFIG_FILE))
(0, fs_1.writeFileSync)(const_1.CLI_CONFIG_FILE, "{}", "utf8");
const conf = (0, plugins_1.readJson)(const_1.CLI_CONFIG_FILE);
if (!conf.buildServerUrl)
conf.buildServerUrl = app_config_1.Config.BASE_URL;
return conf;
};
exports.getCliConfig = getCliConfig;
/**
* Save/update CLI config locally
* @param {CliConfig} updatedConfig
*/
const saveCliConfig = (updatedConfig) => {
const conf = { ...(0, exports.getCliConfig)(), ...updatedConfig };
return (0, plugins_1.saveJson)(JSON.stringify(conf), const_1.CLI_CONFIG_FILE, { overwrite: true });
};
exports.saveCliConfig = saveCliConfig;
const execConfig = async (options) => {
const conf = (0, exports.getCliConfig)();
(0, log_1.log)(conf);
// const { secondAction, thirdAction } = options;
// switch (secondAction) {
// case "get":
// const conf = getCliConfig();
// log(conf);
// return conf;
// default:
// log(`Huh?`);
// break;
// }
};
exports.execConfig = execConfig;