@catladder/cli
Version:
Panter cli tool for cloud CI/CD and DevOps
86 lines (85 loc) • 3.97 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.createDeployJob = exports.DEPLOY_JOB_NAME = void 0;
const createJobCache_1 = require("../../build/cache/createJobCache");
const docker_1 = require("../../build/docker");
const context_1 = require("../../types/context");
const utils_1 = require("../utils");
const stop_1 = require("./stop");
const variables_1 = require("./variables");
exports.DEPLOY_JOB_NAME = "🚀 Deploy";
const createDeployJob = (context, jobDefinition) => {
var _a, _b, _c, _d, _e, _f;
const hasDocker = (0, docker_1.requiresDockerBuild)(context);
const isStoppable = (0, utils_1.contextIsStoppable)(context);
const autoStop = context.environment.envType === "review" ? "1 week" : context.environment.envType === "dev" ? "4 weeks" : undefined;
const deployConfig = (_a = context.deploy) === null || _a === void 0 ? void 0 : _a.config;
// if auto or manual is configured explicitly, use that
const whenDeployDefined = deployConfig && deployConfig.when ? deployConfig.when : undefined;
// otherwise auto deploy if env is not prod. If its prod, deploy automatically if stage is disabled
const 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
const 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: [...(deployConfig ? (_d = (_c = deployConfig.waitFor) === null || _c === void 0 ? void 0 : _c.map(c => ({
componentName: c,
job: exports.DEPLOY_JOB_NAME,
artifacts: false
}))) !== null && _d !== void 0 ? _d : [] : [])],
needsStages:
// if the build is disabled, we don't need to wait for it
context.build.type !== "disabled" ? [...((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,
}]),
// we don't want to deploy when there is a broken test
{
stage: "test",
artifacts: false,
// use test from workspace build
workspaceName: (0, context_1.componentContextHasWorkspaceBuild)(context) ? context.build.workspaceName : undefined
}] : [],
when: whenDeploy === "auto" ? "on_success" : "manual",
allow_failure: whenDeploy === "manual" ? true : false,
stage: "deploy",
variables: {
...context.environment.envVars,
...(hasDocker ? (0, docker_1.getDockerImageVariables)(context) : {}),
...context.environment.jobOnlyVars.deploy.envVars,
...jobDefinition.variables
},
runnerVariables: {
...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;