garbage collection
parent
bcd33296b6
commit
eb7bcf718a
|
|
@ -1465,10 +1465,58 @@ class AwsCliCommands {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
static garbageCollectAwsAll() {
|
||||||
|
var _a;
|
||||||
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
|
process.env.AWS_REGION = input_1.default.region;
|
||||||
|
cloud_runner_logger_1.default.log(`Cloud Formation stacks`);
|
||||||
|
const CF = new aws_sdk_1.default.CloudFormation();
|
||||||
|
cloud_runner_logger_1.default.log(`ECS Clusters`);
|
||||||
|
const ecs = new aws_sdk_1.default.ECS();
|
||||||
|
const clusters = (yield ecs.listClusters().promise()).clusterArns || [];
|
||||||
|
for (const element of clusters) {
|
||||||
|
const input = {
|
||||||
|
cluster: element,
|
||||||
|
};
|
||||||
|
const list = (yield ecs.listTasks(input).promise()).taskArns || [];
|
||||||
|
if (list.length > 0) {
|
||||||
|
cloud_runner_logger_1.default.log(`DescribeTasksRequest`);
|
||||||
|
cloud_runner_logger_1.default.log(JSON.stringify(list, undefined, 4));
|
||||||
|
const describeInput = { tasks: list, cluster: element };
|
||||||
|
const describeList = (yield ecs.describeTasks(describeInput).promise()).tasks || [];
|
||||||
|
if (describeList === []) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
for (const taskElement of describeList) {
|
||||||
|
if (taskElement === undefined) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
taskElement.overrides = {};
|
||||||
|
taskElement.attachments = [];
|
||||||
|
cloud_runner_logger_1.default.log(JSON.stringify(taskElement, undefined, 4));
|
||||||
|
yield ecs.stopTask({ task: taskElement.taskArn || '', cluster: element }).promise();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
yield ecs.deleteCluster({ cluster: element }).promise();
|
||||||
|
}
|
||||||
|
const stacks = ((_a = (yield CF.listStacks().promise()).StackSummaries) === null || _a === void 0 ? void 0 : _a.filter((_x) => _x.StackStatus !== 'DELETE_COMPLETE')) || [];
|
||||||
|
for (const element of stacks) {
|
||||||
|
cloud_runner_logger_1.default.log(JSON.stringify(element, undefined, 4));
|
||||||
|
const deleteStackInput = { StackName: element.StackName };
|
||||||
|
yield CF.deleteStack(deleteStackInput).promise();
|
||||||
|
}
|
||||||
|
if (stacks === undefined) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
__decorate([
|
__decorate([
|
||||||
cli_functions_repository_1.CliFunction(`aws-garbage-collect`, `garbage collect aws`)
|
cli_functions_repository_1.CliFunction(`aws-garbage-collect`, `garbage collect aws`)
|
||||||
], AwsCliCommands, "garbageCollectAws", null);
|
], AwsCliCommands, "garbageCollectAws", null);
|
||||||
|
__decorate([
|
||||||
|
cli_functions_repository_1.CliFunction(`aws-garbage-collect-all`, `garbage collect aws`)
|
||||||
|
], AwsCliCommands, "garbageCollectAwsAll", null);
|
||||||
exports.AwsCliCommands = AwsCliCommands;
|
exports.AwsCliCommands = AwsCliCommands;
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
File diff suppressed because one or more lines are too long
|
|
@ -27,4 +27,49 @@ export class AwsCliCommands {
|
||||||
CloudRunnerLogger.log(JSON.stringify(await ecs.listTasks(input).promise(), undefined, 4));
|
CloudRunnerLogger.log(JSON.stringify(await ecs.listTasks(input).promise(), undefined, 4));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@CliFunction(`aws-garbage-collect-all`, `garbage collect aws`)
|
||||||
|
static async garbageCollectAwsAll() {
|
||||||
|
process.env.AWS_REGION = Input.region;
|
||||||
|
CloudRunnerLogger.log(`Cloud Formation stacks`);
|
||||||
|
const CF = new AWS.CloudFormation();
|
||||||
|
CloudRunnerLogger.log(`ECS Clusters`);
|
||||||
|
const ecs = new AWS.ECS();
|
||||||
|
const clusters = (await ecs.listClusters().promise()).clusterArns || [];
|
||||||
|
for (const element of clusters) {
|
||||||
|
const input: AWS.ECS.ListTasksRequest = {
|
||||||
|
cluster: element,
|
||||||
|
};
|
||||||
|
const list = (await ecs.listTasks(input).promise()).taskArns || [];
|
||||||
|
if (list.length > 0) {
|
||||||
|
CloudRunnerLogger.log(`DescribeTasksRequest`);
|
||||||
|
CloudRunnerLogger.log(JSON.stringify(list, undefined, 4));
|
||||||
|
const describeInput: AWS.ECS.DescribeTasksRequest = { tasks: list, cluster: element };
|
||||||
|
const describeList = (await ecs.describeTasks(describeInput).promise()).tasks || [];
|
||||||
|
if (describeList === []) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
for (const taskElement of describeList) {
|
||||||
|
if (taskElement === undefined) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
taskElement.overrides = {};
|
||||||
|
taskElement.attachments = [];
|
||||||
|
CloudRunnerLogger.log(JSON.stringify(taskElement, undefined, 4));
|
||||||
|
await ecs.stopTask({ task: taskElement.taskArn || '', cluster: element }).promise();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
await ecs.deleteCluster({ cluster: element }).promise();
|
||||||
|
}
|
||||||
|
const stacks =
|
||||||
|
(await CF.listStacks().promise()).StackSummaries?.filter((_x) => _x.StackStatus !== 'DELETE_COMPLETE') || [];
|
||||||
|
for (const element of stacks) {
|
||||||
|
CloudRunnerLogger.log(JSON.stringify(element, undefined, 4));
|
||||||
|
const deleteStackInput: AWS.CloudFormation.DeleteStackInput = { StackName: element.StackName };
|
||||||
|
await CF.deleteStack(deleteStackInput).promise();
|
||||||
|
}
|
||||||
|
if (stacks === undefined) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue