This commit is contained in:
frostebite
2026-01-26 09:06:25 +00:00
parent ecf83cc928
commit e10e61839e
11 changed files with 100 additions and 83 deletions

View File

@@ -1,5 +1,4 @@
import CloudRunnerLogger from '../../services/core/cloud-runner-logger';
import CloudRunnerOptions from '../../options/cloud-runner-options';
import * as core from '@actions/core';
import {
CloudFormation,
@@ -21,37 +20,14 @@ import {
import { BaseStackFormation } from './cloud-formations/base-stack-formation';
import crypto from 'node:crypto';
const LOCALSTACK_ENDPOINT_PATTERN = /localstack|localhost|127\.0\.0\.1/i;
const LOCALSTACK_WAIT_TIME_SECONDS = 600;
const DEFAULT_STACK_WAIT_TIME_SECONDS = 200;
const DEFAULT_STACK_WAIT_TIME_SECONDS = 600;
function detectLocalStackEnvironment(): boolean {
const endpoints = [
process.env.AWS_ENDPOINT,
process.env.AWS_S3_ENDPOINT,
process.env.AWS_CLOUD_FORMATION_ENDPOINT,
process.env.AWS_ECS_ENDPOINT,
process.env.AWS_KINESIS_ENDPOINT,
process.env.AWS_CLOUD_WATCH_LOGS_ENDPOINT,
CloudRunnerOptions.awsEndpoint,
CloudRunnerOptions.awsS3Endpoint,
CloudRunnerOptions.awsCloudFormationEndpoint,
CloudRunnerOptions.awsEcsEndpoint,
CloudRunnerOptions.awsKinesisEndpoint,
CloudRunnerOptions.awsCloudWatchLogsEndpoint,
]
.filter((endpoint) => endpoint !== undefined && endpoint !== '')
.join(' ');
return LOCALSTACK_ENDPOINT_PATTERN.test(endpoints);
}
function determineStackWaitTime(isLocalStack: boolean): number {
function getStackWaitTime(): number {
const overrideValue = Number(process.env.CLOUD_RUNNER_AWS_STACK_WAIT_TIME ?? '');
if (!Number.isNaN(overrideValue) && overrideValue > 0) {
return overrideValue;
}
return isLocalStack ? LOCALSTACK_WAIT_TIME_SECONDS : DEFAULT_STACK_WAIT_TIME_SECONDS;
return DEFAULT_STACK_WAIT_TIME_SECONDS;
}
export class AWSBaseStack {
@@ -62,14 +38,7 @@ export class AWSBaseStack {
async setupBaseStack(CF: CloudFormation) {
const baseStackName = this.baseStackName;
const isLocalStack = detectLocalStackEnvironment();
const stackWaitTimeSeconds = determineStackWaitTime(isLocalStack);
if (isLocalStack) {
CloudRunnerLogger.log(
`LocalStack endpoints detected; will wait up to ${stackWaitTimeSeconds}s for CloudFormation transitions`,
);
}
const stackWaitTimeSeconds = getStackWaitTime();
const baseStack = BaseStackFormation.formation;
@@ -101,7 +70,13 @@ export class AWSBaseStack {
const stacks = await CF.send(
new ListStacksCommand({
StackStatusFilter: ['CREATE_IN_PROGRESS', 'UPDATE_IN_PROGRESS', 'UPDATE_COMPLETE', 'CREATE_COMPLETE', 'ROLLBACK_COMPLETE'],
StackStatusFilter: [
'CREATE_IN_PROGRESS',
'UPDATE_IN_PROGRESS',
'UPDATE_COMPLETE',
'CREATE_COMPLETE',
'ROLLBACK_COMPLETE',
],
}),
);
const stackNames = stacks.StackSummaries?.map((x) => x.StackName) || [];

View File

@@ -18,6 +18,16 @@ import { CleanupCronFormation } from './cloud-formations/cleanup-cron-formation'
import CloudRunnerOptions from '../../options/cloud-runner-options';
import { TaskDefinitionFormation } from './cloud-formations/task-definition-formation';
const DEFAULT_STACK_WAIT_TIME_SECONDS = 600;
function getStackWaitTime(): number {
const overrideValue = Number(process.env.CLOUD_RUNNER_AWS_STACK_WAIT_TIME ?? '');
if (!Number.isNaN(overrideValue) && overrideValue > 0) {
return overrideValue;
}
return DEFAULT_STACK_WAIT_TIME_SECONDS;
}
export class AWSJobStack {
private baseStackName: string;
constructor(baseStackName: string) {
@@ -148,12 +158,15 @@ export class AWSJobStack {
Parameters: parameters,
};
try {
CloudRunnerLogger.log(`Creating job aws formation ${taskDefStackName}`);
const stackWaitTimeSeconds = getStackWaitTime();
CloudRunnerLogger.log(
`Creating job aws formation ${taskDefStackName} (waiting up to ${stackWaitTimeSeconds}s for completion)`,
);
await CF.send(new CreateStackCommand(createStackInput));
await waitUntilStackCreateComplete(
{
client: CF,
maxWaitTime: 200,
maxWaitTime: stackWaitTimeSeconds,
},
{ StackName: taskDefStackName },
);

View File

@@ -17,6 +17,16 @@ import CloudRunnerOptions from '../../options/cloud-runner-options';
import { AwsClientFactory } from './aws-client-factory';
import ResourceTracking from '../../services/core/resource-tracking';
const DEFAULT_STACK_WAIT_TIME_SECONDS = 600;
function getStackWaitTime(): number {
const overrideValue = Number(process.env.CLOUD_RUNNER_AWS_STACK_WAIT_TIME ?? '');
if (!Number.isNaN(overrideValue) && overrideValue > 0) {
return overrideValue;
}
return DEFAULT_STACK_WAIT_TIME_SECONDS;
}
class AWSBuildEnvironment implements ProviderInterface {
private baseStackName: string;
@@ -133,7 +143,8 @@ class AWSBuildEnvironment implements ProviderInterface {
}
async cleanupResources(CF: CloudFormation, taskDef: CloudRunnerAWSTaskDef) {
CloudRunnerLogger.log('Cleanup starting');
const stackWaitTimeSeconds = getStackWaitTime();
CloudRunnerLogger.log(`Cleanup starting (waiting up to ${stackWaitTimeSeconds}s for stack deletion)`);
await CF.send(new DeleteStackCommand({ StackName: taskDef.taskDefStackName }));
if (CloudRunnerOptions.useCleanupCron) {
await CF.send(new DeleteStackCommand({ StackName: `${taskDef.taskDefStackName}-cleanup` }));
@@ -142,7 +153,7 @@ class AWSBuildEnvironment implements ProviderInterface {
await waitUntilStackDeleteComplete(
{
client: CF,
maxWaitTime: 200,
maxWaitTime: stackWaitTimeSeconds,
},
{
StackName: taskDef.taskDefStackName,
@@ -151,7 +162,7 @@ class AWSBuildEnvironment implements ProviderInterface {
await waitUntilStackDeleteComplete(
{
client: CF,
maxWaitTime: 200,
maxWaitTime: stackWaitTimeSeconds,
},
{
StackName: `${taskDef.taskDefStackName}-cleanup`,

View File

@@ -174,9 +174,7 @@ class Kubernetes implements ProviderInterface {
for (const NODE of K3D_NODE_CONTAINERS) {
// Remove all stopped containers (this frees runtime space but keeps images)
cleanupCommands.push(
`docker exec ${NODE} sh -c "crictl rm --all 2>/dev/null || true" || true`,
);
cleanupCommands.push(`docker exec ${NODE} sh -c "crictl rm --all 2>/dev/null || true" || true`);
// Remove non-Unity images only (preserve unityci/editor images to avoid re-pulling 3.9GB)
// This is safe because we explicitly exclude Unity images from deletion
cleanupCommands.push(

View File

@@ -44,7 +44,7 @@ describe('Cloud Runner pre-built S3 steps', () => {
it('Run build and prebuilt s3 cache pull, cache push and upload build', async () => {
const cacheKey = `test-case-${uuidv4()}`;
const buildGuid = `test-build-${uuidv4()}`;
// Use customJob to run only S3 hooks without a full Unity build
// This is a quick validation test for S3 operations, not a full build test
const overrides = {