Skip to content

Commit 93b4ed3

Browse files
committed
Update dist file
1 parent 776f22f commit 93b4ed3

File tree

1 file changed

+76
-63
lines changed

1 file changed

+76
-63
lines changed

dist/index.js

Lines changed: 76 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -234028,6 +234028,9 @@ var updateTerminationProtection_awaiter = (undefined && undefined.__awaiter) ||
234028234028

234029234029
function enableTerminationProtection(targetEnv) {
234030234030
return updateTerminationProtection_awaiter(this, void 0, void 0, function* () {
234031+
if (!targetEnv) {
234032+
throw new Error("No target environment found. Cannot enable termination protection.");
234033+
}
234031234034
const stackName = `awseb-${targetEnv.EnvironmentId}-stack`;
234032234035
console.log(`[${targetEnv.EnvironmentName}]: Enabling termination protection for stack ${stackName}...`);
234033234036
yield cfnClient.send(new client_cloudformation_dist_cjs.UpdateTerminationProtectionCommand({
@@ -234085,7 +234088,7 @@ function removeTargetGroups(inputs) {
234085234088
for (const { Tags, ResourceArn } of TagDescriptions) {
234086234089
const rule = rules[ResourceArn];
234087234090
for (const { Key, Value } of Tags) {
234088-
if (Key === "bluegreenbeanstalk:forward_cname" &&
234091+
if (Key === "bluegreenbeanstalk:target_cname" &&
234089234092
Value === inputs.stagingCNAME) {
234090234093
yield elbv2Client.send(new client_elastic_load_balancing_v2_dist_cjs.ModifyRuleCommand({
234091234094
RuleArn: ResourceArn,
@@ -234117,10 +234120,11 @@ function updateTargetGroups(inputs) {
234117234120
};
234118234121
for (const { Tags, ResourceArn } of TagDescriptions) {
234119234122
const rule = rules[ResourceArn];
234120-
const cname = (_a = Tags.find(({ Key }) => Key === "bluegreenbeanstalk:forward_cname")) === null || _a === void 0 ? void 0 : _a.Value;
234123+
const cname = (_a = Tags.find(({ Key }) => Key === "bluegreenbeanstalk:target_cname")) === null || _a === void 0 ? void 0 : _a.Value;
234121234124
if (![inputs.stagingCNAME, inputs.productionCNAME].includes(cname))
234122234125
continue;
234123-
const port = ((_b = Tags.find(({ Key }) => Key === "bluegreenbeanstalk:forward_port")) === null || _b === void 0 ? void 0 : _b.Value) || 80;
234126+
const port = ((_b = Tags.find(({ Key }) => Key === "bluegreenbeanstalk:target_port")) === null || _b === void 0 ? void 0 : _b.Value) ||
234127+
80;
234124234128
const targetGroupArn = (_c = targetGroupARNs[cname]) === null || _c === void 0 ? void 0 : _c[port];
234125234129
if (targetGroupArn) {
234126234130
yield elbv2Client.send(new client_elastic_load_balancing_v2_dist_cjs.ModifyRuleCommand({
@@ -234205,13 +234209,18 @@ function getRules(resources) {
234205234209
loadBalancerArns.add(Name);
234206234210
}
234207234211
}
234208-
const listeners = [];
234209-
for (const loadBalancerArn of loadBalancerArns) {
234210-
yield elbv2Client.send(new client_elastic_load_balancing_v2_dist_cjs.DescribeListenersCommand({
234211-
LoadBalancerArn: loadBalancerArn,
234212-
}))
234213-
.then(({ Listeners }) => listeners.push(...Listeners));
234212+
if (loadBalancerArns.size === 0) {
234213+
throw new Error("No load balancers found");
234214234214
}
234215+
if (loadBalancerArns.size > 1) {
234216+
throw new Error("Environments must use the same load balancer");
234217+
}
234218+
const loadBalancerArn = Array.from(loadBalancerArns)[0];
234219+
const listeners = [];
234220+
yield elbv2Client.send(new client_elastic_load_balancing_v2_dist_cjs.DescribeListenersCommand({
234221+
LoadBalancerArn: loadBalancerArn,
234222+
}))
234223+
.then(({ Listeners }) => listeners.push(...Listeners));
234215234224
const rules = [];
234216234225
for (const { ListenerArn } of listeners) {
234217234226
yield elbv2Client.send(new client_elastic_load_balancing_v2_dist_cjs.DescribeRulesCommand({ ListenerArn: ListenerArn }))
@@ -234247,15 +234256,19 @@ var terminateEnvironment_awaiter = (undefined && undefined.__awaiter) || functio
234247234256
function terminateEnvironment(inputs, env) {
234248234257
return terminateEnvironment_awaiter(this, void 0, void 0, function* () {
234249234258
if (!inputs.terminateUnhealthyEnvironment) {
234250-
throw new Error("Target environment is unhealthy and terminate_unhealthy_environment is set to false.");
234259+
throw {
234260+
type: "EarlyExit",
234261+
message: "Target environment is unhealthy and terminateUnhealthyEnvironment is false. Exiting...",
234262+
targetEnv: env,
234263+
};
234251234264
}
234252234265
if (inputs.updateListenerRules) {
234253234266
yield removeTargetGroups(inputs);
234254234267
}
234255234268
if (inputs.disableTerminationProtection) {
234256234269
yield disableTerminationProtection(env);
234257234270
}
234258-
console.log(`[${env.EnvironmentName}]: Terminating environment ${env.EnvironmentId}...`);
234271+
console.log(`Terminating environment ${env.EnvironmentName} ${env.EnvironmentId}...`);
234259234272
const startTime = new Date();
234260234273
yield ebClient.send(new dist_cjs.TerminateEnvironmentCommand({
234261234274
EnvironmentId: env.EnvironmentId,
@@ -234266,7 +234279,11 @@ function terminateEnvironment(inputs, env) {
234266234279
clearInterval(interval);
234267234280
}
234268234281
else
234269-
throw new Error("Target environment is terminating and wait_for_termination is set to false.");
234282+
throw {
234283+
type: "EarlyExit",
234284+
message: "Target environment is terminating and waitForTermination is false. Exiting...",
234285+
targetEnv: env,
234286+
};
234270234287
});
234271234288
}
234272234289

@@ -234302,7 +234319,11 @@ function getTargetEnv(inputs) {
234302234319
return null;
234303234320
}
234304234321
else
234305-
throw new Error("Target environment is terminating and wait_for_termination is set to false.");
234322+
throw {
234323+
type: "EarlyExit",
234324+
message: "Target environment is terminating and waitForTermination is false. Exiting...",
234325+
targetEnv,
234326+
};
234306234327
}
234307234328
else if (targetEnv.Status !== "Ready") {
234308234329
if (inputs.waitForEnvironment) {
@@ -234313,7 +234334,11 @@ function getTargetEnv(inputs) {
234313234334
return getTargetEnv(inputs);
234314234335
}
234315234336
else
234316-
throw new Error("Target environment is not ready and wait_for_environment is set to false.");
234337+
throw {
234338+
type: "EarlyExit",
234339+
message: "Target environment is not ready and waitForEnvironment is false. Exiting...",
234340+
targetEnv,
234341+
};
234317234342
}
234318234343
switch (targetEnv.Health) {
234319234344
case "Green":
@@ -234453,8 +234478,8 @@ function updateEnvironment(inputs, targetEnv, applicationVersion) {
234453234478
});
234454234479
}
234455234480

234456-
;// CONCATENATED MODULE: ./src/swapCNAMES.ts
234457-
var swapCNAMES_awaiter = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
234481+
;// CONCATENATED MODULE: ./src/swapCNAMEs.ts
234482+
var swapCNAMEs_awaiter = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
234458234483
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
234459234484
return new (P || (P = Promise))(function (resolve, reject) {
234460234485
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
@@ -234465,30 +234490,30 @@ var swapCNAMES_awaiter = (undefined && undefined.__awaiter) || function (thisArg
234465234490
};
234466234491

234467234492

234468-
const swapCNAMES_core = __nccwpck_require__(42186);
234469-
function swapCNAMES(inputs) {
234470-
return swapCNAMES_awaiter(this, void 0, void 0, function* () {
234471-
const { Environments } = yield ebClient.send(new dist_cjs.DescribeEnvironmentsCommand({
234472-
ApplicationName: inputs.appName,
234473-
EnvironmentNames: [inputs.blueEnv, inputs.greenEnv],
234474-
IncludeDeleted: false,
234475-
}));
234476-
const blueEnv = Environments.find((env) => env.EnvironmentName === inputs.blueEnv);
234477-
const greenEnv = Environments.find((env) => env.EnvironmentName === inputs.greenEnv);
234478-
if (!blueEnv || !greenEnv) {
234479-
swapCNAMES_core.warning("Blue or green environment not found. Cannot swap CNAMES...");
234493+
234494+
const swapCNAMEs_core = __nccwpck_require__(42186);
234495+
function swapCNAMEs(inputs) {
234496+
return swapCNAMEs_awaiter(this, void 0, void 0, function* () {
234497+
const { stagingEnv, prodEnv } = yield getEnvironments(inputs);
234498+
if (!stagingEnv || !prodEnv) {
234499+
swapCNAMEs_core.warning("Cannot swap CNAMEs without both environments...");
234480234500
return;
234481234501
}
234482-
if (blueEnv.Status !== "Ready" || greenEnv.Status !== "Ready") {
234483-
swapCNAMES_core.info("Environments not yet ready. Waiting...");
234484-
yield (0,dist_cjs.waitUntilEnvironmentUpdated)({ client: ebClient, maxWaitTime: 60 * 10, minDelay: 5, maxDelay: 30 }, { EnvironmentIds: [blueEnv.EnvironmentId, greenEnv.EnvironmentId] });
234502+
if (stagingEnv.Health !== "Green") {
234503+
throw new Error(`Target environment is not healthy. Cannot swap CNAMEs.`);
234485234504
}
234486-
swapCNAMES_core.info("Swapping CNAMES...");
234505+
if (stagingEnv.Status !== "Ready" || prodEnv.Status !== "Ready") {
234506+
swapCNAMEs_core.info("Environments not yet ready. Waiting...");
234507+
yield (0,dist_cjs.waitUntilEnvironmentUpdated)({ client: ebClient, maxWaitTime: 60 * 10, minDelay: 5, maxDelay: 30 }, {
234508+
EnvironmentIds: [stagingEnv.EnvironmentId, prodEnv.EnvironmentId],
234509+
});
234510+
}
234511+
swapCNAMEs_core.info("Swapping CNAMEs...");
234487234512
yield ebClient.send(new dist_cjs.SwapEnvironmentCNAMEsCommand({
234488-
DestinationEnvironmentId: blueEnv.EnvironmentId,
234489-
SourceEnvironmentId: greenEnv.EnvironmentId,
234513+
DestinationEnvironmentId: prodEnv.EnvironmentId,
234514+
SourceEnvironmentId: stagingEnv.EnvironmentId,
234490234515
}));
234491-
yield (0,dist_cjs.waitUntilEnvironmentUpdated)({ client: ebClient, maxWaitTime: 60 * 10, minDelay: 5, maxDelay: 30 }, { EnvironmentIds: [blueEnv.EnvironmentId, greenEnv.EnvironmentId] });
234516+
yield (0,dist_cjs.waitUntilEnvironmentUpdated)({ client: ebClient, maxWaitTime: 60 * 10, minDelay: 5, maxDelay: 30 }, { EnvironmentIds: [stagingEnv.EnvironmentId, prodEnv.EnvironmentId] });
234492234517
});
234493234518
}
234494234519

@@ -234514,9 +234539,10 @@ var main_awaiter = (undefined && undefined.__awaiter) || function (thisArg, _arg
234514234539

234515234540
function main(inputs) {
234516234541
return main_awaiter(this, void 0, void 0, function* () {
234542+
let targetEnv = null;
234517234543
try {
234518234544
const applicationVersion = yield getApplicationVersion(inputs);
234519-
let targetEnv = yield getTargetEnv(inputs);
234545+
targetEnv = yield getTargetEnv(inputs);
234520234546
if (inputs.deploy) {
234521234547
if (targetEnv && inputs.updateEnvironment) {
234522234548
yield updateEnvironment(inputs, targetEnv, applicationVersion);
@@ -234526,38 +234552,26 @@ function main(inputs) {
234526234552
}
234527234553
}
234528234554
if (inputs.enableTerminationProtection) {
234529-
if (!targetEnv) {
234530-
throw new Error("No target environment found. Cannot enable termination protection.");
234531-
}
234532234555
yield enableTerminationProtection(targetEnv);
234533234556
}
234534-
if (inputs.promote) {
234535-
if (!targetEnv) {
234536-
throw new Error("No target environment found. Cannot promote to production.");
234537-
}
234538-
console.log(`Promoting environment ${targetEnv.EnvironmentName} to production...`);
234539-
yield ebClient.send(new dist_cjs.DescribeEnvironmentsCommand({
234540-
EnvironmentIds: [targetEnv.EnvironmentId],
234541-
}))
234542-
.then(({ Environments }) => {
234543-
if (Environments[0].Health !== "Green") {
234544-
throw new Error(`Environment ${targetEnv.EnvironmentName} is not healthy. Aborting promotion.`);
234545-
}
234546-
if (Environments[0].Status !== "Ready") {
234547-
throw new Error(`Environment ${targetEnv.EnvironmentName} is not ready. Aborting promotion.`);
234548-
}
234549-
});
234550-
yield swapCNAMES(inputs);
234557+
if (inputs.swapCNAMEs) {
234558+
yield swapCNAMEs(inputs);
234551234559
}
234552234560
if (inputs.updateListenerRules) {
234553234561
yield updateTargetGroups(inputs);
234554234562
}
234555-
yield setOutputs(targetEnv);
234556234563
}
234557234564
catch (err) {
234558-
core.setFailed(err.message);
234559-
return Promise.reject(err);
234565+
if (err.type === "EarlyExit") {
234566+
console.log(err.message);
234567+
targetEnv = err.targetEnv;
234568+
}
234569+
else {
234570+
core.setFailed(err.message);
234571+
return Promise.reject(err);
234572+
}
234560234573
}
234574+
yield setOutputs(targetEnv);
234561234575
});
234562234576
}
234563234577
function setOutputs(targetEnv) {
@@ -234599,9 +234613,9 @@ function getInputs() {
234599234613
: undefined,
234600234614
platformBranchName: core.getInput("platform_branch_name"),
234601234615
productionCNAME: core.getInput("production_cname", { required: true }),
234602-
promote: core.getBooleanInput("promote", { required: true }),
234603234616
sourceBundle: core.getInput("source_bundle") || undefined,
234604234617
stagingCNAME: core.getInput("staging_cname", { required: true }),
234618+
swapCNAMEs: core.getBooleanInput("swap_cnames", { required: true }),
234605234619
templateName: core.getInput("template_name") || undefined,
234606234620
terminateUnhealthyEnvironment: core.getBooleanInput("terminate_unhealthy_environment", { required: true }),
234607234621
updateEnvironment: core.getBooleanInput("update_environment", {
@@ -234641,9 +234655,8 @@ function checkInputs(inputs) {
234641234655
if (inputs.blueEnv === inputs.greenEnv) {
234642234656
throw new Error("blue_env and green_env must be different");
234643234657
}
234644-
if ((!inputs.versionLabel && inputs.sourceBundle) ||
234645-
(inputs.versionLabel && !inputs.sourceBundle)) {
234646-
throw new Error("source_bundle and version_label must be provided together");
234658+
if (!inputs.versionLabel && inputs.sourceBundle) {
234659+
throw new Error("source_bundle must be provided with a version_label");
234647234660
}
234648234661
if (inputs.productionCNAME === inputs.stagingCNAME) {
234649234662
throw new Error("production_cname and staging_cname must be different");

0 commit comments

Comments
 (0)