Skip to content

Commit

Permalink
add test checking for a build-arg overwrite
Browse files Browse the repository at this point in the history
Signed-off-by: Talon Bowler <talon.bowler@docker.com>
  • Loading branch information
daghack committed May 31, 2024
1 parent 77b4008 commit 6f2e67d
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 19 deletions.
6 changes: 3 additions & 3 deletions frontend/dockerfile/dockerfile2llb/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
61 changes: 45 additions & 16 deletions frontend/dockerfile/dockerfile_lint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand All @@ -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]
Expand Down Expand Up @@ -985,4 +1013,5 @@ type lintTestParams struct {
StreamBuildErr string
UnmarshalBuildErr string
BuildErrLocation int32
FrontendAttrs map[string]string
}

0 comments on commit 6f2e67d

Please sign in to comment.