Procházet zdrojové kódy

builder: Remove buildkit's build information

Buildkit deprecated build information in v0.11 and will remove it in v0.12.
It's suggested to use provenance attestations instead.

Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
Paweł Gronowski před 2 roky
rodič
revize
6588b3eef0

+ 4 - 37
builder/builder-next/exporter/export.go

@@ -4,7 +4,6 @@ import (
 	"context"
 	"context"
 	"encoding/json"
 	"encoding/json"
 	"fmt"
 	"fmt"
-	"strconv"
 	"strings"
 	"strings"
 
 
 	distref "github.com/docker/distribution/reference"
 	distref "github.com/docker/distribution/reference"
@@ -18,9 +17,7 @@ import (
 )
 )
 
 
 const (
 const (
-	keyImageName      = "name"
-	keyBuildInfo      = "buildinfo"
-	keyBuildInfoAttrs = "buildinfo-attrs"
+	keyImageName = "name"
 )
 )
 
 
 // Differ can make a moby layer from a snapshot
 // Differ can make a moby layer from a snapshot
@@ -48,7 +45,6 @@ func New(opt Opt) (exporter.Exporter, error) {
 func (e *imageExporter) Resolve(ctx context.Context, opt map[string]string) (exporter.ExporterInstance, error) {
 func (e *imageExporter) Resolve(ctx context.Context, opt map[string]string) (exporter.ExporterInstance, error) {
 	i := &imageExporterInstance{
 	i := &imageExporterInstance{
 		imageExporter: e,
 		imageExporter: e,
-		buildInfo:     true,
 	}
 	}
 	for k, v := range opt {
 	for k, v := range opt {
 		switch k {
 		switch k {
@@ -60,26 +56,6 @@ func (e *imageExporter) Resolve(ctx context.Context, opt map[string]string) (exp
 				}
 				}
 				i.targetNames = append(i.targetNames, ref)
 				i.targetNames = append(i.targetNames, ref)
 			}
 			}
-		case keyBuildInfo:
-			if v == "" {
-				i.buildInfo = true
-				continue
-			}
-			b, err := strconv.ParseBool(v)
-			if err != nil {
-				return nil, errors.Wrapf(err, "non-bool value specified for %s", k)
-			}
-			i.buildInfo = b
-		case keyBuildInfoAttrs:
-			if v == "" {
-				i.buildInfoAttrs = false
-				continue
-			}
-			b, err := strconv.ParseBool(v)
-			if err != nil {
-				return nil, errors.Wrapf(err, "non-bool value specified for %s", k)
-			}
-			i.buildInfoAttrs = b
 		default:
 		default:
 			if i.meta == nil {
 			if i.meta == nil {
 				i.meta = make(map[string][]byte)
 				i.meta = make(map[string][]byte)
@@ -92,10 +68,8 @@ func (e *imageExporter) Resolve(ctx context.Context, opt map[string]string) (exp
 
 
 type imageExporterInstance struct {
 type imageExporterInstance struct {
 	*imageExporter
 	*imageExporter
-	targetNames    []distref.Named
-	meta           map[string][]byte
-	buildInfo      bool
-	buildInfoAttrs bool
+	targetNames []distref.Named
+	meta        map[string][]byte
 }
 }
 
 
 func (e *imageExporterInstance) Name() string {
 func (e *imageExporterInstance) Name() string {
@@ -122,13 +96,9 @@ func (e *imageExporterInstance) Export(ctx context.Context, inp *exporter.Source
 	}
 	}
 
 
 	var config []byte
 	var config []byte
-	var buildInfo []byte
 	switch len(inp.Refs) {
 	switch len(inp.Refs) {
 	case 0:
 	case 0:
 		config = inp.Metadata[exptypes.ExporterImageConfigKey]
 		config = inp.Metadata[exptypes.ExporterImageConfigKey]
-		if v, ok := inp.Metadata[exptypes.ExporterBuildInfo]; ok {
-			buildInfo = v
-		}
 	case 1:
 	case 1:
 		platformsBytes, ok := inp.Metadata[exptypes.ExporterPlatformsKey]
 		platformsBytes, ok := inp.Metadata[exptypes.ExporterPlatformsKey]
 		if !ok {
 		if !ok {
@@ -142,9 +112,6 @@ func (e *imageExporterInstance) Export(ctx context.Context, inp *exporter.Source
 			return nil, nil, errors.Errorf("number of platforms does not match references %d %d", len(p.Platforms), len(inp.Refs))
 			return nil, nil, errors.Errorf("number of platforms does not match references %d %d", len(p.Platforms), len(inp.Refs))
 		}
 		}
 		config = inp.Metadata[fmt.Sprintf("%s/%s", exptypes.ExporterImageConfigKey, p.Platforms[0].ID)]
 		config = inp.Metadata[fmt.Sprintf("%s/%s", exptypes.ExporterImageConfigKey, p.Platforms[0].ID)]
-		if v, ok := inp.Metadata[fmt.Sprintf("%s/%s", exptypes.ExporterBuildInfo, p.Platforms[0].ID)]; ok {
-			buildInfo = v
-		}
 	}
 	}
 
 
 	var diffs []digest.Digest
 	var diffs []digest.Digest
@@ -187,7 +154,7 @@ func (e *imageExporterInstance) Export(ctx context.Context, inp *exporter.Source
 
 
 	diffs, history = normalizeLayersAndHistory(diffs, history, ref)
 	diffs, history = normalizeLayersAndHistory(diffs, history, ref)
 
 
-	config, err = patchImageConfig(config, diffs, history, inp.Metadata[exptypes.ExporterInlineCache], buildInfo)
+	config, err = patchImageConfig(config, diffs, history, inp.Metadata[exptypes.ExporterInlineCache])
 	if err != nil {
 	if err != nil {
 		return nil, nil, err
 		return nil, nil, err
 	}
 	}

+ 1 - 12
builder/builder-next/exporter/writer.go

@@ -7,7 +7,6 @@ import (
 
 
 	"github.com/containerd/containerd/platforms"
 	"github.com/containerd/containerd/platforms"
 	"github.com/moby/buildkit/cache"
 	"github.com/moby/buildkit/cache"
-	binfotypes "github.com/moby/buildkit/util/buildinfo/types"
 	"github.com/moby/buildkit/util/progress"
 	"github.com/moby/buildkit/util/progress"
 	"github.com/moby/buildkit/util/system"
 	"github.com/moby/buildkit/util/system"
 	"github.com/opencontainers/go-digest"
 	"github.com/opencontainers/go-digest"
@@ -43,7 +42,7 @@ func parseHistoryFromConfig(dt []byte) ([]ocispec.History, error) {
 	return config.History, nil
 	return config.History, nil
 }
 }
 
 
-func patchImageConfig(dt []byte, dps []digest.Digest, history []ocispec.History, cache []byte, buildInfo []byte) ([]byte, error) {
+func patchImageConfig(dt []byte, dps []digest.Digest, history []ocispec.History, cache []byte) ([]byte, error) {
 	m := map[string]json.RawMessage{}
 	m := map[string]json.RawMessage{}
 	if err := json.Unmarshal(dt, &m); err != nil {
 	if err := json.Unmarshal(dt, &m); err != nil {
 		return nil, errors.Wrap(err, "failed to parse image config for patch")
 		return nil, errors.Wrap(err, "failed to parse image config for patch")
@@ -87,16 +86,6 @@ func patchImageConfig(dt []byte, dps []digest.Digest, history []ocispec.History,
 		m["moby.buildkit.cache.v0"] = dt
 		m["moby.buildkit.cache.v0"] = dt
 	}
 	}
 
 
-	if buildInfo != nil {
-		dt, err := json.Marshal(buildInfo)
-		if err != nil {
-			return nil, err
-		}
-		m[binfotypes.ImageConfigField] = dt
-	} else {
-		delete(m, binfotypes.ImageConfigField)
-	}
-
 	dt, err = json.Marshal(m)
 	dt, err = json.Marshal(m)
 	return dt, errors.Wrap(err, "failed to marshal config after patch")
 	return dt, errors.Wrap(err, "failed to marshal config after patch")
 }
 }