@topgroup/diginext
Version:
A BUILD SERVER & CLI to deploy apps to any Kubernetes clusters.
79 lines (78 loc) • 3.83 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.execBuild = void 0;
const log_1 = require("diginext-utils/dist/xconsole/log");
const inquirer_1 = __importDefault(require("inquirer"));
const lodash_1 = require("lodash");
const slug_1 = require("../../plugins/slug");
const utils_1 = require("../../plugins/utils");
const app_helper_1 = require("../apps/app-helper");
const ask_project_and_app_1 = require("../apps/ask-project-and-app");
const update_config_1 = require("../apps/update-config");
const ask_for_domain_1 = require("./ask-for-domain");
const start_build_1 = require("./start-build");
/**
* This command allow you to build & deploy your application directly from your machine, without requesting to the build server.
* Notes that it could lead to platform conflicts if your machine & your cluster are running different OS.
* @deprecated
*/
async function execBuild(options) {
if (typeof options.targetDirectory == "undefined")
options.targetDirectory = process.cwd();
const { env = "dev", targetDirectory, author } = options;
let { app } = await (0, ask_project_and_app_1.askForProjectAndApp)(options.targetDirectory, options);
let appConfig = (0, app_helper_1.getAppConfigFromApp)(app);
const { project, slug } = appConfig;
const deployEnvironment = appConfig.deployEnvironment[env];
// check Dockerfile
let dockerFile = (0, utils_1.resolveDockerfilePath)({ targetDirectory, env });
if (!dockerFile)
return;
let domains, selectedSSL = "letsencrypt", selectedSecretName;
// ask for generated domains:
try {
domains = await (0, ask_for_domain_1.askForDomain)(env, project, slug, deployEnvironment, { user: author });
}
catch (e) {
(0, log_1.logError)(`[EXEC_BUILD] ${e}`);
return;
}
if ((0, lodash_1.isEmpty)(domains)) {
domains = [];
(0, log_1.logWarn)(`This app doesn't have any domains configurated & only visible to the namespace scope, you can add your own domain to app config in Diginext workspace to expose this app to the internet anytime.`);
}
appConfig.deployEnvironment[env].domains = domains;
// if they have any domains, ask if they want to use "letsencrypt":
if (appConfig.deployEnvironment[env].domains.length > 0 && !appConfig.deployEnvironment[env].ssl) {
const askSSL = await inquirer_1.default.prompt({
type: "list",
name: "selectedSSL",
message: `Which SSL certificate do you want to use for these domains?`,
default: "letsencrypt",
choices: ["letsencrypt", "custom", "none"],
});
selectedSSL = askSSL.selectedSSL;
}
selectedSecretName = `tls-secret-${selectedSSL}-${(0, slug_1.makeSlug)(appConfig.deployEnvironment[env].domains[0])}`;
// if they select "custom" SSL certificate -> ask for secret name:
if (selectedSSL == "custom") {
const askSecretName = await inquirer_1.default.prompt({
type: "input",
name: "secretName",
message: `Name your custom SSL secret (ENTER to use default):`,
default: selectedSecretName,
});
selectedSecretName = askSecretName.secretName;
}
appConfig.deployEnvironment[env].ssl = selectedSSL;
appConfig.deployEnvironment[env].tlsSecret = selectedSecretName;
// save domains & SSL configs
appConfig = await (0, update_config_1.updateAppConfig)(app, env, appConfig.deployEnvironment[env]);
// request build server to build & deploy:
const buildStatus = await (0, start_build_1.startBuildV1)(options);
return buildStatus;
}
exports.execBuild = execBuild;