Skip to content

Commit

Permalink
fix: review comment - add container name to all service names
Browse files Browse the repository at this point in the history
Signed-off-by: Ben Meier <[email protected]>
  • Loading branch information
astromechza committed Feb 5, 2024
1 parent 8f972e9 commit fba396c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 11 deletions.
14 changes: 5 additions & 9 deletions internal/compose/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions internal/compose/convert_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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}"),
Expand Down

0 comments on commit fba396c

Please sign in to comment.