@catladder/pipeline
Version:
Panter workflow for cloud CI/CD and DevOps
122 lines (121 loc) • 4.32 kB
JavaScript
;
var __assign = this && this.__assign || function () {
__assign = Object.assign || function (t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
var __rest = this && this.__rest || function (s, e) {
var t = {};
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p];
if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]];
}
return t;
};
var __read = this && this.__read || function (o, n) {
var m = typeof Symbol === "function" && o[Symbol.iterator];
if (!m) return o;
var i = m.call(o),
r,
ar = [],
e;
try {
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
} catch (error) {
e = {
error: error
};
} finally {
try {
if (r && !r.done && (m = i["return"])) m.call(i);
} finally {
if (e) throw e.error;
}
}
return ar;
};
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.createKubeValues = void 0;
var lodash_1 = require("lodash");
var utils_1 = require("../../utils");
var types_1 = require("../types");
var cloudSql_1 = require("./cloudSql");
var kubeEnv_1 = require("./kubeEnv");
var mongodb_1 = require("./mongodb");
var createAppConfig = function (context, application) {
if (application === false) {
return {
enabled: false
};
}
var _a = application !== null && application !== void 0 ? application : {},
healthRoute = _a.healthRoute,
command = _a.command,
rest = __rest(_a, ["healthRoute", "command"]);
return (0, utils_1.mergeWithMergingArrays)({
host: context.environment.envVars.HOSTNAME,
command: command !== null && command !== void 0 ? command : context.build.type !== "disabled" ? context.build.config.startCommand : undefined,
livenessProbe: {
httpGet: {
path: healthRoute !== null && healthRoute !== void 0 ? healthRoute : "__health"
}
},
readinessProbe: {
httpGet: {
path: healthRoute !== null && healthRoute !== void 0 ? healthRoute : "__health"
}
},
startupProbe: {
httpGet: {
path: healthRoute !== null && healthRoute !== void 0 ? healthRoute : "__health"
}
}
},
// default
rest);
};
var removeFalsy = function (record) {
if (!record) return undefined;
return Object.fromEntries(Object.entries(record).filter(function (_a) {
var _b = __read(_a, 2),
value = _b[1];
return value !== false;
}));
};
var createKubeValues = function (context) {
var _a, _b, _c;
var deployConfig = (_a = context.deploy) === null || _a === void 0 ? void 0 : _a.config;
if (!deployConfig) {
return [];
}
if (!(0, types_1.isOfDeployType)(deployConfig, "kubernetes")) {
// should not happen
throw new Error("deploy config is not kubernetes");
}
var values = deployConfig.values;
// we remove the application config because it can be just the value `false` which is a convenience feature, but not supported in the helm chart
// we only merge the rest of the values in
var _d = values !== null && values !== void 0 ? values : {},
application = _d.application,
jobs = _d.jobs,
cronjobs = _d.cronjobs,
rest = __rest(_d, ["application", "jobs", "cronjobs"]);
var env = (0, kubeEnv_1.createKubeEnv)(context);
var defaultKubeValues = (0, lodash_1.merge)({
env: env,
application: createAppConfig(context, application)
}, (0, cloudSql_1.hasKubernetesCloudSQL)(context) ? (0, cloudSql_1.createKubernetesCloudsqlBaseValues)(context) : {}, ((_c = (_b = deployConfig.values) === null || _b === void 0 ? void 0 : _b.mongodb) === null || _c === void 0 ? void 0 : _c.enabled) ? (0, mongodb_1.createMongodbBaseConfig)(context) : {});
var kubeValues = (0, utils_1.mergeWithMergingArrays)(defaultKubeValues, __assign({
jobs: removeFalsy(jobs),
cronjobs: removeFalsy(cronjobs)
}, rest));
return kubeValues;
};
exports.createKubeValues = createKubeValues;