Skip to content

Commit

Permalink
Merge pull request #4544 from jedevc/fix-each-ref-evaluate
Browse files Browse the repository at this point in the history
solver: ensure each ref in the result map is evaluated
  • Loading branch information
tonistiigi authored Jan 17, 2024
2 parents 0b09663 + cb7d240 commit 0e1e36b
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
42 changes: 42 additions & 0 deletions frontend/dockerfile/dockerfile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ var allTests = integration.TestFuncs(
testCacheMultiPlatformImportExport,
testOnBuildCleared,
testFrontendUseForwardedSolveResults,
testFrontendEvaluate,
testFrontendInputs,
testErrorsSourceMap,
testMultiArgs,
Expand Down Expand Up @@ -4902,6 +4903,47 @@ COPY foo foo2
require.Equal(t, dt, []byte("data"))
}

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

dockerfile := []byte(`
FROM scratch
COPY badfile /
`)
dir := integration.Tmpdir(t, fstest.CreateFile("Dockerfile", dockerfile, 0600))

frontend := func(ctx context.Context, c gateway.Client) (*gateway.Result, error) {
_, err := c.Solve(ctx, gateway.SolveRequest{
Frontend: "dockerfile.v0",
Evaluate: true,
})
require.ErrorContains(t, err, `"/badfile": not found`)

_, err = c.Solve(ctx, gateway.SolveRequest{
Frontend: "dockerfile.v0",
FrontendOpt: map[string]string{
"platform": "linux/amd64,linux/arm64",
},
Evaluate: true,
})
require.ErrorContains(t, err, `"/badfile": not found`)

return nil, nil
}

_, err = c.Build(sb.Context(), client.SolveOpt{
Exports: []client.ExportEntry{},
LocalDirs: map[string]string{
dockerui.DefaultLocalNameDockerfile: dir,
dockerui.DefaultLocalNameContext: dir,
},
}, "", frontend, nil)
require.NoError(t, err)
}

func testFrontendInputs(t *testing.T, sb integration.Sandbox) {
integration.SkipOnPlatform(t, "windows")
f := getFrontend(t, sb)
Expand Down
2 changes: 1 addition & 1 deletion solver/llbsolver/provenance.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ func (b *provenanceBridge) Solve(ctx context.Context, req frontend.SolveRequest,
}
if req.Evaluate {
err = res.EachRef(func(ref solver.ResultProxy) error {
_, err := res.Ref.Result(ctx)
_, err := ref.Result(ctx)
return err
})
}
Expand Down

0 comments on commit 0e1e36b

Please sign in to comment.