diff --git a/frontend/dockerfile/dockerfile2llb/convert.go b/frontend/dockerfile/dockerfile2llb/convert.go index 34ded701fe929..0efc2331d39da 100644 --- a/frontend/dockerfile/dockerfile2llb/convert.go +++ b/frontend/dockerfile/dockerfile2llb/convert.go @@ -717,9 +717,9 @@ func toDispatchState(ctx context.Context, dt []byte, opt ConvertOpt) (*dispatchS } // If lint.Error() returns an error, it means that - // error if there were warnings, and that our linter has been - // configured to return an error on warnings, so we appropriately return - // that error here. + // there were warnings, and that our linter has been + // configured to return an error on warnings, + // so we appropriately return that error here. err = lint.Error() if err != nil { return nil, err diff --git a/frontend/dockerfile/dockerfile_lint_test.go b/frontend/dockerfile/dockerfile_lint_test.go index 2d1830c8f34de..ec8d6dd59b03c 100644 --- a/frontend/dockerfile/dockerfile_lint_test.go +++ b/frontend/dockerfile/dockerfile_lint_test.go @@ -101,6 +101,40 @@ copy Dockerfile . UnmarshalBuildErr: "lint violation found for rules: FromAsCasing", BuildErrLocation: 2, }) + + dockerfile = []byte(`#check=skip=all +FROM scratch as base +copy Dockerfile . +`) + checkLinterWarnings(t, sb, &lintTestParams{ + Dockerfile: dockerfile, + Warnings: []expectedLintWarning{ + { + RuleName: "FromAsCasing", + Description: "The 'as' keyword should match the case of the 'from' keyword", + Detail: "'as' and 'FROM' keywords' casing do not match", + Line: 2, + Level: 1, + }, + }, + StreamBuildErr: "failed to solve: lint violation found for rules: FromAsCasing", + UnmarshalBuildErr: "lint violation found for rules: FromAsCasing", + BuildErrLocation: 2, + FrontendAttrs: map[string]string{ + "build-arg:BUILDKIT_DOCKERFILE_LINT": "skip=FileConsistentCommandCasing;error=true", + }, + }) + + dockerfile = []byte(`#check=error=true +FROM scratch as base +copy Dockerfile . +`) + checkLinterWarnings(t, sb, &lintTestParams{ + Dockerfile: dockerfile, + FrontendAttrs: map[string]string{ + "build-arg:BUILDKIT_DOCKERFILE_LINT": "skip=all", + }, + }) } func testStageName(t *testing.T, sb integration.Sandbox) { @@ -793,12 +827,16 @@ func checkUnmarshal(t *testing.T, sb integration.Sandbox, lintTest *lintTestPara called := false frontend := func(ctx context.Context, c gateway.Client) (*gateway.Result, error) { + frontendOpts := map[string]string{ + "frontend.caps": "moby.buildkit.frontend.subrequests", + "requestid": "frontend.lint", + } + for k, v := range lintTest.FrontendAttrs { + frontendOpts[k] = v + } res, err := c.Solve(ctx, gateway.SolveRequest{ - FrontendOpt: map[string]string{ - "frontend.caps": "moby.buildkit.frontend.subrequests", - "requestid": "frontend.lint", - }, - Frontend: "dockerfile.v0", + FrontendOpt: frontendOpts, + Frontend: "dockerfile.v0", }) if err != nil { return nil, err @@ -864,9 +902,7 @@ func checkProgressStream(t *testing.T, sb integration.Sandbox, lintTest *lintTes f := getFrontend(t, sb) _, err := f.Solve(sb.Context(), lintTest.Client, client.SolveOpt{ - FrontendAttrs: map[string]string{ - "platform": "linux/amd64,linux/arm64", - }, + FrontendAttrs: lintTest.FrontendAttrs, LocalMounts: map[string]fsutil.FS{ dockerui.DefaultLocalNameDockerfile: lintTest.TmpDir, dockerui.DefaultLocalNameContext: lintTest.TmpDir, @@ -884,14 +920,6 @@ func checkProgressStream(t *testing.T, sb integration.Sandbox, lintTest *lintTes t.Fatalf("timed out waiting for statusDone") } - // two platforms only show one warning - if len(lintTest.Warnings) != len(warnings) { - // print warnings for debugging - for _, w := range warnings { - t.Logf("received warning: %q", w.Short) - } - } - require.Equal(t, len(lintTest.Warnings), len(warnings)) sort.Slice(warnings, func(i, j int) bool { w1 := warnings[i] @@ -985,4 +1013,5 @@ type lintTestParams struct { StreamBuildErr string UnmarshalBuildErr string BuildErrLocation int32 + FrontendAttrs map[string]string }