Skip to content

Commit

Permalink
provenance: set default mode=max if not set
Browse files Browse the repository at this point in the history
Signed-off-by: Justin Chadwell <me@jedevc.com>
  • Loading branch information
jedevc committed Dec 6, 2022
1 parent 3e3618b commit 8e107a6
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 10 deletions.
20 changes: 13 additions & 7 deletions frontend/dockerfile/dockerfile_provenance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,18 @@ RUN echo "ok" > /foo
)
require.NoError(t, err)

for _, mode := range []string{"min", "max"} {
for _, mode := range []string{"", "min", "max"} {
t.Run(mode, func(t *testing.T) {
target := registry + "/buildkit/testwithprovenance:" + mode
var target string
if target == "" {
target = registry + "/buildkit/testwithprovenance:none"
} else {
target = registry + "/buildkit/testwithprovenance:" + mode
}

provReq := ""
if mode == "max" {
provReq = "mode=max"
if mode != "" {
provReq = "mode=" + mode
}
_, err = f.Solve(sb.Context(), c, client.SolveOpt{
LocalDirs: map[string]string{
Expand Down Expand Up @@ -129,7 +135,7 @@ RUN echo "ok" > /foo
} else if isGateway {
require.Equal(t, "gateway.v0", pred.Invocation.Parameters.Frontend)

if mode == "max" {
if mode == "max" || mode == "" {
require.Equal(t, 3, len(args), "%v", args)
require.True(t, pred.Metadata.Completeness.Parameters)

Expand All @@ -144,7 +150,7 @@ RUN echo "ok" > /foo
} else {
require.Equal(t, "dockerfile.v0", pred.Invocation.Parameters.Frontend)

if mode == "max" {
if mode == "max" || mode == "" {
require.Equal(t, 2, len(args))
require.True(t, pred.Metadata.Completeness.Parameters)

Expand Down Expand Up @@ -193,7 +199,7 @@ RUN echo "ok" > /foo
require.False(t, pred.Metadata.Reproducible)
require.False(t, pred.Metadata.Completeness.Hermetic)

if mode == "max" {
if mode == "max" || mode == "" {
require.Equal(t, 2, len(pred.Metadata.BuildKitMetadata.Layers))
require.NotNil(t, pred.Metadata.BuildKitMetadata.Source)
require.Equal(t, "Dockerfile", pred.Metadata.BuildKitMetadata.Source.Infos[0].Filename)
Expand Down
9 changes: 6 additions & 3 deletions solver/llbsolver/proc/provenance.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func ProvenanceProcessor(attrs map[string]string) llbsolver.Processor {
reproducible = b
}

var mode string
mode := "max"
if v, ok := attrs["mode"]; ok {
switch v {
case "full":
Expand Down Expand Up @@ -90,7 +90,8 @@ func ProvenanceProcessor(attrs map[string]string) llbsolver.Processor {

var addLayers func() error

if mode != "max" {
switch mode {
case "min":
args := make(map[string]string)
for k, v := range pr.Invocation.Parameters.Args {
if strings.HasPrefix(k, "build-arg:") || strings.HasPrefix(k, "label:") {
Expand All @@ -102,7 +103,7 @@ func ProvenanceProcessor(attrs map[string]string) llbsolver.Processor {
pr.Invocation.Parameters.Args = args
pr.Invocation.Parameters.Secrets = nil
pr.Invocation.Parameters.SSH = nil
} else {
case "max":
dgsts, err := provenance.AddBuildConfig(ctx, pr, res.Refs[p.ID])
if err != nil {
return nil, err
Expand Down Expand Up @@ -144,6 +145,8 @@ func ProvenanceProcessor(attrs map[string]string) llbsolver.Processor {

return nil
}
default:
return nil, errors.Errorf("invalid mode %q", mode)
}

res.AddAttestation(p.ID, result.Attestation{
Expand Down

0 comments on commit 8e107a6

Please sign in to comment.