Skip to content

Commit

Permalink
Merge pull request moby#5730 from jsternberg/fix-check-invalid-platforms
Browse files Browse the repository at this point in the history
verifier: do not run invalid platforms check when there are no results
  • Loading branch information
tonistiigi authored Feb 13, 2025
2 parents 2308949 + 14d407b commit a9720d0
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 7 deletions.
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

0 comments on commit a9720d0

Please sign in to comment.