UNPKG

@catladder/cli

Version:

Panter cli tool for cloud CI/CD and DevOps

79 lines 3.7 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.createKubernetesDeployJobs = void 0; const getEnvironmentVariables_1 = require("../../context/getEnvironmentVariables"); const runner_1 = require("../../runner"); const base_1 = require("../base"); const sbom_1 = require("../sbom"); const types_1 = require("../types"); const kubeValues_1 = require("./kubeValues"); const bashYaml_1 = require("../../bash/bashYaml"); const gitlab_1 = require("../../utils/gitlab"); const ALL_VALUES_FILE = "__all_values.yml"; const createKubernetesDeployJobs = (context) => { var _a, _b, _c; const deployConfig = (_a = context.deploy) === null || _a === void 0 ? void 0 : _a.config; if (!(0, types_1.isOfDeployType)(deployConfig, "kubernetes")) { // should not happen throw new Error("deploy config is not kubernetes"); } const shared = { image: (0, runner_1.getRunnerImage)("kubernetes"), ...(deployConfig.debug ? { artifacts: { paths: [ ALL_VALUES_FILE, // debug ], when: "always", }, } : {}), variables: { ...context.environment.envVars, RELEASE_NAME: context.environment.fullName, HELM_EXPERIMENTAL_OCI: "1", KUBE_DOCKER_IMAGE_PULL_SECRET: `gitlab-registry-${context.name}`, HELM_GITLAB_CHART_NAME: (_b = deployConfig.chartName) !== null && _b !== void 0 ? _b : "/helm-charts/the-panter-chart", HELM_ARGS: [ ...(deployConfig.debug ? ["--debug"] : []), ...((_c = deployConfig.additionalHelmArgs) !== null && _c !== void 0 ? _c : []), ].join(" "), COMPONENT_NAME: context.name, }, }; const clusterName = `kube-${context.environment.fullName}`; const connectContext = [ `kubectl config set-cluster "${clusterName}" --server="$${(0, getEnvironmentVariables_1.getSecretVarNameForContext)(context, "KUBE_URL")}" --certificate-authority <(echo $${(0, getEnvironmentVariables_1.getSecretVarNameForContext)(context, "KUBE_CA_PEM")} | base64 -d) --embed-certs=true`, `kubectl config set-credentials "${clusterName}" --token="$${(0, getEnvironmentVariables_1.getSecretVarNameForContext)(context, "KUBE_TOKEN")}"`, `kubectl config set-context "${clusterName}" --cluster="${clusterName}" --user="${clusterName}" --namespace="${context.environment.envVars.KUBE_NAMESPACE}"`, `kubectl config use-context "${clusterName}"`, ]; return (0, base_1.createDeployementJobs)(context, { deploy: { ...shared, script: [ ...connectContext, ...(0, gitlab_1.collapseableSection)("writeallvalues", "Write " + ALL_VALUES_FILE + " for helm deployment")((0, bashYaml_1.writeBashYamlToFileScript)((0, kubeValues_1.createKubeValues)(context), ALL_VALUES_FILE)), "kubernetesCreateSecret", "kubernetesDeploy", ...(0, sbom_1.getDependencyTrackUploadScript)(context), "echo deployment successful 😻", ], }, stop: { ...shared, script: [ ...connectContext, "kubernetesDelete", ...(0, sbom_1.getDependencyTrackDeleteScript)(context), ], }, rollback: { ...shared, script: [...connectContext, "kubernetesRollback"], }, }); }; exports.createKubernetesDeployJobs = createKubernetesDeployJobs; //# sourceMappingURL=deployJob.js.map