diff --git a/cli/compose/loader/merge.go b/cli/compose/loader/merge.go index a2bdabec73..97d55ea6b8 100644 --- a/cli/compose/loader/merge.go +++ b/cli/compose/loader/merge.go @@ -59,6 +59,7 @@ func mergeServices(base, override []types.ServiceConfig) ([]types.ServiceConfig, reflect.TypeOf([]types.ServiceConfigObjConfig{}): mergeSlice(toServiceConfigObjConfigsMap, toSServiceConfigObjConfigsSlice), reflect.TypeOf(&types.UlimitsConfig{}): mergeUlimitsConfig, reflect.TypeOf([]types.ServiceVolumeConfig{}): mergeSlice(toServiceVolumeConfigsMap, toServiceVolumeConfigsSlice), + reflect.TypeOf(types.ShellCommand{}): mergeShellCommand, reflect.TypeOf(&types.ServiceNetworkConfig{}): mergeServiceNetworkConfig, }, } @@ -235,9 +236,9 @@ func mergeUlimitsConfig(dst, src reflect.Value) error { } //nolint: unparam -func mergeServiceVolumeConfig(dst, src reflect.Value) error { - if dst.Elem().FieldByName("target").String() == src.Elem().FieldByName("target").String() { - dst.Set(src.Elem()) +func mergeShellCommand(dst, src reflect.Value) error { + if src.Len() != 0 { + dst.Set(src) } return nil } diff --git a/cli/compose/loader/merge_test.go b/cli/compose/loader/merge_test.go index c5bbf3b5de..6f2262b072 100644 --- a/cli/compose/loader/merge_test.go +++ b/cli/compose/loader/merge_test.go @@ -1017,6 +1017,59 @@ func TestLoadMultipleNetworks(t *testing.T) { }, config) } +func TestLoadMultipleServiceCommands(t *testing.T) { + base := map[string]interface{}{ + "version": "3.7", + "services": map[string]interface{}{ + "foo": map[string]interface{}{ + "image": "baz", + "command": "foo bar", + }, + }, + "volumes": map[string]interface{}{}, + "networks": map[string]interface{}{}, + "secrets": map[string]interface{}{}, + "configs": map[string]interface{}{}, + } + override := map[string]interface{}{ + "version": "3.7", + "services": map[string]interface{}{ + "foo": map[string]interface{}{ + "image": "baz", + "command": "foo baz", + }, + }, + "volumes": map[string]interface{}{}, + "networks": map[string]interface{}{}, + "secrets": map[string]interface{}{}, + "configs": map[string]interface{}{}, + } + configDetails := types.ConfigDetails{ + ConfigFiles: []types.ConfigFile{ + {Filename: "base.yml", Config: base}, + {Filename: "override.yml", Config: override}, + }, + } + config, err := Load(configDetails) + assert.NilError(t, err) + assert.DeepEqual(t, &types.Config{ + Filename: "base.yml", + Version: "3.7", + Services: []types.ServiceConfig{ + { + Name: "foo", + Image: "baz", + Command: types.ShellCommand{"foo", "baz"}, + Environment: types.MappingWithEquals{}, + }, + }, + Volumes: map[string]types.VolumeConfig{}, + Secrets: map[string]types.SecretConfig{}, + Configs: map[string]types.ConfigObjConfig{}, + Networks: map[string]types.NetworkConfig{}, + }, config) +} + func TestLoadMultipleServiceVolumes(t *testing.T) { base := map[string]interface{}{ "version": "3.7",