From fba396cbf5481f4362baa476d9ff0a76e22f3236 Mon Sep 17 00:00:00 2001 From: Ben Meier Date: Mon, 5 Feb 2024 14:17:18 +0000 Subject: [PATCH] fix: review comment - add container name to all service names Signed-off-by: Ben Meier --- internal/compose/convert.go | 14 +++++--------- internal/compose/convert_test.go | 4 ++-- 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/internal/compose/convert.go b/internal/compose/convert.go index 10d3516..0db93a1 100644 --- a/internal/compose/convert.go +++ b/internal/compose/convert.go @@ -92,7 +92,7 @@ func ConvertSpec(spec *score.Workload) (*compose.Project, ExternalVariables, err // END (NOTE) var svc = compose.ServiceConfig{ - Name: spec.Metadata.Name, + Name: spec.Metadata.Name + "-" + containerName, Image: cSpec.Image, Entrypoint: cSpec.Command, Command: cSpec.Args, @@ -101,14 +101,10 @@ func ConvertSpec(spec *score.Workload) (*compose.Project, ExternalVariables, err Volumes: volumes, } - if len(spec.Containers) > 1 { - // if we have more than 1 container then namespace them with the container name - svc.Name += "-" + containerName - // if we are not the "first" service, then inherit the network from the first service - if len(project.Services) > 0 { - svc.Ports = nil - svc.NetworkMode = "service:" + project.Services[0].Name - } + // if we are not the "first" service, then inherit the network from the first service + if len(project.Services) > 0 { + svc.Ports = nil + svc.NetworkMode = "service:" + project.Services[0].Name } project.Services = append(project.Services, svc) diff --git a/internal/compose/convert_test.go b/internal/compose/convert_test.go index 44fd8a3..06acecc 100644 --- a/internal/compose/convert_test.go +++ b/internal/compose/convert_test.go @@ -67,7 +67,7 @@ func TestScoreConvert(t *testing.T) { Project: &compose.Project{ Services: compose.Services{ { - Name: "test", + Name: "test-backend", Image: "busybox", Entrypoint: compose.ShellCommand{ "/bin/sh", @@ -137,7 +137,7 @@ func TestScoreConvert(t *testing.T) { Project: &compose.Project{ Services: compose.Services{ { - Name: "test", + Name: "test-backend", Image: "busybox", Environment: compose.MappingWithEquals{ "DEBUG": stringPtr("${DEBUG}"),