Skip to content

Commit

Permalink
Avoid creating no-op service discovery entries
Browse files Browse the repository at this point in the history
Skipping these can reduce the number of resources in CF templates
for simple deployments by ~20% which is useful given the CF limit
of 500 resources per (non-nested) stack.
  • Loading branch information
austindrenski committed May 7, 2024
1 parent 9b8ea67 commit 25422ba
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions ecs/cloudformation.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,9 +191,6 @@ func (b *ecsAPIService) createService(project *types.Project, service types.Serv
taskDefinition := fmt.Sprintf("%sTaskDefinition", normalizeResourceName(service.Name))
template.Resources[taskDefinition] = definition

var healthCheck *cloudmap.Service_HealthCheckConfig
serviceRegistry := b.createServiceRegistry(service, template, healthCheck)

var (
dependsOn []string
serviceLB []ecs.Service_LoadBalancer
Expand Down Expand Up @@ -269,7 +266,7 @@ func (b *ecsAPIService) createService(project *types.Project, service types.Serv
PlatformVersion: platformVersion,
PropagateTags: ecsapi.PropagateTagsService,
SchedulingStrategy: ecsapi.SchedulingStrategyReplica,
ServiceRegistries: []ecs.Service_ServiceRegistry{serviceRegistry},
ServiceRegistries: b.createServiceRegistries(service, template),
Tags: serviceTags(project, service),
TaskDefinition: cloudformation.Ref(normalizeResourceName(taskDefinition)),
}
Expand Down Expand Up @@ -414,15 +411,19 @@ func (b *ecsAPIService) createTargetGroup(project *types.Project, service types.
return targetGroupName
}

func (b *ecsAPIService) createServiceRegistry(service types.ServiceConfig, template *cloudformation.Template, healthCheck *cloudmap.Service_HealthCheckConfig) ecs.Service_ServiceRegistry {
func (b *ecsAPIService) createServiceRegistries(service types.ServiceConfig, template *cloudformation.Template) []ecs.Service_ServiceRegistry {
if len(service.Ports) == 0 {
return []ecs.Service_ServiceRegistry{}
}

serviceRegistration := fmt.Sprintf("%sServiceDiscoveryEntry", normalizeResourceName(service.Name))
serviceRegistry := ecs.Service_ServiceRegistry{
RegistryArn: cloudformation.GetAtt(serviceRegistration, "Arn"),
}

template.Resources[serviceRegistration] = &cloudmap.Service{
Description: fmt.Sprintf("%q service discovery entry in Cloud Map", service.Name),
HealthCheckConfig: healthCheck,
HealthCheckConfig: nil,
HealthCheckCustomConfig: &cloudmap.Service_HealthCheckCustomConfig{
FailureThreshold: 1,
},
Expand All @@ -438,7 +439,7 @@ func (b *ecsAPIService) createServiceRegistry(service types.ServiceConfig, templ
RoutingPolicy: cloudmapapi.RoutingPolicyMultivalue,
},
}
return serviceRegistry
return []ecs.Service_ServiceRegistry{serviceRegistry}
}

func (b *ecsAPIService) createTaskExecutionRole(project *types.Project, service types.ServiceConfig, template *cloudformation.Template) string {
Expand Down

0 comments on commit 25422ba

Please sign in to comment.