briareus
Version:
Briareus assists with Feature Branch deploys to ECS
48 lines (40 loc) • 1.25 kB
JavaScript
const AWS = require('aws-sdk');
const async = require('async');
let action = module.exports = function (pipeline, payload, cb) {
const ecs = new AWS.ECS();
// Return if we have no ECS Service
if (!payload.assets.ecsService) return cb(null, []);
const describeParams = {
services: [payload.name],
cluster: payload.ecsClusterArn,
};
const updateParams = {
service: payload.name,
cluster: payload.ecsClusterArn,
desiredCount: 0
};
const waitForParams = {
services: [payload.name],
cluster: payload.ecsClusterArn
};
async.series([
(next) => ecs.updateService(updateParams, next),
(next) => {
ecs.describeServices(describeParams, (err, data) => {
if (err) return cb(err);
// If running count is already 0, don't wait for service to be stable. Because we'll never get that event
if (data.services[0].runningCount === 0) return cb(null, []);
next();
});
},
(next) => {
// wait until service is stable, ie all tasks have stopped
ecs.waitFor('servicesStable', waitForParams, next);
}
], (err) => {
cb(null, []);
})
}
action.waiting = 'Scaling down ECS Service';
action.done = 'ECS Service has no task running';