diff --git a/ecs/Makefile b/ecs/Makefile index e07af815e..5d3c5883d 100644 --- a/ecs/Makefile +++ b/ecs/Makefile @@ -2,7 +2,7 @@ clean: rm -rf dist/ build: - go build -v -o dist/docker-ecs cmd/main.go + go build -v -o dist/docker-ecs cmd/main/main.go test: ## Run tests go test ./... -v diff --git a/ecs/cmd/main.go b/ecs/cmd/main/main.go similarity index 100% rename from ecs/cmd/main.go rename to ecs/cmd/main/main.go diff --git a/ecs/pkg/amazon/cloudformation.go b/ecs/pkg/amazon/cloudformation.go index 76aa80887..7664d1a9c 100644 --- a/ecs/pkg/amazon/cloudformation.go +++ b/ecs/pkg/amazon/cloudformation.go @@ -13,6 +13,7 @@ import ( "github.com/awslabs/goformation/v4/cloudformation/ec2" "github.com/awslabs/goformation/v4/cloudformation/ecs" "github.com/awslabs/goformation/v4/cloudformation/iam" + cloudmap "github.com/awslabs/goformation/v4/cloudformation/servicediscovery" "github.com/docker/ecs-plugin/pkg/compose" ) @@ -54,6 +55,13 @@ func (c client) Convert(ctx context.Context, project *compose.Project) (*cloudfo LogGroupName: logGroup, } + // Private DNS namespace will allow DNS name for the services to be ..local + template.Resources["CloudMap"] = &cloudmap.PrivateDnsNamespace{ + Description: fmt.Sprintf("Service Map for Docker Compose project %s", project.Name), + Name: fmt.Sprintf("%s.local", project.Name), + Vpc: vpc, + } + for _, service := range project.Services { definition, err := Convert(project, service) if err != nil { @@ -89,6 +97,19 @@ func (c client) Convert(ctx context.Context, project *compose.Project) (*cloudfo ServiceName: service.Name, TaskDefinition: cloudformation.Ref(taskDefinition), } + + var healthCheck *cloudmap.Service_HealthCheckConfig + if service.HealthCheck != nil && !service.HealthCheck.Disable { + // FIXME ECS only support HTTP(s) health checks, while Docker only support CMD + } + + serviceRegistration := fmt.Sprintf("%sServiceRegistration", service.Name) + template.Resources[serviceRegistration] = &cloudmap.Service{ + Description: fmt.Sprintf("%q registration in Service Map", service.Name), + HealthCheckConfig: healthCheck, + Name: serviceRegistration, + NamespaceId: cloudformation.Ref("CloudMap"), + } } return template, nil }