diff --git a/pkg/domain/dockerCompose/config.go b/pkg/domain/dockerCompose/config.go index 87d25c5..6962bb5 100644 --- a/pkg/domain/dockerCompose/config.go +++ b/pkg/domain/dockerCompose/config.go @@ -490,8 +490,17 @@ func (s *Service) mergeLastWinEnvironments(environments []string) { } func (s *Service) mergeLastWinImage(image string) { - if s.Image != image { + switch { + case len(s.Image) == 0 && len(image) != 0: s.Image = image + case len(s.Image) != 0 && len(image) == 0: + fallthrough + case len(s.Image) == 0 && len(image) == 0: + return + default: + if s.Image != image { + s.Image = image + } } } diff --git a/pkg/domain/dockerCompose/config_test.go b/pkg/domain/dockerCompose/config_test.go index 4fe949b..1f4fa2e 100644 --- a/pkg/domain/dockerCompose/config_test.go +++ b/pkg/domain/dockerCompose/config_test.go @@ -735,6 +735,41 @@ func TestService_MergeLastWin(t *testing.T) { }, }, + // Image + { + serviceDeploymentA: &dockerCompose.Service{ + Image: "", + }, + serviceDeploymentB: &dockerCompose.Service{ + Image: "", + }, + expectedService: &dockerCompose.Service{ + Image: "", + }, + }, + { + serviceDeploymentA: &dockerCompose.Service{ + Image: "HelloWorld", + }, + serviceDeploymentB: &dockerCompose.Service{ + Image: "FooBar", + }, + expectedService: &dockerCompose.Service{ + Image: "FooBar", + }, + }, + { + serviceDeploymentA: &dockerCompose.Service{ + Image: "HelloWorld", + }, + serviceDeploymentB: &dockerCompose.Service{ + Image: "", + }, + expectedService: &dockerCompose.Service{ + Image: "HelloWorld", + }, + }, + // Labels { serviceDeploymentA: &dockerCompose.Service{