UNPKG

@catladder/cli

Version:

Panter cli tool for cloud CI/CD and DevOps

78 lines 3.11 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getOnDeployExecuteScript = void 0; const createArgsString_1 = require("../../utils/createArgsString"); const getJobOrServiceArgs_1 = require("../../utils/getJobOrServiceArgs"); const jobName_1 = require("../../utils/jobName"); const cloudRunJobs_1 = require("../cloudRunJobs"); const common_1 = require("../common"); const getOnDeployExecuteScript = (context, when) => { const executes = getExecutes(context); return executes .filter(({ config }) => config.when === when) .map((execute) => { return getJobRunScriptForExecute(context, execute); }); }; exports.getOnDeployExecuteScript = getOnDeployExecuteScript; const getExecutes = (context) => { var _a; const deployConfig = (0, common_1.getCloudRunDeployConfig)(context); return [ ...getLegacyExecutes(context), ...Object.entries((_a = deployConfig.execute) !== null && _a !== void 0 ? _a : {}).flatMap(([key, value]) => { if (!value || (value.when !== "schedule" && value.type !== "job")) { return []; } return [ { jobName: key, config: value, }, ]; }), ]; }; const getLegacyExecutes = (context) => { const jobsWithNames = (0, cloudRunJobs_1.getCloudRunJobsWithNames)(context); return jobsWithNames.flatMap(({ jobName, job }) => { if (!job.when || !["preDeploy", "postDeploy", "preStop", "postStop"].includes(job.when)) { return []; } return [ { jobName, config: { job: jobName, type: "job", when: job.when, ...(job.when === "preDeploy" || job.when === "postDeploy" ? { waitForCompletion: job.waitForCompletion, } : {}), }, }, ]; }); }; const getJobRunScriptForExecute = (context, { jobName, config }) => { var _a; const commonArgs = (0, common_1.getCommonCloudRunArgs)(context); // always wait for completion for preStop and postStop jobs // since stop will delete the jobs afterwards, so they will fail const waitForCompletion = ["preStop", "postStop"].includes(config.when) ? true // always : "waitForCompletion" in config ? ((_a = config.waitForCompletion) !== null && _a !== void 0 ? _a : false) // depends on config : false; const argString = (0, createArgsString_1.createArgsString)({ ...commonArgs, wait: waitForCompletion === true ? true : undefined, args: (0, getJobOrServiceArgs_1.getCloudRunServiceOrJobArgsArg)(config.args), }); const fullJobName = (0, jobName_1.getFullJobName)(context, jobName); return `${(0, common_1.gcloudRunCmd)()} jobs execute ${fullJobName.toString()} ${argString}`; }; //# sourceMappingURL=onDeploy.js.map