From cec3187bbb4a95a23cafe590f7d2a72a3c6bc3ce Mon Sep 17 00:00:00 2001 From: aiordache Date: Fri, 24 Jul 2020 20:01:17 +0200 Subject: [PATCH] Set task tags Signed-off-by: aiordache Signed-off-by: Nicolas De Loof --- ecs/pkg/amazon/backend/convert.go | 32 ++++++++++++++----- .../simple-cloudformation-conversion.golden | 14 ++++++++ 2 files changed, 38 insertions(+), 8 deletions(-) diff --git a/ecs/pkg/amazon/backend/convert.go b/ecs/pkg/amazon/backend/convert.go index e3591ee70..4470e116d 100644 --- a/ecs/pkg/amazon/backend/convert.go +++ b/ecs/pkg/amazon/backend/convert.go @@ -37,14 +37,29 @@ func Convert(project *types.Project, service types.ServiceConfig) (*ecs.TaskDefi fmt.Sprintf(" %s.local", project.Name), })) + tags := []tags.Tag{ + { + Key: compose.ProjectTag, + Value: project.Name, + }, + { + Key: compose.ServiceTag, + Value: service.Name, + }, + } + tags = append(tags, toTags(service.Labels)...) + return &ecs.TaskDefinition{ ContainerDefinitions: []ecs.TaskDefinition_ContainerDefinition{ { - Command: service.Command, - DisableNetworking: service.NetworkMode == "none", - DnsSearchDomains: service.DNSSearch, - DnsServers: service.DNS, - DockerLabels: nil, + Command: service.Command, + DisableNetworking: service.NetworkMode == "none", + DnsSearchDomains: service.DNSSearch, + DnsServers: service.DNS, + DockerLabels: map[string]string{ + compose.ProjectTag: project.Name, + compose.ServiceTag: service.Name, + }, DockerSecurityOptions: service.SecurityOpt, EntryPoint: service.Entrypoint, Environment: toKeyValuePair(service.Environment), @@ -78,8 +93,9 @@ func Convert(project *types.Project, service types.ServiceConfig) (*ecs.TaskDefi SystemControls: toSystemControls(service.Sysctls), Ulimits: toUlimits(service.Ulimits), User: service.User, - VolumesFrom: nil, - WorkingDirectory: service.WorkingDir, + + VolumesFrom: nil, + WorkingDirectory: service.WorkingDir, }, }, Cpu: cpu, @@ -91,7 +107,7 @@ func Convert(project *types.Project, service types.ServiceConfig) (*ecs.TaskDefi PlacementConstraints: toPlacementConstraints(service.Deploy), ProxyConfiguration: nil, RequiresCompatibilities: []string{ecsapi.LaunchTypeFargate}, - Tags: toTags(service.Labels), + Tags: tags, }, nil } diff --git a/ecs/pkg/amazon/backend/testdata/simple/simple-cloudformation-conversion.golden b/ecs/pkg/amazon/backend/testdata/simple/simple-cloudformation-conversion.golden index 4db597e4d..2538d4c0b 100644 --- a/ecs/pkg/amazon/backend/testdata/simple/simple-cloudformation-conversion.golden +++ b/ecs/pkg/amazon/backend/testdata/simple/simple-cloudformation-conversion.golden @@ -219,6 +219,10 @@ "Properties": { "ContainerDefinitions": [ { + "DockerLabels": { + "com.docker.compose.project": "TestSimpleConvert", + "com.docker.compose.service": "simple" + }, "Environment": [ { "Name": "LOCALDOMAIN", @@ -270,6 +274,16 @@ "NetworkMode": "awsvpc", "RequiresCompatibilities": [ "FARGATE" + ], + "Tags": [ + { + "Key": "com.docker.compose.project", + "Value": "TestSimpleConvert" + }, + { + "Key": "com.docker.compose.service", + "Value": "simple" + } ] }, "Type": "AWS::ECS::TaskDefinition"