Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,18 @@ The task definition file can be updated prior to deployment with the new contain
wait-for-service-stability: true
```

If you're using CloudFormation tools such as AWS CDK, Serverless Framework, or others to construct your task definition, you can directly pass the ARN of the task definition. For example:

```yaml
- name: Deploy Amazon ECS task definition
uses: aws-actions/amazon-ecs-deploy-task-definition@v2
with:
task-definition-arn: arn:aws:ecs:<region>:<aws_account_id>:task-definition/<task_definition_name>:<revision_number>
service: my-service
cluster: my-cluster
wait-for-service-stability: true
```

### Tags

To turn on [Amazon ECS-managed tags](https://docs.aws.amazon.com/AmazonECS/latest/developerguide/ecs-using-tags.html#managed-tags) `aws:ecs:serviceName` and `aws:ecs:clusterName` for the tasks in the service or the standalone tasks by setting `enable-ecs-managed-tags`:
Expand Down
7 changes: 5 additions & 2 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@ branding:
color: 'orange'
inputs:
task-definition:
description: 'The path to the ECS task definition file to register.'
required: true
description: 'The path to the ECS task definition file to register. Either this or task-definition-arn must be provided.'
required: false
task-definition-arn:
description: 'The ARN of an existing ECS task definition to deploy. Either this or task-definition must be provided.'
required: false
desired-count:
description: 'The number of instantiations of the task to place and keep running in your service.'
required: false
Expand Down
49 changes: 33 additions & 16 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,8 @@ async function run() {
});

// Get inputs
const taskDefinitionFile = core.getInput('task-definition', { required: true });
const taskDefinitionArn = core.getInput('task-definition-arn', { required: false });
const taskDefinitionFile = core.getInput('task-definition', { required: false });
const service = core.getInput('service', { required: false });
const cluster = core.getInput('cluster', { required: false });
const waitForService = core.getInput('wait-for-service-stability', { required: false });
Expand All @@ -411,23 +412,39 @@ async function run() {
}
const propagateTags = core.getInput('propagate-tags', { required: false }) || 'NONE';

// Register the task definition
core.debug('Registering the task definition');
const taskDefPath = path.isAbsolute(taskDefinitionFile) ?
let taskDefArn = null;

// Prioritize task-definition-arn if provided
if (taskDefinitionArn) {
taskDefArn = taskDefinitionArn;
} else if (taskDefinitionFile) {
// Fall back to task-definition file if provided
core.debug('Registering the task definition');
const taskDefPath = path.isAbsolute(taskDefinitionFile) ?
taskDefinitionFile :
path.join(process.env.GITHUB_WORKSPACE, taskDefinitionFile);
const fileContents = fs.readFileSync(taskDefPath, 'utf8');
const taskDefContents = maintainValidObjects(removeIgnoredAttributes(cleanNullKeys(yaml.parse(fileContents))));
let registerResponse;
try {
registerResponse = await ecs.registerTaskDefinition(taskDefContents);
} catch (error) {
core.setFailed("Failed to register task definition in ECS: " + error.message);
core.debug("Task definition contents:");
core.debug(JSON.stringify(taskDefContents, undefined, 4));
throw(error);
path.join(process.env.GITHUB_WORKSPACE, taskDefinitionFile);
const fileContents = fs.readFileSync(taskDefPath, 'utf8');
const taskDefContents = maintainValidObjects(removeIgnoredAttributes(cleanNullKeys(yaml.parse(fileContents))));
try {
const registerResponse = await ecs.registerTaskDefinition(taskDefContents);
taskDefArn = registerResponse.taskDefinition.taskDefinitionArn;
} catch (error) {
core.setFailed("Failed to register task definition in ECS: " + error.message);
core.debug("Task definition contents:");
core.debug(JSON.stringify(taskDefContents, undefined, 4));
throw(error);
}
} else {
// Error if neither is provided
core.setFailed('Either task-definition or task-definition-arn must be provided');
throw new Error('Either task-definition or task-definition-arn must be provided');
}
const taskDefArn = registerResponse.taskDefinition.taskDefinitionArn;

if (!taskDefArn) {
core.setFailed('Task definition ARN is not defined');
throw new Error('Task definition ARN is not defined');
}

core.setOutput('task-definition-arn', taskDefArn);

// Run the task outside of the service
Expand Down
49 changes: 33 additions & 16 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,8 @@ async function run() {
});

// Get inputs
const taskDefinitionFile = core.getInput('task-definition', { required: true });
const taskDefinitionArn = core.getInput('task-definition-arn', { required: false });
const taskDefinitionFile = core.getInput('task-definition', { required: false });
const service = core.getInput('service', { required: false });
const cluster = core.getInput('cluster', { required: false });
const waitForService = core.getInput('wait-for-service-stability', { required: false });
Expand All @@ -405,23 +406,39 @@ async function run() {
}
const propagateTags = core.getInput('propagate-tags', { required: false }) || 'NONE';

// Register the task definition
core.debug('Registering the task definition');
const taskDefPath = path.isAbsolute(taskDefinitionFile) ?
let taskDefArn = null;

// Prioritize task-definition-arn if provided
if (taskDefinitionArn) {
taskDefArn = taskDefinitionArn;
} else if (taskDefinitionFile) {
// Fall back to task-definition file if provided
core.debug('Registering the task definition');
const taskDefPath = path.isAbsolute(taskDefinitionFile) ?
taskDefinitionFile :
path.join(process.env.GITHUB_WORKSPACE, taskDefinitionFile);
const fileContents = fs.readFileSync(taskDefPath, 'utf8');
const taskDefContents = maintainValidObjects(removeIgnoredAttributes(cleanNullKeys(yaml.parse(fileContents))));
let registerResponse;
try {
registerResponse = await ecs.registerTaskDefinition(taskDefContents);
} catch (error) {
core.setFailed("Failed to register task definition in ECS: " + error.message);
core.debug("Task definition contents:");
core.debug(JSON.stringify(taskDefContents, undefined, 4));
throw(error);
path.join(process.env.GITHUB_WORKSPACE, taskDefinitionFile);
const fileContents = fs.readFileSync(taskDefPath, 'utf8');
const taskDefContents = maintainValidObjects(removeIgnoredAttributes(cleanNullKeys(yaml.parse(fileContents))));
try {
const registerResponse = await ecs.registerTaskDefinition(taskDefContents);
taskDefArn = registerResponse.taskDefinition.taskDefinitionArn;
} catch (error) {
core.setFailed("Failed to register task definition in ECS: " + error.message);
core.debug("Task definition contents:");
core.debug(JSON.stringify(taskDefContents, undefined, 4));
throw(error);
}
} else {
// Error if neither is provided
core.setFailed('Either task-definition or task-definition-arn must be provided');
throw new Error('Either task-definition or task-definition-arn must be provided');
}

if (!taskDefArn) {
core.setFailed('Task definition ARN is not defined');
throw new Error('Task definition ARN is not defined');
}
const taskDefArn = registerResponse.taskDefinition.taskDefinitionArn;

core.setOutput('task-definition-arn', taskDefArn);

// Run the task outside of the service
Expand Down
Loading