Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ECS] Force New Deployment #8232

Merged
merged 3 commits into from
Oct 16, 2024
Merged
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
7 changes: 7 additions & 0 deletions moto/ecs/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1692,6 +1692,7 @@ def update_service(self, service_properties: Dict[str, Any]) -> Service:
task_definition_str = service_properties.pop("task_definition", None)
cluster = self._get_cluster(cluster_str)
service_name = service_properties.pop("service").split("/")[-1]
force_new_deployment = service_properties.pop("force_new_deployment", False)
cluster_service_pair = f"{cluster.name}:{service_name}"

if cluster_service_pair in self.services:
Expand All @@ -1705,6 +1706,12 @@ def update_service(self, service_properties: Dict[str, Any]) -> Service:
if task_definition_str:
self.describe_task_definition(task_definition_str)
current_service.task_definition = task_definition_str
if force_new_deployment and current_service.deployments:
deployment = current_service.deployments[0]
deployment["id"] = f"ecs-svc/{mock_random.randint(0, 32**12)}"
now = datetime.now(timezone.utc)
deployment["createdAt"] = now
deployment["updatedAt"] = now
return current_service
else:
raise ServiceNotFoundException
Expand Down
16 changes: 16 additions & 0 deletions tests/test_ecs/test_ecs_boto3.py
Original file line number Diff line number Diff line change
Expand Up @@ -1225,6 +1225,8 @@ def test_update_service():
desiredCount=2,
)
assert response["service"]["desiredCount"] == 2
id = response["service"]["deployments"][0]["id"]
created_at = response["service"]["deployments"][0]["createdAt"]

response = client.update_service(
cluster="test_ecs_cluster",
Expand All @@ -1248,6 +1250,20 @@ def test_update_service():
assert response["service"]["runningCount"] == 1
assert response["service"]["pendingCount"] == 0

response = client.update_service(
cluster="test_ecs_cluster",
service="test_ecs_service",
taskDefinition="test_ecs_task",
desiredCount=1,
forceNewDeployment=True,
)
assert response["service"]["deployments"][0]["id"] != id
assert response["service"]["deployments"][0]["createdAt"] != created_at
assert (
response["service"]["deployments"][0]["createdAt"]
== response["service"]["deployments"][0]["updatedAt"]
)


@mock_aws
def test_update_missing_service():
Expand Down
Loading