Skip to content

Commit 050c16b

Browse files
authored
Merge pull request #16 from sonikro/allow-ecs-cluster-name-input
feat: allow ecs-cluster-name to be an input
2 parents e4b2c17 + 83bb969 commit 050c16b

File tree

5 files changed

+36
-24
lines changed

5 files changed

+36
-24
lines changed

Diff for: action.yml

+4
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ inputs:
1919
required: false
2020
default: "256"
2121
description: Amount of vCPU to be used by the remote ECS Task (Must be a FARGATE Compatible combination. See https://docs.aws.amazon.com/AmazonECS/latest/developerguide/task-cpu-memory-error.html)
22+
ecs_cluster_name:
23+
required: false
24+
default: "github-actions-aws-run"
25+
description: The name of the ECS Cluster where the Tasks will run. It will be automatically created if it doesn't exist
2226
image:
2327
required: true
2428
description: Name of the docker container to be used for the step execution

Diff for: dist/index.js

+11-10
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: dist/index.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: src/main.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ async function run(): Promise<void> {
2323
const securityGroupId: string = core.getInput('security_group_id')
2424
const memory: string = core.getInput(`memory`)
2525
const cpu: string = core.getInput(`cpu`)
26+
const ecsClusterName: string = core.getInput(`ecs_cluster_name`)
2627

2728
core.debug(`Using ${roleArn} to authenticate to AWS`) // debug is only output if you set the secret `ACTIONS_STEP_DEBUG` to true
2829
core.debug(`Using ${image} as the container image for running the task`)
@@ -57,7 +58,8 @@ async function run(): Promise<void> {
5758
shell,
5859
securityGroupId,
5960
memory,
60-
cpu
61+
cpu,
62+
ecsClusterName
6163
})
6264

6365
if (executionResult.exitCode !== 0) {

Diff for: src/providers/remoteEnvironments/AWSECSRemoteEnvironment.ts

+17-12
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ export interface ECSExecutionSettings extends ExecutionSettings {
3131
securityGroupId: string
3232
memory: string
3333
cpu: string
34+
ecsClusterName: string
3435
}
3536

3637
export interface ECSTaskExecutionResult extends ExecutionResult {
@@ -44,8 +45,6 @@ export type TeardownFunction = () => Promise<any>
4445
export class AWSECSRemoteEnvironment
4546
implements RemoteEnvironment<ECSExecutionSettings>
4647
{
47-
static readonly CLUSTER_NAME = 'github-actions-aws-run'
48-
4948
private readonly tearDownQueue: TeardownFunction[] = []
5049

5150
static async fromGithubOidc({
@@ -108,7 +107,7 @@ export class AWSECSRemoteEnvironment
108107

109108
// Setup Environment
110109
console.log('Setting up required infrastructure')
111-
const ecsCluster = await this.setupECSCluster()
110+
const ecsCluster = await this.setupECSCluster({settings})
112111
console.log(`Using ECS Cluster ${ecsCluster.clusterName}`)
113112
core.debug(
114113
`Uploading runner workspace to S3 so it can be shared with the remote execution ECS Task`
@@ -161,8 +160,12 @@ export class AWSECSRemoteEnvironment
161160
}
162161
}
163162

164-
protected async setupECSCluster(): Promise<ECS.Cluster> {
165-
const ecsCluster = await this.getOrCreateCluster()
163+
protected async setupECSCluster({
164+
settings
165+
}: {
166+
settings: ECSExecutionSettings
167+
}): Promise<ECS.Cluster> {
168+
const ecsCluster = await this.getOrCreateCluster({settings})
166169
return ecsCluster
167170
}
168171

@@ -190,7 +193,7 @@ export class AWSECSRemoteEnvironment
190193

191194
const awsLogsParameters = {
192195
'awslogs-create-group': 'true',
193-
'awslogs-group': AWSECSRemoteEnvironment.CLUSTER_NAME,
196+
'awslogs-group': settings.ecsClusterName,
194197
'awslogs-region': ecs.config.region!,
195198
'awslogs-stream-prefix': 'aws-run-logs'
196199
}
@@ -321,9 +324,7 @@ export class AWSECSRemoteEnvironment
321324
}): Promise<ECS.Task> {
322325
const {cloudwatchLogs, ecs} = this.dependencies
323326

324-
const taskId = taskArn.split(
325-
`:task/${AWSECSRemoteEnvironment.CLUSTER_NAME}/`
326-
)[1]
327+
const taskId = taskArn.split(`:task/${settings.ecsClusterName}/`)[1]
327328

328329
const POLLING_INTERVAL = 2000
329330

@@ -476,12 +477,16 @@ export class AWSECSRemoteEnvironment
476477
await s3.deleteBucket({Bucket: bucketName}).promise()
477478
}
478479

479-
protected async getOrCreateCluster(): Promise<ECS.Cluster> {
480+
protected async getOrCreateCluster({
481+
settings
482+
}: {
483+
settings: ECSExecutionSettings
484+
}): Promise<ECS.Cluster> {
480485
const {ecs} = this.dependencies
481486

482487
const existingClusterResponse = await ecs
483488
.describeClusters({
484-
clusters: [AWSECSRemoteEnvironment.CLUSTER_NAME]
489+
clusters: [settings.ecsClusterName]
485490
})
486491
.promise()
487492

@@ -492,7 +497,7 @@ export class AWSECSRemoteEnvironment
492497
const newClusterResponse = await ecs
493498
.createCluster({
494499
capacityProviders: ['FARGATE'],
495-
clusterName: AWSECSRemoteEnvironment.CLUSTER_NAME,
500+
clusterName: settings.ecsClusterName,
496501
tags: [{key: 'managedBy', value: 'aws-run'}]
497502
})
498503
.promise()

0 commit comments

Comments
 (0)