fix
parent
945dec774c
commit
a8deca8551
|
|
@ -3,9 +3,15 @@ import {
|
||||||
DescribeStacksCommand,
|
DescribeStacksCommand,
|
||||||
ListStacksCommand,
|
ListStacksCommand,
|
||||||
} from '@aws-sdk/client-cloudformation';
|
} from '@aws-sdk/client-cloudformation';
|
||||||
import { DescribeLogGroupsCommand } from '@aws-sdk/client-cloudwatch-logs';
|
import type { StackSummary } from '@aws-sdk/client-cloudformation';
|
||||||
|
import {
|
||||||
|
DescribeLogGroupsCommand,
|
||||||
|
DescribeLogGroupsCommandInput,
|
||||||
|
} from '@aws-sdk/client-cloudwatch-logs';
|
||||||
|
import type { LogGroup } from '@aws-sdk/client-cloudwatch-logs';
|
||||||
import { DescribeTasksCommand, ListClustersCommand, ListTasksCommand } from '@aws-sdk/client-ecs';
|
import { DescribeTasksCommand, ListClustersCommand, ListTasksCommand } from '@aws-sdk/client-ecs';
|
||||||
import { ListObjectsCommand } from '@aws-sdk/client-s3';
|
import type { Task } from '@aws-sdk/client-ecs';
|
||||||
|
import { ListObjectsV2Command } from '@aws-sdk/client-s3';
|
||||||
import Input from '../../../../input';
|
import Input from '../../../../input';
|
||||||
import CloudRunnerLogger from '../../../services/core/cloud-runner-logger';
|
import CloudRunnerLogger from '../../../services/core/cloud-runner-logger';
|
||||||
import { BaseStackFormation } from '../cloud-formations/base-stack-formation';
|
import { BaseStackFormation } from '../cloud-formations/base-stack-formation';
|
||||||
|
|
@ -25,8 +31,8 @@ export class TaskService {
|
||||||
|
|
||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
public static async getCloudFormationJobStacks() {
|
public static async getCloudFormationJobStacks(): Promise<StackSummary[]> {
|
||||||
const result: any[] = [];
|
const result: StackSummary[] = [];
|
||||||
CloudRunnerLogger.log(``);
|
CloudRunnerLogger.log(``);
|
||||||
CloudRunnerLogger.log(`List Cloud Formation Stacks`);
|
CloudRunnerLogger.log(`List Cloud Formation Stacks`);
|
||||||
process.env.AWS_REGION = Input.region;
|
process.env.AWS_REGION = Input.region;
|
||||||
|
|
@ -77,21 +83,36 @@ export class TaskService {
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
public static async getTasks() {
|
public static async getTasks(): Promise<{ taskElement: Task; element: string }[]> {
|
||||||
const result: { taskElement: any; element: string }[] = [];
|
const result: { taskElement: Task; element: string }[] = [];
|
||||||
CloudRunnerLogger.log(``);
|
CloudRunnerLogger.log(``);
|
||||||
CloudRunnerLogger.log(`List Tasks`);
|
CloudRunnerLogger.log(`List Tasks`);
|
||||||
process.env.AWS_REGION = Input.region;
|
process.env.AWS_REGION = Input.region;
|
||||||
const ecs = AwsClientFactory.getECS();
|
const ecs = AwsClientFactory.getECS();
|
||||||
const clusters = (await ecs.send(new ListClustersCommand({}))).clusterArns || [];
|
const clusters: string[] = [];
|
||||||
|
{
|
||||||
|
let nextToken: string | undefined;
|
||||||
|
do {
|
||||||
|
const clusterResponse = await ecs.send(new ListClustersCommand({ nextToken }));
|
||||||
|
clusters.push(...(clusterResponse.clusterArns ?? []));
|
||||||
|
nextToken = clusterResponse.nextToken;
|
||||||
|
} while (nextToken);
|
||||||
|
}
|
||||||
CloudRunnerLogger.log(`Task Clusters ${clusters.length}`);
|
CloudRunnerLogger.log(`Task Clusters ${clusters.length}`);
|
||||||
for (const element of clusters) {
|
for (const element of clusters) {
|
||||||
const input = {
|
const taskArns: string[] = [];
|
||||||
cluster: element,
|
{
|
||||||
};
|
let nextToken: string | undefined;
|
||||||
const list = (await ecs.send(new ListTasksCommand(input))).taskArns || [];
|
do {
|
||||||
if (list.length > 0) {
|
const taskResponse = await ecs.send(
|
||||||
const describeInput = { tasks: list, cluster: element };
|
new ListTasksCommand({ cluster: element, nextToken }),
|
||||||
|
);
|
||||||
|
taskArns.push(...(taskResponse.taskArns ?? []));
|
||||||
|
nextToken = taskResponse.nextToken;
|
||||||
|
} while (nextToken);
|
||||||
|
}
|
||||||
|
if (taskArns.length > 0) {
|
||||||
|
const describeInput = { tasks: taskArns, cluster: element };
|
||||||
const describeList = (await ecs.send(new DescribeTasksCommand(describeInput))).tasks || [];
|
const describeList = (await ecs.send(new DescribeTasksCommand(describeInput))).tasks || [];
|
||||||
if (describeList.length === 0) {
|
if (describeList.length === 0) {
|
||||||
CloudRunnerLogger.log(`No Tasks`);
|
CloudRunnerLogger.log(`No Tasks`);
|
||||||
|
|
@ -102,8 +123,6 @@ export class TaskService {
|
||||||
if (taskElement === undefined) {
|
if (taskElement === undefined) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
taskElement.overrides = {};
|
|
||||||
taskElement.attachments = [];
|
|
||||||
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;
|
||||||
|
|
@ -148,18 +167,21 @@ export class TaskService {
|
||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public static async getLogGroups() {
|
public static async getLogGroups(): Promise<LogGroup[]> {
|
||||||
const result: any[] = [];
|
const result: LogGroup[] = [];
|
||||||
process.env.AWS_REGION = Input.region;
|
process.env.AWS_REGION = Input.region;
|
||||||
const ecs = AwsClientFactory.getCloudWatchLogs();
|
const cwl = AwsClientFactory.getCloudWatchLogs();
|
||||||
let logStreamInput: any = {
|
let logStreamInput: DescribeLogGroupsCommandInput = {
|
||||||
/* logGroupNamePrefix: 'game-ci' */
|
/* logGroupNamePrefix: 'game-ci' */
|
||||||
};
|
};
|
||||||
let logGroupsDescribe = await ecs.send(new DescribeLogGroupsCommand(logStreamInput));
|
let logGroupsDescribe = await cwl.send(new DescribeLogGroupsCommand(logStreamInput));
|
||||||
const logGroups = logGroupsDescribe.logGroups || [];
|
const logGroups = logGroupsDescribe.logGroups || [];
|
||||||
while (logGroupsDescribe.nextToken) {
|
while (logGroupsDescribe.nextToken) {
|
||||||
logStreamInput = { /* logGroupNamePrefix: 'game-ci',*/ nextToken: logGroupsDescribe.nextToken };
|
logStreamInput = {
|
||||||
logGroupsDescribe = await ecs.send(new DescribeLogGroupsCommand(logStreamInput));
|
/* logGroupNamePrefix: 'game-ci',*/
|
||||||
|
nextToken: logGroupsDescribe.nextToken,
|
||||||
|
};
|
||||||
|
logGroupsDescribe = await cwl.send(new DescribeLogGroupsCommand(logStreamInput));
|
||||||
logGroups.push(...(logGroupsDescribe?.logGroups || []));
|
logGroups.push(...(logGroupsDescribe?.logGroups || []));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -181,10 +203,10 @@ export class TaskService {
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
public static async getLocks() {
|
public static async getLocks(): Promise<Array<{ Key: string }>> {
|
||||||
process.env.AWS_REGION = Input.region;
|
process.env.AWS_REGION = Input.region;
|
||||||
if (CloudRunner.buildParameters.storageProvider === 'rclone') {
|
if (CloudRunner.buildParameters.storageProvider === 'rclone') {
|
||||||
const objects = await (SharedWorkspaceLocking as any).listObjects('');
|
const objects = await (SharedWorkspaceLocking as { listObjects(prefix: string): Promise<string[]> }).listObjects('');
|
||||||
return objects.map((x: string) => ({ Key: x }));
|
return objects.map((x: string) => ({ Key: x }));
|
||||||
}
|
}
|
||||||
const s3 = AwsClientFactory.getS3();
|
const s3 = AwsClientFactory.getS3();
|
||||||
|
|
@ -192,8 +214,8 @@ export class TaskService {
|
||||||
Bucket: CloudRunner.buildParameters.awsStackName,
|
Bucket: CloudRunner.buildParameters.awsStackName,
|
||||||
};
|
};
|
||||||
|
|
||||||
const results = await s3.send(new ListObjectsCommand(listRequest));
|
const results = await s3.send(new ListObjectsV2Command(listRequest));
|
||||||
|
|
||||||
return results.Contents || [];
|
return (results.Contents || []).map((obj) => ({ Key: obj.Key || '' }));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue