UNPKG

@topgroup/diginext

Version:

A BUILD SERVER & CLI to deploy apps to any Kubernetes clusters.

32 lines (31 loc) 1.44 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.promoteDeployEnvironment = void 0; const DB_1 = require("../api/DB"); const deploy_build_v2_1 = require("./deploy-build-v2"); async function promoteDeployEnvironment(options) { const { appSlug, fromEnv } = options; if (!appSlug) throw new Error(`Params "appSlug" is required.`); if (!fromEnv) throw new Error(`Params "env" (deploy environment) is required.`); const app = await DB_1.DB.findOne("app", { slug: appSlug }); if (!app) throw new Error(`App "${appSlug}" is not found.`); const deployEnvironment = app.deployEnvironment[fromEnv]; const { latestRelease, port } = deployEnvironment; // copy port from original deploy environment options.port = port; if (!latestRelease) throw new Error(`Deploy environment "${fromEnv}" is not found.`); const release = await DB_1.DB.findOne("release", { _id: latestRelease }, { populate: ["build"] }); if (!release) throw new Error(`Release "${latestRelease}" is not found.`); if (!release.build) throw new Error(`Build of release "${latestRelease}" is not found.`); // default options: wait for deploy to finish options.deployInBackground = false; const build = release.build; return (0, deploy_build_v2_1.deployBuildV2)(build, options); } exports.promoteDeployEnvironment = promoteDeployEnvironment;