Skip to content

Commit

Permalink
Merge branch 'release/4.0.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
rajadain committed Jan 5, 2024
2 parents 953af0c + d4b3664 commit 048216e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 12 deletions.
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [4.0.0] - 2024-01-05
### Changed
- Return task ARN from the handle command [#34](https://github.com/azavea/django-ecsmanage/pull/34)

## [3.0.0] - 2023-12-18
### Added
- Add support for Django 3.2, 4.2, 5.0 [#33](https://github.com/azavea/django-ecsmanage/pull/33)
Expand Down Expand Up @@ -70,7 +74,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Update PyPi credentials [#4](https://github.com/azavea/django-ecsmanage/pull/4)
- Initialize Django module for one-off management commands [#2](https://github.com/azavea/django-ecsmanage/pull/2)

[Unreleased]: https://github.com/azavea/django-ecsmanage/compare/3.0.0...HEAD
[Unreleased]: https://github.com/azavea/django-ecsmanage/compare/4.0.0...HEAD
[4.0.0]: https://github.com/azavea/django-ecsmanage/compare/3.0.0...4.0.0
[3.0.0]: https://github.com/azavea/django-ecsmanage/compare/2.0.1...3.0.0
[2.0.1]: https://github.com/azavea/django-ecsmanage/compare/2.0.0...2.0.1
[2.0.0]: https://github.com/azavea/django-ecsmanage/compare/1.1.0...2.0.0
Expand Down
25 changes: 14 additions & 11 deletions ecsmanage/management/commands/ecsmanage.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def add_arguments(self, parser):
def handle(self, *args, **options):
"""
Run the given command on the latest app CLI task definition and print
out a URL to view the status.
out a URL to view the status. Returns the task ARN of the started task.
"""
self.env = options["env"]
cmd = options["cmd"]
Expand All @@ -45,7 +45,15 @@ def handle(self, *args, **options):
security_group_id = self.get_security_group(config["SECURITY_GROUP_TAGS"])
subnet_id = self.get_subnet(config["SUBNET_TAGS"])

task_id = self.run_task(config, task_def_arn, security_group_id, subnet_id, cmd)
task_arn = self.run_task(config, task_def_arn, security_group_id, subnet_id, cmd)

# Task ARNs have at least two formats:
#
# - Old: arn:aws:ecs:region:aws_account_id:task/task-id
# - New: arn:aws:ecs:region:aws_account_id:task/cluster-name/task-id
#
# See: https://docs.aws.amazon.com/AmazonECS/latest/userguide/ecs-account-settings.html#ecs-resource-ids # NOQA
task_id = task_arn.split("/")[-1]

cluster_name = config["CLUSTER_NAME"]

Expand All @@ -58,6 +66,8 @@ def handle(self, *args, **options):
self.style.SUCCESS(f"Task started! View here:\n{url}")
) # NOQA

return task_arn

def parse_config(self):
"""
Parse configuration settings for the app, checking to make sure that
Expand Down Expand Up @@ -165,7 +175,7 @@ def get_subnet(self, subnet_tags):
def run_task(self, config, task_def_arn, security_group_id, subnet_id, cmd):
"""
Run a task for a given task definition ARN using the given security
group and subnets, and return the task ID.
group and subnets, and return the task ARN of the started task.
"""
task_def = self.ecs_client.describe_task_definition(
taskDefinition=task_def_arn
Expand Down Expand Up @@ -200,11 +210,4 @@ def run_task(self, config, task_def_arn, security_group_id, subnet_id, cmd):

task = self.parse_response(self.ecs_client.run_task(**kwargs), "tasks", 0)

# Task ARNs have at least two formats:
#
# - Old: arn:aws:ecs:region:aws_account_id:task/task-id
# - New: arn:aws:ecs:region:aws_account_id:task/cluster-name/task-id
#
# See: https://docs.aws.amazon.com/AmazonECS/latest/userguide/ecs-account-settings.html#ecs-resource-ids # NOQA
task_id = task["taskArn"].split("/")[-1]
return task_id
return task["taskArn"]

0 comments on commit 048216e

Please sign in to comment.