@topgroup/diginext
Version:
A BUILD SERVER & CLI to deploy apps to any Kubernetes clusters.
139 lines (138 loc) • 6.3 kB
JavaScript
;
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.installCertManagerStack = exports.installNginxIngressStack = void 0;
const fs_1 = require("fs");
const path_1 = __importDefault(require("path"));
const const_1 = require("../../config/const");
const plugins_1 = require("../../plugins");
const index_1 = __importDefault(require("./index"));
const stack_check_1 = require("./stack-check");
/**
* Install `NGINX Ingress` stack to your cluster
* @copyright https://kubernetes.github.io/ingress-nginx/
*/
const installNginxIngressStack = async (cluster, options = {}) => {
const { execa, execaCommand, execaSync, execaCommandSync } = await Promise.resolve().then(() => __importStar(require("execa")));
const { slug, contextName: context, isVerified } = cluster;
const { onUpdate } = options;
if (!isVerified)
throw new Error(`Cluster (${slug}) hasn't been verified yet.`);
let nginxIngressInstalled = await (0, stack_check_1.checkNginxIngressInstalled)(cluster);
if (nginxIngressInstalled) {
if (!(options === null || options === void 0 ? void 0 : options.skipable))
throw new Error(`Cluster already had "NGINX Ingress" Stack installed.`);
return true;
}
// use Helm to install:
const name = "ingress-nginx";
const namespace = "ingress-nginx";
const helmRepoURL = "https://kubernetes.github.io/ingress-nginx";
const command = `helm upgrade --install ${name} ${name} --repo ${helmRepoURL} --namespace ${namespace} --create-namespace`;
const stream = execaCommand(command);
stream.stdio.forEach((_stdio) => {
if (_stdio) {
_stdio.on("data", (data) => {
if (onUpdate)
onUpdate(data.toString(), "log");
});
}
});
await stream;
// verify the installation: Pending, Running, Succeeded, Failed, Unknown
await (0, plugins_1.waitUntil)(async () => {
let isStackFinished = false;
const pods = await index_1.default.getPodsByFilter(namespace);
pods.map((pod) => {
if (pod.status.phase !== "Pending")
isStackFinished = true;
if (pod.status.phase === "Running" || pod.status.phase === "Succeeded")
nginxIngressInstalled = true;
});
return isStackFinished;
});
return nginxIngressInstalled;
};
exports.installNginxIngressStack = installNginxIngressStack;
/**
* Install `CertManager` stack to your cluster
* @copyright https://cert-manager.io/
*/
const installCertManagerStack = async (cluster, options = {}) => {
const { execa, execaCommand, execaSync, execaCommandSync } = await Promise.resolve().then(() => __importStar(require("execa")));
const { slug, contextName: context, isVerified } = cluster;
const { onUpdate } = options;
if (!isVerified)
throw new Error(`Cluster (${slug}) hasn't been verified yet.`);
// check stack has been installed yet or not
let isStackInstalled = await (0, stack_check_1.checkCertManagerInstalled)(cluster);
if (isStackInstalled) {
if (!(options === null || options === void 0 ? void 0 : options.skipable))
throw new Error(`Cluster already had "CertManager" Stack installed.`);
return true;
}
// add Helm repo
await execaCommand(`helm repo add jetstack https://charts.jetstack.io && helm repo update`);
// use Helm to install:
const name = "cert-manager";
const namespace = "cert-manager";
const version = "v1.11.0";
const command = `helm install ${name} jetstack/cert-manager --namespace ${namespace} --create-namespace --version ${version} --set installCRDs=true`;
const stream = execaCommand(command);
stream.stdio.forEach((_stdio) => {
if (_stdio) {
_stdio.on("data", (data) => {
if (onUpdate)
onUpdate(data.toString(), "log");
});
}
});
await stream;
// verify the installation:
await (0, plugins_1.waitUntil)(async () => {
let isStackFinished = false;
const pods = await index_1.default.getPodsByFilter(namespace);
pods.map((pod) => {
if (pod.status.phase !== "Pending")
isStackFinished = true;
if (pod.status.phase === "Running" || pod.status.phase === "Succeeded")
isStackInstalled = true;
});
return isStackFinished;
});
// create default "ClusterIssuer" for issuing Let's Encrypt SSL certificates
if (isStackInstalled) {
const clusterIssuerTemplateFile = path_1.default.resolve(const_1.CLI_DIR, "templates/cert-manager/cluster-issuer.yaml");
if (!(0, fs_1.existsSync)(clusterIssuerTemplateFile))
throw new Error(`[CERT MANAGER] ClusterIssuer template not found.`);
const clusterIssuerDeploy = await index_1.default.kubectlApply(clusterIssuerTemplateFile, { context });
console.log("clusterIssuerDeploy :>> ", clusterIssuerDeploy);
}
return isStackInstalled;
};
exports.installCertManagerStack = installCertManagerStack;