bake: merge targets on same groups

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
pull/134/head
Tonis Tiigi 5 years ago
parent 5b974158f9
commit 15a5a42eb1

@ -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 {

@ -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"])
}

Loading…
Cancel
Save