2022-11-07 20:41:00 +00:00
|
|
|
import AWS from 'aws-sdk';
|
|
|
|
import Input from '../../../../input';
|
|
|
|
import CloudRunnerLogger from '../../../services/cloud-runner-logger';
|
|
|
|
import { BaseStackFormation } from '../cloud-formations/base-stack-formation';
|
|
|
|
import AwsTaskRunner from '../aws-task-runner';
|
2022-11-17 18:59:33 +00:00
|
|
|
import { ListObjectsRequest } from 'aws-sdk/clients/s3';
|
Cloud runner develop - better parameterization of s3 usage, improved async workflow and GC, github checks early integration (#479)
* custom steps may leave value undefined, will be pulled from env vars
* custom steps may leave value undefined, will be pulled from env vars
* custom steps may leave value undefined, will be pulled from env vars
* add 3 new premade steps, steam-deploy-client, steam-deploy-project, aws-s3-pull-build
* fix
* fix
* fix
* continue building async-workflow support
* test checks
* test checks
* test checks
* move github checks within build workflow
* async workflow test
* async workflow test
* async workflow test
* async workflow test
* async workflow test
* async workflow test
* async workflow test
* async workflow test for aws only
* async workflow test for aws only
* async workflow test for aws only
* async workflow test for aws only
* cleanup logging
* disable lz4 compression by default
* disable lz4 compression by default
* AWS BASE STACK for tests
* AWS BASE STACK for tests
* AWS BASE STACK for tests
* AWS BASE STACK for tests
* AWS BASE STACK for tests
* AWS BASE STACK for tests
* disable lz4 compression by default
* disable lz4 compression by default
* Update github check with aws log
* Update github check with aws log
* Update github check with aws log
* Update github check with aws log
* Update github check with aws log
* Update github check with aws log
* Update github check with aws log
* Update github check with aws log
* Update github check with aws log
* Update github check with aws log
* Update github check with aws log
* Update github check with aws log
* Update github check with aws log
* Update github check with aws log
* kinesis and subscription filter for logs creation skipped when watchToEnd false
* kinesis and subscription filter for logs creation skipped when watchToEnd false
* kinesis and subscription filter for logs creation skipped when watchToEnd false
* kinesis and subscription filter for logs creation skipped when watchToEnd false
* kinesis and subscription filter for logs creation skipped when watchToEnd false
* kinesis and subscription filter for logs creation skipped when watchToEnd false
* kinesis and subscription filter for logs creation skipped when watchToEnd false
* kinesis and subscription filter for logs creation skipped when watchToEnd false
* kinesis and subscription filter for logs creation skipped when watchToEnd false
* kinesis and subscription filter for logs creation skipped when watchToEnd false
* cleanup local pipeline, log aws formation
* cleanup local pipeline, log aws formation
* cleanup local pipeline, log aws formation
* cleanup local pipeline, log aws formation
* cleanup local pipeline, log aws formation
* cleanup local pipeline, log aws formation
* cleanup local pipeline, log aws formation
* cleanup local pipeline, log aws formation
* cleanup local pipeline, log aws formation
* cleanup local pipeline, log aws formation
* cleanup local pipeline, log aws formation
* cleanup local pipeline, log aws formation
* cleanup local pipeline, log aws formation
* cleanup local pipeline, log aws formation
* cleanup local pipeline, log aws formation
* cleanup local pipeline, log aws formation
* cleanup local pipeline, log aws formation
* cleanup local pipeline, log aws formation
* cleanup local pipeline, log aws formation
* cleanup local pipeline, log aws formation
* cleanup local pipeline, log aws formation
* async pipeline
* async pipeline
* async pipeline
* async pipeline
* async pipeline
* async pipeline
* async pipeline
* async pipeline
* async pipeline
* async pipeline
* async pipeline
* async pipeline
* async pipeline
* async pipeline
* async pipeline
* async pipeline
* async pipeline
* async pipeline
* async pipeline
* async pipeline
* async pipeline
* async pipeline
* async pipeline
* async pipeline
* async pipeline
* async pipeline
* async pipeline
* workflow
* workflow
* workflow
* workflow
* workflow
* workflow
* workflow
* workflow
* parameterize s3
* parameterize s3
* parameterize s3
* parameterize s3
* parameterize s3
* parameterize s3
* parameterize s3
* parameterize s3
* parameterize s3
* parameterize s3
* parameterize s3
* parameterize s3
* parameterize s3
* parameterize s3
* parameterize s3
* parameterize s3
* parameterize s3
* parameterize s3
* parameterize s3
* parameterize s3
* parameterize s3
* parameterize s3
* parameterize s3
* parameterize s3
* parameterize s3
* parameterize s3
* parameterize s3
* parameterize s3
* parameterize s3
* parameterize s3
* parameterize s3
* parameterize s3
* parameterize s3
* parameterize s3
* parameterize s3
* parameterize s3
* parameterize s3
* parameterize s3
* parameterize s3
* parameterize s3
* parameterize s3
* parameterize s3
* parameterize s3
* parameterize s3
* parameterize s3
* parameterize s3
* parameterize s3
* parameterize s3
* parameterize s3
2023-01-20 17:40:57 +00:00
|
|
|
import CloudRunner from '../../../cloud-runner';
|
2022-11-07 20:41:00 +00:00
|
|
|
|
|
|
|
export class TaskService {
|
|
|
|
static async watch() {
|
|
|
|
// eslint-disable-next-line no-unused-vars
|
|
|
|
const { output, shouldCleanup } = await AwsTaskRunner.streamLogsUntilTaskStops(
|
|
|
|
process.env.cluster || ``,
|
|
|
|
process.env.taskArn || ``,
|
|
|
|
process.env.streamName || ``,
|
|
|
|
);
|
|
|
|
|
|
|
|
return output;
|
|
|
|
}
|
2022-11-17 18:59:33 +00:00
|
|
|
public static async getCloudFormationJobStacks() {
|
|
|
|
const result: any[] = [];
|
|
|
|
CloudRunnerLogger.log(``);
|
|
|
|
CloudRunnerLogger.log(`List Cloud Formation Stacks`);
|
2022-11-07 20:41:00 +00:00
|
|
|
process.env.AWS_REGION = Input.region;
|
|
|
|
const CF = new AWS.CloudFormation();
|
|
|
|
const stacks =
|
|
|
|
(await CF.listStacks().promise()).StackSummaries?.filter(
|
2022-11-17 18:59:33 +00:00
|
|
|
(_x) =>
|
|
|
|
_x.StackStatus !== 'DELETE_COMPLETE' && _x.TemplateDescription !== BaseStackFormation.baseStackDecription,
|
2022-11-07 20:41:00 +00:00
|
|
|
) || [];
|
2022-11-17 18:59:33 +00:00
|
|
|
CloudRunnerLogger.log(``);
|
|
|
|
CloudRunnerLogger.log(`Cloud Formation Stacks ${stacks.length}`);
|
2022-11-07 20:41:00 +00:00
|
|
|
for (const element of stacks) {
|
|
|
|
const ageDate: Date = new Date(Date.now() - element.CreationTime.getTime());
|
|
|
|
|
|
|
|
CloudRunnerLogger.log(
|
|
|
|
`Task Stack ${element.StackName} - Age D${Math.floor(
|
|
|
|
ageDate.getHours() / 24,
|
|
|
|
)} H${ageDate.getHours()} M${ageDate.getMinutes()}`,
|
|
|
|
);
|
2022-11-17 18:59:33 +00:00
|
|
|
result.push(element);
|
2022-11-07 20:41:00 +00:00
|
|
|
}
|
|
|
|
const baseStacks =
|
|
|
|
(await CF.listStacks().promise()).StackSummaries?.filter(
|
|
|
|
(_x) =>
|
|
|
|
_x.StackStatus !== 'DELETE_COMPLETE' && _x.TemplateDescription === BaseStackFormation.baseStackDecription,
|
|
|
|
) || [];
|
2022-11-17 18:59:33 +00:00
|
|
|
CloudRunnerLogger.log(``);
|
2022-11-07 20:41:00 +00:00
|
|
|
CloudRunnerLogger.log(`Base Stacks ${baseStacks.length}`);
|
|
|
|
for (const element of baseStacks) {
|
|
|
|
const ageDate: Date = new Date(Date.now() - element.CreationTime.getTime());
|
|
|
|
|
|
|
|
CloudRunnerLogger.log(
|
|
|
|
`Task Stack ${element.StackName} - Age D${Math.floor(
|
|
|
|
ageDate.getHours() / 24,
|
|
|
|
)} H${ageDate.getHours()} M${ageDate.getMinutes()}`,
|
|
|
|
);
|
2022-11-17 18:59:33 +00:00
|
|
|
result.push(element);
|
2022-11-07 20:41:00 +00:00
|
|
|
}
|
2022-11-17 18:59:33 +00:00
|
|
|
CloudRunnerLogger.log(``);
|
|
|
|
|
|
|
|
return result;
|
2022-11-07 20:41:00 +00:00
|
|
|
}
|
2022-11-17 18:59:33 +00:00
|
|
|
public static async getTasks() {
|
|
|
|
const result: any[] = [];
|
|
|
|
CloudRunnerLogger.log(``);
|
2022-11-08 09:37:16 +00:00
|
|
|
CloudRunnerLogger.log(`List Tasks`);
|
2022-11-07 20:41:00 +00:00
|
|
|
process.env.AWS_REGION = Input.region;
|
|
|
|
const ecs = new AWS.ECS();
|
|
|
|
const clusters = (await ecs.listClusters().promise()).clusterArns || [];
|
2022-11-17 18:59:33 +00:00
|
|
|
CloudRunnerLogger.log(`Task Clusters ${clusters.length}`);
|
2022-11-07 20:41:00 +00:00
|
|
|
for (const element of clusters) {
|
|
|
|
const input: AWS.ECS.ListTasksRequest = {
|
|
|
|
cluster: element,
|
|
|
|
};
|
|
|
|
|
|
|
|
const list = (await ecs.listTasks(input).promise()).taskArns || [];
|
|
|
|
if (list.length > 0) {
|
|
|
|
const describeInput: AWS.ECS.DescribeTasksRequest = { tasks: list, cluster: element };
|
|
|
|
const describeList = (await ecs.describeTasks(describeInput).promise()).tasks || [];
|
|
|
|
if (describeList.length === 0) {
|
2022-11-17 18:59:33 +00:00
|
|
|
CloudRunnerLogger.log(`No Tasks`);
|
2022-11-07 20:41:00 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
CloudRunnerLogger.log(`Tasks ${describeList.length}`);
|
|
|
|
for (const taskElement of describeList) {
|
|
|
|
if (taskElement === undefined) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
taskElement.overrides = {};
|
|
|
|
taskElement.attachments = [];
|
|
|
|
if (taskElement.createdAt === undefined) {
|
|
|
|
CloudRunnerLogger.log(`Skipping ${taskElement.taskDefinitionArn} no createdAt date`);
|
|
|
|
continue;
|
|
|
|
}
|
2022-11-17 18:59:33 +00:00
|
|
|
result.push({ taskElement, element });
|
2022-11-07 20:41:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-11-17 18:59:33 +00:00
|
|
|
CloudRunnerLogger.log(``);
|
2022-11-07 20:41:00 +00:00
|
|
|
|
2022-11-17 18:59:33 +00:00
|
|
|
return result;
|
2022-11-07 20:41:00 +00:00
|
|
|
}
|
|
|
|
public static async awsDescribeJob(job: string) {
|
|
|
|
process.env.AWS_REGION = Input.region;
|
|
|
|
const CF = new AWS.CloudFormation();
|
|
|
|
const stack = (await CF.listStacks().promise()).StackSummaries?.find((_x) => _x.StackName === job) || undefined;
|
|
|
|
const stackInfo = (await CF.describeStackResources({ StackName: job }).promise()) || undefined;
|
|
|
|
const stackInfo2 = (await CF.describeStacks({ StackName: job }).promise()) || undefined;
|
|
|
|
if (stack === undefined) {
|
|
|
|
throw new Error('stack not defined');
|
|
|
|
}
|
|
|
|
const ageDate: Date = new Date(Date.now() - stack.CreationTime.getTime());
|
|
|
|
const message = `
|
|
|
|
Task Stack ${stack.StackName}
|
|
|
|
Age D${Math.floor(ageDate.getHours() / 24)} H${ageDate.getHours()} M${ageDate.getMinutes()}
|
|
|
|
${JSON.stringify(stack, undefined, 4)}
|
|
|
|
${JSON.stringify(stackInfo, undefined, 4)}
|
|
|
|
${JSON.stringify(stackInfo2, undefined, 4)}
|
|
|
|
`;
|
|
|
|
CloudRunnerLogger.log(message);
|
|
|
|
|
|
|
|
return message;
|
|
|
|
}
|
2022-11-17 18:59:33 +00:00
|
|
|
public static async getLogGroups() {
|
|
|
|
const result: any[] = [];
|
|
|
|
process.env.AWS_REGION = Input.region;
|
|
|
|
const ecs = new AWS.CloudWatchLogs();
|
|
|
|
let logStreamInput: AWS.CloudWatchLogs.DescribeLogGroupsRequest = {
|
|
|
|
/* logGroupNamePrefix: 'game-ci' */
|
|
|
|
};
|
|
|
|
let logGroupsDescribe = await ecs.describeLogGroups(logStreamInput).promise();
|
|
|
|
const logGroups = logGroupsDescribe.logGroups || [];
|
|
|
|
while (logGroupsDescribe.nextToken) {
|
|
|
|
logStreamInput = { /* logGroupNamePrefix: 'game-ci',*/ nextToken: logGroupsDescribe.nextToken };
|
|
|
|
logGroupsDescribe = await ecs.describeLogGroups(logStreamInput).promise();
|
|
|
|
logGroups.push(...(logGroupsDescribe?.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;
|
|
|
|
}
|
|
|
|
const ageDate: Date = new Date(Date.now() - element.creationTime);
|
|
|
|
|
|
|
|
CloudRunnerLogger.log(
|
|
|
|
`Task Stack ${element.logGroupName} - Age D${Math.floor(
|
|
|
|
ageDate.getHours() / 24,
|
|
|
|
)} H${ageDate.getHours()} M${ageDate.getMinutes()}`,
|
|
|
|
);
|
|
|
|
result.push(element);
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
public static async getLocks() {
|
|
|
|
process.env.AWS_REGION = Input.region;
|
|
|
|
const s3 = new AWS.S3();
|
|
|
|
const listRequest: ListObjectsRequest = {
|
Cloud runner develop - better parameterization of s3 usage, improved async workflow and GC, github checks early integration (#479)
* custom steps may leave value undefined, will be pulled from env vars
* custom steps may leave value undefined, will be pulled from env vars
* custom steps may leave value undefined, will be pulled from env vars
* add 3 new premade steps, steam-deploy-client, steam-deploy-project, aws-s3-pull-build
* fix
* fix
* fix
* continue building async-workflow support
* test checks
* test checks
* test checks
* move github checks within build workflow
* async workflow test
* async workflow test
* async workflow test
* async workflow test
* async workflow test
* async workflow test
* async workflow test
* async workflow test for aws only
* async workflow test for aws only
* async workflow test for aws only
* async workflow test for aws only
* cleanup logging
* disable lz4 compression by default
* disable lz4 compression by default
* AWS BASE STACK for tests
* AWS BASE STACK for tests
* AWS BASE STACK for tests
* AWS BASE STACK for tests
* AWS BASE STACK for tests
* AWS BASE STACK for tests
* disable lz4 compression by default
* disable lz4 compression by default
* Update github check with aws log
* Update github check with aws log
* Update github check with aws log
* Update github check with aws log
* Update github check with aws log
* Update github check with aws log
* Update github check with aws log
* Update github check with aws log
* Update github check with aws log
* Update github check with aws log
* Update github check with aws log
* Update github check with aws log
* Update github check with aws log
* Update github check with aws log
* kinesis and subscription filter for logs creation skipped when watchToEnd false
* kinesis and subscription filter for logs creation skipped when watchToEnd false
* kinesis and subscription filter for logs creation skipped when watchToEnd false
* kinesis and subscription filter for logs creation skipped when watchToEnd false
* kinesis and subscription filter for logs creation skipped when watchToEnd false
* kinesis and subscription filter for logs creation skipped when watchToEnd false
* kinesis and subscription filter for logs creation skipped when watchToEnd false
* kinesis and subscription filter for logs creation skipped when watchToEnd false
* kinesis and subscription filter for logs creation skipped when watchToEnd false
* kinesis and subscription filter for logs creation skipped when watchToEnd false
* cleanup local pipeline, log aws formation
* cleanup local pipeline, log aws formation
* cleanup local pipeline, log aws formation
* cleanup local pipeline, log aws formation
* cleanup local pipeline, log aws formation
* cleanup local pipeline, log aws formation
* cleanup local pipeline, log aws formation
* cleanup local pipeline, log aws formation
* cleanup local pipeline, log aws formation
* cleanup local pipeline, log aws formation
* cleanup local pipeline, log aws formation
* cleanup local pipeline, log aws formation
* cleanup local pipeline, log aws formation
* cleanup local pipeline, log aws formation
* cleanup local pipeline, log aws formation
* cleanup local pipeline, log aws formation
* cleanup local pipeline, log aws formation
* cleanup local pipeline, log aws formation
* cleanup local pipeline, log aws formation
* cleanup local pipeline, log aws formation
* cleanup local pipeline, log aws formation
* async pipeline
* async pipeline
* async pipeline
* async pipeline
* async pipeline
* async pipeline
* async pipeline
* async pipeline
* async pipeline
* async pipeline
* async pipeline
* async pipeline
* async pipeline
* async pipeline
* async pipeline
* async pipeline
* async pipeline
* async pipeline
* async pipeline
* async pipeline
* async pipeline
* async pipeline
* async pipeline
* async pipeline
* async pipeline
* async pipeline
* async pipeline
* workflow
* workflow
* workflow
* workflow
* workflow
* workflow
* workflow
* workflow
* parameterize s3
* parameterize s3
* parameterize s3
* parameterize s3
* parameterize s3
* parameterize s3
* parameterize s3
* parameterize s3
* parameterize s3
* parameterize s3
* parameterize s3
* parameterize s3
* parameterize s3
* parameterize s3
* parameterize s3
* parameterize s3
* parameterize s3
* parameterize s3
* parameterize s3
* parameterize s3
* parameterize s3
* parameterize s3
* parameterize s3
* parameterize s3
* parameterize s3
* parameterize s3
* parameterize s3
* parameterize s3
* parameterize s3
* parameterize s3
* parameterize s3
* parameterize s3
* parameterize s3
* parameterize s3
* parameterize s3
* parameterize s3
* parameterize s3
* parameterize s3
* parameterize s3
* parameterize s3
* parameterize s3
* parameterize s3
* parameterize s3
* parameterize s3
* parameterize s3
* parameterize s3
* parameterize s3
* parameterize s3
* parameterize s3
2023-01-20 17:40:57 +00:00
|
|
|
Bucket: CloudRunner.buildParameters.awsBaseStackName,
|
2022-11-17 18:59:33 +00:00
|
|
|
};
|
|
|
|
const results = await s3.listObjects(listRequest).promise();
|
|
|
|
|
|
|
|
return results.Contents || [];
|
|
|
|
}
|
2022-11-07 20:41:00 +00:00
|
|
|
}
|