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 0c9d73c
Show file tree
Hide file tree
Showing 11 changed files with 16 additions and 20 deletions.
2 changes: 1 addition & 1 deletion e2e-tests/resources/outputs/example-01-hello-output.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
services:
hello-world:
hello-world-hello:
command:
- -c
- while true; do echo Hello World!; sleep 5; done
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
services:
hello-world:
hello-world-hello:
command:
- -c
- while true; do echo Hello $${FRIEND}!; sleep 5; done
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
services:
service-a:
service-a-service-a:
command:
- -c
- 'while true; do echo service-a: Hello $${FRIEND}! Connecting to $${CONNECTION_STRING}...; sleep 10; done'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
services:
service-b:
service-b-service-b:
command:
- -c
- 'while true; do echo service-b: Hello $${FRIEND}!; sleep 5; done'
Expand Down
2 changes: 1 addition & 1 deletion e2e-tests/resources/outputs/example-04-extras-output.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
services:
web-app:
web-app-hello:
image: nginx
ports:
- target: 80
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
services:
hello-world:
hello-world-hello:
build:
context: test
command:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
services:
hello-world:
hello-world-hello:
command:
- -c
- while true; do echo Hello World!; sleep 5; done
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
services:
hello-world:
hello-world-hello:
command:
- -c
- while true; do echo Hello World!; sleep 5; done
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
services:
hello-world:
hello-world-hello:
command:
- -c
- while true; do echo Hello World!; sleep 5; done
Expand Down
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 0c9d73c

Please sign in to comment.