Skip to content

bake: skip empty attributes#2832

Closed
crazy-max wants to merge 2 commits intodocker:masterfrom
crazy-max:bake-empty-attr
Closed

bake: skip empty attributes#2832
crazy-max wants to merge 2 commits intodocker:masterfrom
crazy-max:bake-empty-attr

Conversation

@crazy-max
Copy link
Copy Markdown
Member

@crazy-max crazy-max commented Dec 2, 2024

relates to #428
fixes #2822
closes #2826

Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com>
Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com>
Comment thread bake/bake_test.go
Comment on lines +2022 to +2040
// https://github.com/docker/buildx/pull/428
// https://github.com/docker/buildx/issues/2822
func TestEmptyAttribute(t *testing.T) {
fp := File{
Name: "docker-bake.hcl",
Data: []byte(`
target "app" {
output = [""]
}
`),
}

ctx := context.TODO()

_, _, err := ReadTargets(ctx, []File{fp}, []string{"app"}, nil, nil)
require.NoError(t, err)
}
Copy link
Copy Markdown
Member Author

@crazy-max crazy-max Dec 2, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test works in current state but when looking at the app target it contains an empty ExportEntry, while previously there were none. So I guess we need to make some changes in the HCL parser as well. I will update this test to make sure of it.

@crazy-max crazy-max changed the title bake: do not attempt to unmarshal empty attributes bake: skip empty attributes Dec 2, 2024
Comment thread bake/bake_test.go

m, _, err := ReadTargets(ctx, []File{fp}, []string{"app"}, nil, nil)
require.Equal(t, 1, len(m))
require.Len(t, m["app"].Outputs, 0)
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It fails as expected: https://github.com/docker/buildx/actions/runs/12120057362/job/33787924177?pr=2832#step:6:1326

=== FAIL: bake TestEmptyAttribute (0.00s)
    bake_test.go:2038: 
        	Error Trace:	/home/runner/work/buildx/buildx/bake/bake_test.go:2038
        	Error:      	"[]" should have 0 item(s), but has 1
        	Test:       	TestEmptyAttribute

@crazy-max crazy-max added this to the v0.20.0 milestone Dec 2, 2024
@crazy-max crazy-max closed this Dec 16, 2024
@crazy-max crazy-max deleted the bake-empty-attr branch December 16, 2024 13:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[v0.19.0] bake: Unsuitable value: EOF

1 participant