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