UNPKG

@atomist/atomist-sdm

Version:

Atomist SDM to deliver our own projects

155 lines 5.48 kB
"use strict"; /* * Copyright © 2019 Atomist, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); const automation_client_1 = require("@atomist/automation-client"); const sdm_1 = require("@atomist/sdm"); const sdm_pack_node_1 = require("@atomist/sdm-pack-node"); const sdm_pack_spring_1 = require("@atomist/sdm-pack-spring"); exports.kubernetesDeployRegistrationProd = { name: "@atomist/k8s-sdm_gke-int-production", applicationData: kubernetesApplicationData, }; exports.kubernetesDeployRegistrationGlobal = { name: "@atomist/k8s-sdm_gke-customer-global", applicationData: kubernetesApplicationData, }; exports.kubernetesDeployRegistrationDemo = { name: "@atomist/k8s-sdm_gke-int-demo", applicationData: kubernetesApplicationData, }; /** * Augment default Kubernetes application object with specifics for * the provided deploy goal event. */ function kubernetesApplicationData(app, p, goal, goalEvent) { return __awaiter(this, void 0, void 0, function* () { const name = goalEvent.repo.name; const ns = namespaceFromGoal(goalEvent); let port; if (yield sdm_pack_spring_1.IsMaven.predicate(p)) { port = 8080; } else if (yield sdm_pack_node_1.IsAtomistAutomationClient.predicate(p)) { port = 2866; } let replicas = 1; if (ns === "production") { replicas = 3; } else if (ns === "sdm" && (name === "atomist-sdm" || name === "global-sdm")) { replicas = 3; } const ingress = ingressFromGoal(name, ns); const baseApp = Object.assign({}, app, { name, ns, port, replicas }, ingress); return baseApp; }); } exports.kubernetesApplicationData = kubernetesApplicationData; /** * Determine deploy namespace from goal event. * * @param goalEvent SDM goal event for this deploy. * @return Namespace to deploy this app to. */ function namespaceFromGoal(goalEvent) { const name = goalEvent.repo.name; if (name === "atomist-internal-sdm" || name === "global-sdm") { if (goalEvent.environment === sdm_1.StagingEnvironment.replace(/\/$/, "")) { return "sdm-testing"; } else if (goalEvent.environment === sdm_1.ProductionEnvironment.replace(/\/$/, "")) { return "sdm"; } } else if (/-sdm$/.test(name) && name !== "sample-sdm" && name !== "spring-sdm") { return "sdm"; } else if (name === "k8vent") { return "k8vent"; } else if (goalEvent.environment === sdm_1.StagingEnvironment.replace(/\/$/, "")) { return "testing"; } else if (goalEvent.environment === sdm_1.ProductionEnvironment.replace(/\/$/, "")) { return "production"; } automation_client_1.logger.debug(`Unmatched goal.environment using default namespace: ${goalEvent.environment}`); return "default"; } /** * Determine if this deploy requires an ingress, returning it if is * does. * * @param repo Name of repository. * @param ns Kubernetes namespace where app will be deployed. * @return Object with ingress-related properties of KubernetesApplication populated or `undefined`. */ function ingressFromGoal(repo, ns) { let host; let path; const ingressSpec = { metadata: { annotations: { "kubernetes.io/ingress.class": "nginx", "nginx.ingress.kubernetes.io/client-body-buffer-size": "1m", }, }, }; const tail = (ns === "production") ? "com" : "services"; if (repo === "card-automation") { host = "pusher"; path = "/"; } else if (repo === "sdm-automation") { host = "badge"; path = "/"; } else if (repo === "intercom-automation") { host = "intercom"; path = "/"; } else if (repo === "rolar") { host = "rolar"; path = "/"; } else if (repo === "org-visualizer") { host = "visualizer"; path = "/"; } else { return undefined; } return { host: `${host}.atomist.${tail}`, ingressSpec, path, tlsSecret: `star-atomist-${tail}`, }; } exports.ingressFromGoal = ingressFromGoal; //# sourceMappingURL=k8sSupport.js.map