Skip to content
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

verifier: do not run invalid platforms check when there are no results #5730

Merged
merged 1 commit into from
Feb 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 49 additions & 1 deletion client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@ var allTests = []func(t *testing.T, sb integration.Sandbox){
testOCIIndexMediatype,
testLayerLimitOnMounts,
testFrontendVerifyPlatforms,
testFrontendLintSkipVerifyPlatforms,
testRunValidExitCodes,
testFileOpSymlink,
}
Expand Down Expand Up @@ -10414,6 +10415,52 @@ func testFrontendVerifyPlatforms(t *testing.T, sb integration.Sandbox) {
require.Contains(t, string(warnings[0].Short), "do not match result platforms linux/amd64,linux/arm64")
}

func testFrontendLintSkipVerifyPlatforms(t *testing.T, sb integration.Sandbox) {
c, err := New(sb.Context(), sb.Address())
require.NoError(t, err)
defer c.Close()

frontend := func(ctx context.Context, c gateway.Client) (*gateway.Result, error) {
dockerfile := `
FROM scratch
COPY foo /foo
`
st := llb.Scratch().File(
llb.Mkfile("Dockerfile", 0600, []byte(dockerfile)).
Mkfile("foo", 0600, []byte("data")))

def, err := st.Marshal(sb.Context())
if err != nil {
return nil, err
}

return c.Solve(ctx, gateway.SolveRequest{
FrontendInputs: map[string]*pb.Definition{
"context": def.ToPB(),
"dockerfile": def.ToPB(),
},
FrontendOpt: map[string]string{
"requestid": "frontend.lint",
"frontend.caps": "moby.buildkit.frontend.subrequests",
},
})
}

wc := newWarningsCapture()
_, err = c.Build(sb.Context(), SolveOpt{
FrontendAttrs: map[string]string{
"platform": "linux/amd64,linux/arm64",
},
}, "", frontend, wc.status)
require.NoError(t, err)
warnings := wc.wait()

for _, w := range warnings {
t.Logf("warning: %s", string(w.Short))
}
require.Len(t, warnings, 0)
}

type warningsCapture struct {
status chan *SolveStatus
statusDone chan struct{}
Expand Down Expand Up @@ -10876,7 +10923,8 @@ func testClientCustomGRPCOpts(t *testing.T, sb integration.Sandbox) {
reply interface{},
cc *grpc.ClientConn,
invoker grpc.UnaryInvoker,
opts ...grpc.CallOption) error {
opts ...grpc.CallOption,
) error {
interceptedMethods = append(interceptedMethods, method)
return invoker(ctx, method, req, reply, cc, opts...)
}
Expand Down
13 changes: 7 additions & 6 deletions exporter/verifier/platforms.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,13 @@ func CheckInvalidPlatforms[T comparable](ctx context.Context, res *result.Result
return nil, err
}

if req.Request != "" {
return nil, nil
}

if _, ok := res.Metadata[exptypes.ExporterPlatformsKey]; len(res.Refs) > 0 && !ok {
return nil, errors.Errorf("build result contains multiple refs without platforms mapping")
if _, ok := res.Metadata[exptypes.ExporterPlatformsKey]; !ok {
if len(res.Refs) > 0 {
return nil, errors.Errorf("build result contains multiple refs without platforms mapping")
} else if res.IsEmpty() {
// No results and no exporter key. Don't run this check.
return nil, nil
}
}

isMap := len(res.Refs) > 0
Expand Down
14 changes: 14 additions & 0 deletions solver/result/result.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,20 @@ func (r *Result[T]) EachRef(fn func(T) error) (err error) {
return err
}

// IsEmpty returns true if this result does not refer to
// any references.
func (r *Result[T]) IsEmpty() bool {
r.mu.Lock()
defer r.mu.Unlock()

if len(r.Refs) > 0 {
return false
}

var zero T
return r.Ref == zero
}

// EachRef iterates over references in both a and b.
// a and b are assumed to be of the same size and map their references
// to the same set of keys
Expand Down