mirror of
https://github.com/game-ci/unity-builder.git
synced 2026-05-31 13:56:13 -07:00
* Rename "Cloud Runner" to "Orchestrator" across entire codebase Breaking change: All CloudRunner classes, options, environment variables, and action.yml inputs have been renamed to Orchestrator equivalents. - Renamed src/model/cloud-runner/ directory to src/model/orchestrator/ - Renamed all cloud-runner-* files to orchestrator-* - Renamed all CloudRunner* classes to Orchestrator* (15+ classes) - Renamed all cloudRunner* properties to orchestrator* equivalents - Renamed CLOUD_RUNNER_* env vars to ORCHESTRATOR_* - Updated action.yml [CloudRunner] markers to [Orchestrator] - Updated workflow files and package.json test scripts - Updated all runtime strings (cache paths, log messages, branch refs) - Rebuilt dist/index.js No backward compatibility layer is provided. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * Remove tracked log/temp files and add to .gitignore Remove $LOG_FILE and temp/job-log.txt debug artifacts that should not be in the repository. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
76 lines
3.0 KiB
TypeScript
76 lines
3.0 KiB
TypeScript
import { DeleteStackCommand, DescribeStackResourcesCommand } from '@aws-sdk/client-cloudformation';
|
|
import { DeleteLogGroupCommand } from '@aws-sdk/client-cloudwatch-logs';
|
|
import { StopTaskCommand } from '@aws-sdk/client-ecs';
|
|
import Input from '../../../../input';
|
|
import OrchestratorLogger from '../../../services/core/orchestrator-logger';
|
|
import { TaskService } from './task-service';
|
|
import { AwsClientFactory } from '../aws-client-factory';
|
|
|
|
export class GarbageCollectionService {
|
|
static isOlderThan1day(date: Date) {
|
|
const ageDate = new Date(date.getTime() - Date.now());
|
|
|
|
return ageDate.getDay() > 0;
|
|
}
|
|
|
|
public static async cleanup(deleteResources = false, OneDayOlderOnly: boolean = false) {
|
|
process.env.AWS_REGION = Input.region;
|
|
const CF = AwsClientFactory.getCloudFormation();
|
|
const ecs = AwsClientFactory.getECS();
|
|
const cwl = AwsClientFactory.getCloudWatchLogs();
|
|
const taskDefinitionsInUse = new Array();
|
|
const tasks = await TaskService.getTasks();
|
|
|
|
for (const task of tasks) {
|
|
const { taskElement, element } = task;
|
|
taskDefinitionsInUse.push(taskElement.taskDefinitionArn);
|
|
if (deleteResources && (!OneDayOlderOnly || GarbageCollectionService.isOlderThan1day(taskElement.createdAt!))) {
|
|
OrchestratorLogger.log(`Stopping task ${taskElement.containers?.[0].name}`);
|
|
await ecs.send(new StopTaskCommand({ task: taskElement.taskArn || '', cluster: element }));
|
|
}
|
|
}
|
|
|
|
const jobStacks = await TaskService.getCloudFormationJobStacks();
|
|
for (const element of jobStacks) {
|
|
if (
|
|
(await CF.send(new DescribeStackResourcesCommand({ StackName: element.StackName }))).StackResources?.some(
|
|
(x) => x.ResourceType === 'AWS::ECS::TaskDefinition' && taskDefinitionsInUse.includes(x.PhysicalResourceId),
|
|
)
|
|
) {
|
|
OrchestratorLogger.log(`Skipping ${element.StackName} - active task was running not deleting`);
|
|
|
|
return;
|
|
}
|
|
|
|
if (
|
|
deleteResources &&
|
|
(!OneDayOlderOnly || (element.CreationTime && GarbageCollectionService.isOlderThan1day(element.CreationTime)))
|
|
) {
|
|
if (element.StackName === 'game-ci' || element.TemplateDescription === 'Game-CI base stack') {
|
|
OrchestratorLogger.log(`Skipping ${element.StackName} ignore list`);
|
|
|
|
return;
|
|
}
|
|
|
|
OrchestratorLogger.log(`Deleting ${element.StackName}`);
|
|
await CF.send(new DeleteStackCommand({ StackName: element.StackName }));
|
|
}
|
|
}
|
|
const logGroups = await TaskService.getLogGroups();
|
|
for (const element of logGroups) {
|
|
if (
|
|
deleteResources &&
|
|
(!OneDayOlderOnly || GarbageCollectionService.isOlderThan1day(new Date(element.creationTime!)))
|
|
) {
|
|
OrchestratorLogger.log(`Deleting ${element.logGroupName}`);
|
|
await cwl.send(new DeleteLogGroupCommand({ logGroupName: element.logGroupName || '' }));
|
|
}
|
|
}
|
|
|
|
const locks = await TaskService.getLocks();
|
|
for (const element of locks) {
|
|
OrchestratorLogger.log(`Lock: ${element.Key}`);
|
|
}
|
|
}
|
|
}
|