bake: fix override bug with inheritance#259
Conversation
fe74b65 to
28986b7
Compare
| t.Run("NoOverrides", func(t *testing.T) { | ||
| m, err := ReadTargets(ctx, []string{fp}, []string{"webapp"}, nil) | ||
| require.NoError(t, err) | ||
| require.Equal(t, 1, len(m)) |
There was a problem hiding this comment.
test hardening to catch a regression I had during dev
|
Found another bug:
EDIT: was regression in a previous version of my PR, added a test case. |
28986b7 to
a1b6cff
Compare
| // building leaf but overriding parent fields | ||
| t.Run("parent", func(t *testing.T) { | ||
| m, err := ReadTargets(ctx, []string{fp}, []string{"webapp"}, []string{ | ||
| "dep.args.VAR_INHERITED=override", |
There was a problem hiding this comment.
this is a regression test for a regression I hit during writing the PR
a1b6cff to
78f869d
Compare
| } | ||
| t.Inherits = nil | ||
| tt = merge(merge(defaultTarget(), t), tt) | ||
| tt = merge(merge(merge(defaultTarget(), t), tt), overrides[name]) |
There was a problem hiding this comment.
Note: nothing is setting c.Target[name] (aka t here), so I believe we could remove the defaultTarget() merge and do merge(t, tt) directly.
78f869d to
c623b89
Compare
c623b89 to
fc713b4
Compare
Signed-off-by: Tibor Vass <tibor@docker.com>
fc713b4 to
4388f14
Compare
Signed-off-by: Tibor Vass <tibor@docker.com>
4388f14 to
14e65ff
Compare
| } | ||
| t.Inherits = nil | ||
| tt = merge(merge(defaultTarget(), t), tt) | ||
| tt = merge(merge(merge(defaultTarget(), tt), t), overrides[name]) |
There was a problem hiding this comment.
@tonistiigi I found another bug (not a regression from this PR). See test with VAR_BOTH. I believe this is correct: t is the child target, and tt is the parent, we want to merge the child into the parent, and the overrides on top.
There was a problem hiding this comment.
An important invariant I can add a comment in the code for, is that t should not have the default overrides (context = "." and dockerfile = "."), which is the case here because target() is called before setting those defaults in ResolveTarget.
| t.Run("parent", func(t *testing.T) { | ||
| m, err := ReadTargets(ctx, []string{fp}, []string{"webapp"}, []string{ | ||
| "dep.args.VAR_INHERITED=override", | ||
| "dep.args.VAR_BOTH=override", |
There was a problem hiding this comment.
this one is not, it's a bug in master.
Added the bug case in tests:
bake --set webapp.args.VAR_INHERITED=overridewas still inheritingdepvalue.