better aws cli commands and better cleanup for aws
parent
a184b7abae
commit
3bd297d1c8
|
|
@ -23,13 +23,13 @@ jobs:
|
|||
with:
|
||||
node-version: 12.x
|
||||
- run: yarn
|
||||
- run: yarn run cli -m aws-list-tasks
|
||||
- run: yarn run cli --help
|
||||
env:
|
||||
AWS_REGION: eu-west-2
|
||||
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
|
||||
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
|
||||
AWS_DEFAULT_REGION: eu-west-2
|
||||
- run: yarn run cli -m aws-list-stacks
|
||||
- run: yarn run cli -m aws-list-all
|
||||
env:
|
||||
AWS_REGION: eu-west-2
|
||||
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
|
||||
|
|
|
|||
|
|
@ -1413,8 +1413,9 @@ exports.BaseStackFormation = void 0;
|
|||
class BaseStackFormation {
|
||||
}
|
||||
exports.BaseStackFormation = BaseStackFormation;
|
||||
BaseStackFormation.baseStackDecription = `Game-CI base stack`;
|
||||
BaseStackFormation.formation = `AWSTemplateFormatVersion: '2010-09-09'
|
||||
Description: Game-CI base stack
|
||||
Description: ${BaseStackFormation.baseStackDecription}
|
||||
Parameters:
|
||||
EnvironmentName:
|
||||
Type: String
|
||||
|
|
@ -1816,11 +1817,12 @@ exports.TaskDefinitionFormation = void 0;
|
|||
class TaskDefinitionFormation {
|
||||
}
|
||||
exports.TaskDefinitionFormation = TaskDefinitionFormation;
|
||||
TaskDefinitionFormation.description = `AWS Fargate cluster that can span public and private subnets. Supports public
|
||||
facing load balancers, private internal load balancers, and both internal and
|
||||
external service discovery namespaces.`;
|
||||
TaskDefinitionFormation.formation = `AWSTemplateFormatVersion: 2010-09-09
|
||||
Description: >-
|
||||
AWS Fargate cluster that can span public and private subnets. Supports public
|
||||
facing load balancers, private internal load balancers, and both internal and
|
||||
external service discovery namespaces.
|
||||
|
||||
Parameters:
|
||||
EnvironmentName:
|
||||
Type: String
|
||||
|
|
@ -2005,17 +2007,29 @@ const aws_sdk_1 = __importDefault(__nccwpck_require__(71786));
|
|||
const cli_functions_repository_1 = __nccwpck_require__(85301);
|
||||
const input_1 = __importDefault(__nccwpck_require__(91933));
|
||||
const cloud_runner_logger_1 = __importDefault(__nccwpck_require__(22855));
|
||||
const base_stack_formation_1 = __nccwpck_require__(29643);
|
||||
class AwsCliCommands {
|
||||
static awsListStacks(perResultCallback) {
|
||||
var _a;
|
||||
static awsListAll() {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
yield AwsCliCommands.awsListStacks();
|
||||
yield AwsCliCommands.awsListTasks();
|
||||
yield AwsCliCommands.awsListLogGroups();
|
||||
});
|
||||
}
|
||||
static awsListStacks(perResultCallback = false) {
|
||||
var _a, _b;
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
process.env.AWS_REGION = input_1.default.region;
|
||||
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')) || [];
|
||||
cloud_runner_logger_1.default.log(`DescribeStacksRequest ${stacks.length}`);
|
||||
const stacks = ((_a = (yield CF.listStacks().promise()).StackSummaries) === null || _a === void 0 ? void 0 : _a.filter((_x) => _x.StackStatus !== 'DELETE_COMPLETE' && _x.TemplateDescription !== base_stack_formation_1.BaseStackFormation.baseStackDecription)) || [];
|
||||
cloud_runner_logger_1.default.log(`Stacks ${stacks.length}`);
|
||||
for (const element of stacks) {
|
||||
cloud_runner_logger_1.default.log(JSON.stringify(element, undefined, 4));
|
||||
cloud_runner_logger_1.default.log(`${element.StackName}`);
|
||||
if (perResultCallback)
|
||||
yield perResultCallback(element);
|
||||
}
|
||||
const baseStacks = ((_b = (yield CF.listStacks().promise()).StackSummaries) === null || _b === void 0 ? void 0 : _b.filter((_x) => _x.StackStatus !== 'DELETE_COMPLETE' && _x.TemplateDescription === base_stack_formation_1.BaseStackFormation.baseStackDecription)) || [];
|
||||
cloud_runner_logger_1.default.log(`Base Stacks ${baseStacks.length}`);
|
||||
for (const element of baseStacks) {
|
||||
if (perResultCallback)
|
||||
yield perResultCallback(element);
|
||||
}
|
||||
|
|
@ -2024,12 +2038,12 @@ class AwsCliCommands {
|
|||
}
|
||||
});
|
||||
}
|
||||
static awsListTasks(perResultCallback) {
|
||||
static awsListTasks(perResultCallback = false) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
process.env.AWS_REGION = input_1.default.region;
|
||||
cloud_runner_logger_1.default.log(`ECS Clusters`);
|
||||
const ecs = new aws_sdk_1.default.ECS();
|
||||
const clusters = (yield ecs.listClusters().promise()).clusterArns || [];
|
||||
cloud_runner_logger_1.default.log(`Clusters ${clusters.length}`);
|
||||
for (const element of clusters) {
|
||||
const input = {
|
||||
cluster: element,
|
||||
|
|
@ -2041,14 +2055,13 @@ class AwsCliCommands {
|
|||
if (describeList === []) {
|
||||
continue;
|
||||
}
|
||||
cloud_runner_logger_1.default.log(`DescribeTasksRequest ${describeList.length}`);
|
||||
cloud_runner_logger_1.default.log(`Tasks ${describeList.length}`);
|
||||
for (const taskElement of describeList) {
|
||||
if (taskElement === undefined) {
|
||||
continue;
|
||||
}
|
||||
taskElement.overrides = {};
|
||||
taskElement.attachments = [];
|
||||
cloud_runner_logger_1.default.log(JSON.stringify(taskElement, undefined, 4));
|
||||
if (taskElement.createdAt === undefined) {
|
||||
cloud_runner_logger_1.default.log(`Skipping ${taskElement.taskDefinitionArn} no createdAt date`);
|
||||
continue;
|
||||
|
|
@ -2060,6 +2073,23 @@ class AwsCliCommands {
|
|||
}
|
||||
});
|
||||
}
|
||||
static awsListLogGroups(perResultCallback = false) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
process.env.AWS_REGION = input_1.default.region;
|
||||
const ecs = new aws_sdk_1.default.CloudWatchLogs();
|
||||
const logStreamInput = { logGroupNamePrefix: 'game-ci' };
|
||||
const logGroups = (yield ecs.describeLogGroups(logStreamInput).promise()).logGroups || [];
|
||||
cloud_runner_logger_1.default.log(`Log Groups ${logGroups.length}`);
|
||||
for (const element of logGroups) {
|
||||
if (element.creationTime === undefined) {
|
||||
cloud_runner_logger_1.default.log(`Skipping ${element.logGroupName} no createdAt date`);
|
||||
continue;
|
||||
}
|
||||
if (perResultCallback)
|
||||
yield perResultCallback(element, element);
|
||||
}
|
||||
});
|
||||
}
|
||||
static garbageCollectAws() {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
yield AwsCliCommands.cleanup(false);
|
||||
|
|
@ -2098,12 +2128,18 @@ class AwsCliCommands {
|
|||
});
|
||||
}
|
||||
}
|
||||
__decorate([
|
||||
cli_functions_repository_1.CliFunction(`aws-list-all`, `List all resources`)
|
||||
], AwsCliCommands, "awsListAll", null);
|
||||
__decorate([
|
||||
cli_functions_repository_1.CliFunction(`aws-list-stacks`, `List stacks`)
|
||||
], AwsCliCommands, "awsListStacks", null);
|
||||
__decorate([
|
||||
cli_functions_repository_1.CliFunction(`aws-list-tasks`, `List tasks`)
|
||||
], AwsCliCommands, "awsListTasks", null);
|
||||
__decorate([
|
||||
cli_functions_repository_1.CliFunction(`aws-list-log-groups`, `List tasks`)
|
||||
], AwsCliCommands, "awsListLogGroups", null);
|
||||
__decorate([
|
||||
cli_functions_repository_1.CliFunction(`aws-garbage-collect`, `garbage collect aws`)
|
||||
], AwsCliCommands, "garbageCollectAws", null);
|
||||
|
|
|
|||
File diff suppressed because one or more lines are too long
|
|
@ -1,6 +1,7 @@
|
|||
export class BaseStackFormation {
|
||||
public static readonly baseStackDecription = `Game-CI base stack`;
|
||||
public static readonly formation: string = `AWSTemplateFormatVersion: '2010-09-09'
|
||||
Description: Game-CI base stack
|
||||
Description: ${BaseStackFormation.baseStackDecription}
|
||||
Parameters:
|
||||
EnvironmentName:
|
||||
Type: String
|
||||
|
|
|
|||
|
|
@ -2,18 +2,35 @@ import AWS from 'aws-sdk';
|
|||
import { CliFunction } from '../../../../cli/cli-functions-repository';
|
||||
import Input from '../../../../input';
|
||||
import CloudRunnerLogger from '../../../services/cloud-runner-logger';
|
||||
import { BaseStackFormation } from '../cloud-formations/base-stack-formation';
|
||||
|
||||
export class AwsCliCommands {
|
||||
@CliFunction(`aws-list-all`, `List all resources`)
|
||||
static async awsListAll() {
|
||||
await AwsCliCommands.awsListStacks();
|
||||
await AwsCliCommands.awsListTasks();
|
||||
await AwsCliCommands.awsListLogGroups();
|
||||
}
|
||||
@CliFunction(`aws-list-stacks`, `List stacks`)
|
||||
static async awsListStacks(perResultCallback: any) {
|
||||
static async awsListStacks(perResultCallback: any = false) {
|
||||
process.env.AWS_REGION = Input.region;
|
||||
const CF = new AWS.CloudFormation();
|
||||
const stacks =
|
||||
(await CF.listStacks().promise()).StackSummaries?.filter((_x) => _x.StackStatus !== 'DELETE_COMPLETE') || [];
|
||||
CloudRunnerLogger.log(`DescribeStacksRequest ${stacks.length}`);
|
||||
(await CF.listStacks().promise()).StackSummaries?.filter(
|
||||
(_x) =>
|
||||
_x.StackStatus !== 'DELETE_COMPLETE' && _x.TemplateDescription !== BaseStackFormation.baseStackDecription,
|
||||
) || [];
|
||||
CloudRunnerLogger.log(`Stacks ${stacks.length}`);
|
||||
for (const element of stacks) {
|
||||
CloudRunnerLogger.log(JSON.stringify(element, undefined, 4));
|
||||
CloudRunnerLogger.log(`${element.StackName}`);
|
||||
if (perResultCallback) await perResultCallback(element);
|
||||
}
|
||||
const baseStacks =
|
||||
(await CF.listStacks().promise()).StackSummaries?.filter(
|
||||
(_x) =>
|
||||
_x.StackStatus !== 'DELETE_COMPLETE' && _x.TemplateDescription === BaseStackFormation.baseStackDecription,
|
||||
) || [];
|
||||
CloudRunnerLogger.log(`Base Stacks ${baseStacks.length}`);
|
||||
for (const element of baseStacks) {
|
||||
if (perResultCallback) await perResultCallback(element);
|
||||
}
|
||||
if (stacks === undefined) {
|
||||
|
|
@ -21,11 +38,11 @@ export class AwsCliCommands {
|
|||
}
|
||||
}
|
||||
@CliFunction(`aws-list-tasks`, `List tasks`)
|
||||
static async awsListTasks(perResultCallback: any) {
|
||||
static async awsListTasks(perResultCallback: any = false) {
|
||||
process.env.AWS_REGION = Input.region;
|
||||
CloudRunnerLogger.log(`ECS Clusters`);
|
||||
const ecs = new AWS.ECS();
|
||||
const clusters = (await ecs.listClusters().promise()).clusterArns || [];
|
||||
CloudRunnerLogger.log(`Clusters ${clusters.length}`);
|
||||
for (const element of clusters) {
|
||||
const input: AWS.ECS.ListTasksRequest = {
|
||||
cluster: element,
|
||||
|
|
@ -37,14 +54,13 @@ export class AwsCliCommands {
|
|||
if (describeList === []) {
|
||||
continue;
|
||||
}
|
||||
CloudRunnerLogger.log(`DescribeTasksRequest ${describeList.length}`);
|
||||
CloudRunnerLogger.log(`Tasks ${describeList.length}`);
|
||||
for (const taskElement of describeList) {
|
||||
if (taskElement === undefined) {
|
||||
continue;
|
||||
}
|
||||
taskElement.overrides = {};
|
||||
taskElement.attachments = [];
|
||||
CloudRunnerLogger.log(JSON.stringify(taskElement, undefined, 4));
|
||||
if (taskElement.createdAt === undefined) {
|
||||
CloudRunnerLogger.log(`Skipping ${taskElement.taskDefinitionArn} no createdAt date`);
|
||||
continue;
|
||||
|
|
@ -54,6 +70,21 @@ export class AwsCliCommands {
|
|||
}
|
||||
}
|
||||
}
|
||||
@CliFunction(`aws-list-log-groups`, `List tasks`)
|
||||
static async awsListLogGroups(perResultCallback: any = false) {
|
||||
process.env.AWS_REGION = Input.region;
|
||||
const ecs = new AWS.CloudWatchLogs();
|
||||
const logStreamInput: AWS.CloudWatchLogs.DescribeLogGroupsRequest = { logGroupNamePrefix: 'game-ci' };
|
||||
const logGroups = (await ecs.describeLogGroups(logStreamInput).promise()).logGroups || [];
|
||||
CloudRunnerLogger.log(`Log Groups ${logGroups.length}`);
|
||||
for (const element of logGroups) {
|
||||
if (element.creationTime === undefined) {
|
||||
CloudRunnerLogger.log(`Skipping ${element.logGroupName} no createdAt date`);
|
||||
continue;
|
||||
}
|
||||
if (perResultCallback) await perResultCallback(element, element);
|
||||
}
|
||||
}
|
||||
|
||||
@CliFunction(`aws-garbage-collect`, `garbage collect aws`)
|
||||
static async garbageCollectAws() {
|
||||
|
|
|
|||
Loading…
Reference in New Issue