@catladder/pipeline
Version:
Panter workflow for cloud CI/CD and DevOps
122 lines (121 loc) • 5.33 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 __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;
};
var __spreadArray = this && this.__spreadArray || function (to, from, pack) {
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
if (ar || !(i in from)) {
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
ar[i] = from[i];
}
}
return to.concat(ar || Array.prototype.slice.call(from));
};
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.createDeployJob = exports.DEPLOY_JOB_NAME = void 0;
var createJobCache_1 = require("../../build/cache/createJobCache");
var docker_1 = require("../../build/docker");
var sbom_1 = require("../../build/sbom");
var context_1 = require("../../types/context");
var sbom_2 = require("../sbom");
var utils_1 = require("../utils");
var stop_1 = require("./stop");
var variables_1 = require("./variables");
exports.DEPLOY_JOB_NAME = "🚀 Deploy";
var createDeployJob = function (context, jobDefinition) {
var _a, _b, _c, _d, _e, _f;
var hasDocker = (0, docker_1.requiresDockerBuild)(context);
var isStoppable = (0, utils_1.contextIsStoppable)(context);
var autoStop = context.environment.envType === "review" ? "1 week" : context.environment.envType === "dev" ? "4 weeks" : undefined;
var deployConfig = (_a = context.deploy) === null || _a === void 0 ? void 0 : _a.config;
// if auto or manual is configured explicitly, use that
var whenDeployDefined = deployConfig && deployConfig.when ? deployConfig.when : undefined;
// otherwise auto deploy if env is not prod. If its prod, deploy automatically if stage is disabled
var whenDeployDefault = context.environment.envType !== "prod" ? "auto" // is not stage, auto deploy
: ((_b = context.componentConfig.env) === null || _b === void 0 ? void 0 : _b.stage) === false ? "auto" // is prod, but no staging, auto deploy
: "manual"; // manually deploy
var whenDeploy = whenDeployDefined ? whenDeployDefined : whenDeployDefault;
return {
name: exports.DEPLOY_JOB_NAME,
script: jobDefinition.script,
image: jobDefinition.image,
cache: jobDefinition.cache ? (0, createJobCache_1.createJobCacheFromCacheConfigs)(context, jobDefinition.cache) : undefined,
artifacts: jobDefinition.artifacts,
services: jobDefinition.services,
envMode: "stagePerEnv",
// makes it easier to run manual tasks er env
needs: __spreadArray(__spreadArray([], __read((0, sbom_2.sbomDeactivated)(context) ? [] : [{
job: sbom_1.SBOM_BUILD_JOB_NAME,
artifacts: true
}]), false), __read(deployConfig ? (_d = (_c = deployConfig.waitFor) === null || _c === void 0 ? void 0 : _c.map(function (c) {
return {
componentName: c,
job: exports.DEPLOY_JOB_NAME,
artifacts: false
};
})) !== null && _d !== void 0 ? _d : [] : []), false),
// we don't want to deploy when there is a broken test
needsStages: __spreadArray(__spreadArray([], __read((0, context_1.componentContextHasWorkspaceBuild)(context) ? hasDocker // docker build is per component,
? [
// we don't need artifacts, but have to wait for the component build
{
stage: "build",
artifacts: false
}] : [{
// pick build artifacts from workspace build
stage: "build",
artifacts: true,
workspaceName: context.build.workspaceName
}] : [{
stage: "build",
artifacts: hasDocker ? false : true // we asume that no-docker deployments need build artifacts,
}]), false), [{
stage: "test",
artifacts: false,
// use test from workspace build
workspaceName: (0, context_1.componentContextHasWorkspaceBuild)(context) ? context.build.workspaceName : undefined
}], false),
when: whenDeploy === "auto" ? "on_success" : "manual",
allow_failure: whenDeploy === "manual" ? true : false,
stage: "deploy",
variables: __assign(__assign(__assign(__assign({}, context.environment.envVars), hasDocker ? (0, docker_1.getDockerImageVariables)(context) : {}), context.environment.jobOnlyVars.deploy.envVars), jobDefinition.variables),
runnerVariables: __assign(__assign(__assign({}, variables_1.DEPLOY_RUNNER_VARIABLES), (_e = jobDefinition.runnerVariables) !== null && _e !== void 0 ? _e : {}), deployConfig ? (_f = deployConfig.runnerVariables) !== null && _f !== void 0 ? _f : {} : {}),
environment: isStoppable ? {
on_stop: stop_1.STOP_JOB_NAME,
auto_stop_in: autoStop
} : {},
jobTags: deployConfig ? deployConfig.jobTags : undefined
};
};
exports.createDeployJob = createDeployJob;