-
Notifications
You must be signed in to change notification settings - Fork 616
bake: fix override bug with inheritance #259
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is a regression test for a regression I hit during writing the PR
a1b6cff to
78f869d
Compare
bake/bake.go
Outdated
| } | ||
| 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 <[email protected]>
fc713b4 to
4388f14
Compare
Signed-off-by: Tibor Vass <[email protected]>
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.