diff --git a/bake/bake.go b/bake/bake.go index 2e44af4f..8fbd93cf 100644 --- a/bake/bake.go +++ b/bake/bake.go @@ -77,7 +77,20 @@ func mergeConfig(c1, c2 Config) Config { if c1.Group == nil { c1.Group = map[string]Group{} } - c1.Group[k] = g + if g1, exists := c1.Group[k]; exists { + nextTarget: + for _, t := range g.Targets { + for _, t2 := range g1.Targets { + if t == t2 { + continue nextTarget + } + } + g1.Targets = append(g1.Targets, t) + } + c1.Group[k] = g1 + } else { + c1.Group[k] = g + } } for k, t := range c2.Target { diff --git a/bake/bake_test.go b/bake/bake_test.go index defc3f84..21c114f9 100644 --- a/bake/bake_test.go +++ b/bake/bake_test.go @@ -59,11 +59,30 @@ services: `), 0600) require.NoError(t, err) + fp2 := filepath.Join(tmpdir, "docker-compose2.yml") + err = ioutil.WriteFile(fp2, []byte(` +version: "3" + +services: + newservice: + build: . + webapp: + build: + args: + buildno2: 12 +`), 0600) + require.NoError(t, err) + ctx := context.TODO() - m, err := ReadTargets(ctx, []string{fp}, []string{"default"}, nil) + m, err := ReadTargets(ctx, []string{fp, fp2}, []string{"default"}, nil) require.NoError(t, err) + require.Equal(t, 3, len(m)) + _, ok := m["newservice"] + require.True(t, ok) require.Equal(t, "Dockerfile.webapp", *m["webapp"].Dockerfile) require.Equal(t, ".", *m["webapp"].Context) + require.Equal(t, "1", m["webapp"].Args["buildno"]) + require.Equal(t, "12", m["webapp"].Args["buildno2"]) }