garbage collection
parent
eb7bcf718a
commit
b2d2a1501a
|
|
@ -1442,30 +1442,16 @@ const input_1 = __importDefault(__nccwpck_require__(91933));
|
||||||
const cloud_runner_logger_1 = __importDefault(__nccwpck_require__(22855));
|
const cloud_runner_logger_1 = __importDefault(__nccwpck_require__(22855));
|
||||||
class AwsCliCommands {
|
class AwsCliCommands {
|
||||||
static garbageCollectAws() {
|
static garbageCollectAws() {
|
||||||
var _a;
|
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
process.env.AWS_REGION = input_1.default.region;
|
yield AwsCliCommands.cleanup(false);
|
||||||
cloud_runner_logger_1.default.log(`Cloud Formation stacks`);
|
|
||||||
const CF = new aws_sdk_1.default.CloudFormation();
|
|
||||||
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));
|
|
||||||
}
|
|
||||||
cloud_runner_logger_1.default.log(`ECS Clusters`);
|
|
||||||
const ecs = new aws_sdk_1.default.ECS();
|
|
||||||
const clusters = (yield ecs.listClusters().promise()).clusterArns || [];
|
|
||||||
if (stacks === undefined) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
for (const element of clusters) {
|
|
||||||
const input = {
|
|
||||||
cluster: element,
|
|
||||||
};
|
|
||||||
cloud_runner_logger_1.default.log(JSON.stringify(yield ecs.listTasks(input).promise(), undefined, 4));
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
static garbageCollectAwsAll() {
|
static garbageCollectAwsAll() {
|
||||||
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
|
yield AwsCliCommands.cleanup(true);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
static cleanup(deleteResources = false) {
|
||||||
var _a;
|
var _a;
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
process.env.AWS_REGION = input_1.default.region;
|
process.env.AWS_REGION = input_1.default.region;
|
||||||
|
|
@ -1494,16 +1480,22 @@ class AwsCliCommands {
|
||||||
taskElement.overrides = {};
|
taskElement.overrides = {};
|
||||||
taskElement.attachments = [];
|
taskElement.attachments = [];
|
||||||
cloud_runner_logger_1.default.log(JSON.stringify(taskElement, undefined, 4));
|
cloud_runner_logger_1.default.log(JSON.stringify(taskElement, undefined, 4));
|
||||||
yield ecs.stopTask({ task: taskElement.taskArn || '', cluster: element }).promise();
|
if (deleteResources) {
|
||||||
|
yield ecs.stopTask({ task: taskElement.taskArn || '', cluster: element }).promise();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
yield ecs.deleteCluster({ cluster: element }).promise();
|
if (deleteResources) {
|
||||||
|
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')) || [];
|
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) {
|
for (const element of stacks) {
|
||||||
cloud_runner_logger_1.default.log(JSON.stringify(element, undefined, 4));
|
cloud_runner_logger_1.default.log(JSON.stringify(element, undefined, 4));
|
||||||
const deleteStackInput = { StackName: element.StackName };
|
const deleteStackInput = { StackName: element.StackName };
|
||||||
yield CF.deleteStack(deleteStackInput).promise();
|
if (deleteResources) {
|
||||||
|
yield CF.deleteStack(deleteStackInput).promise();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (stacks === undefined) {
|
if (stacks === undefined) {
|
||||||
return;
|
return;
|
||||||
|
|
|
||||||
File diff suppressed because one or more lines are too long
|
|
@ -6,29 +6,14 @@ import CloudRunnerLogger from '../../../services/cloud-runner-logger';
|
||||||
export class AwsCliCommands {
|
export class AwsCliCommands {
|
||||||
@CliFunction(`aws-garbage-collect`, `garbage collect aws`)
|
@CliFunction(`aws-garbage-collect`, `garbage collect aws`)
|
||||||
static async garbageCollectAws() {
|
static async garbageCollectAws() {
|
||||||
process.env.AWS_REGION = Input.region;
|
await AwsCliCommands.cleanup(false);
|
||||||
CloudRunnerLogger.log(`Cloud Formation stacks`);
|
|
||||||
const CF = new AWS.CloudFormation();
|
|
||||||
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));
|
|
||||||
}
|
|
||||||
CloudRunnerLogger.log(`ECS Clusters`);
|
|
||||||
const ecs = new AWS.ECS();
|
|
||||||
const clusters = (await ecs.listClusters().promise()).clusterArns || [];
|
|
||||||
if (stacks === undefined) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
for (const element of clusters) {
|
|
||||||
const input: AWS.ECS.ListTasksRequest = {
|
|
||||||
cluster: element,
|
|
||||||
};
|
|
||||||
CloudRunnerLogger.log(JSON.stringify(await ecs.listTasks(input).promise(), undefined, 4));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@CliFunction(`aws-garbage-collect-all`, `garbage collect aws`)
|
@CliFunction(`aws-garbage-collect-all`, `garbage collect aws`)
|
||||||
static async garbageCollectAwsAll() {
|
static async garbageCollectAwsAll() {
|
||||||
|
await AwsCliCommands.cleanup(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static async cleanup(deleteResources = false) {
|
||||||
process.env.AWS_REGION = Input.region;
|
process.env.AWS_REGION = Input.region;
|
||||||
CloudRunnerLogger.log(`Cloud Formation stacks`);
|
CloudRunnerLogger.log(`Cloud Formation stacks`);
|
||||||
const CF = new AWS.CloudFormation();
|
const CF = new AWS.CloudFormation();
|
||||||
|
|
@ -55,18 +40,23 @@ export class AwsCliCommands {
|
||||||
taskElement.overrides = {};
|
taskElement.overrides = {};
|
||||||
taskElement.attachments = [];
|
taskElement.attachments = [];
|
||||||
CloudRunnerLogger.log(JSON.stringify(taskElement, undefined, 4));
|
CloudRunnerLogger.log(JSON.stringify(taskElement, undefined, 4));
|
||||||
await ecs.stopTask({ task: taskElement.taskArn || '', cluster: element }).promise();
|
if (deleteResources) {
|
||||||
|
await ecs.stopTask({ task: taskElement.taskArn || '', cluster: element }).promise();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (deleteResources) {
|
||||||
await ecs.deleteCluster({ cluster: element }).promise();
|
await ecs.deleteCluster({ cluster: element }).promise();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
const stacks =
|
const stacks =
|
||||||
(await CF.listStacks().promise()).StackSummaries?.filter((_x) => _x.StackStatus !== 'DELETE_COMPLETE') || [];
|
(await CF.listStacks().promise()).StackSummaries?.filter((_x) => _x.StackStatus !== 'DELETE_COMPLETE') || [];
|
||||||
for (const element of stacks) {
|
for (const element of stacks) {
|
||||||
CloudRunnerLogger.log(JSON.stringify(element, undefined, 4));
|
CloudRunnerLogger.log(JSON.stringify(element, undefined, 4));
|
||||||
const deleteStackInput: AWS.CloudFormation.DeleteStackInput = { StackName: element.StackName };
|
const deleteStackInput: AWS.CloudFormation.DeleteStackInput = { StackName: element.StackName };
|
||||||
await CF.deleteStack(deleteStackInput).promise();
|
if (deleteResources) {
|
||||||
|
await CF.deleteStack(deleteStackInput).promise();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (stacks === undefined) {
|
if (stacks === undefined) {
|
||||||
return;
|
return;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue