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>
This commit is contained in:
parent
e068c38618
commit
6588b3eef0
2 changed files with 5 additions and 49 deletions
|
@ -4,7 +4,6 @@ import (
|
|||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
distref "github.com/docker/distribution/reference"
|
||||
|
@ -18,9 +17,7 @@ import (
|
|||
)
|
||||
|
||||
const (
|
||||
keyImageName = "name"
|
||||
keyBuildInfo = "buildinfo"
|
||||
keyBuildInfoAttrs = "buildinfo-attrs"
|
||||
keyImageName = "name"
|
||||
)
|
||||
|
||||
// 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) {
|
||||
i := &imageExporterInstance{
|
||||
imageExporter: e,
|
||||
buildInfo: true,
|
||||
}
|
||||
for k, v := range opt {
|
||||
switch k {
|
||||
|
@ -60,26 +56,6 @@ func (e *imageExporter) Resolve(ctx context.Context, opt map[string]string) (exp
|
|||
}
|
||||
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:
|
||||
if i.meta == nil {
|
||||
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 {
|
||||
*imageExporter
|
||||
targetNames []distref.Named
|
||||
meta map[string][]byte
|
||||
buildInfo bool
|
||||
buildInfoAttrs bool
|
||||
targetNames []distref.Named
|
||||
meta map[string][]byte
|
||||
}
|
||||
|
||||
func (e *imageExporterInstance) Name() string {
|
||||
|
@ -122,13 +96,9 @@ func (e *imageExporterInstance) Export(ctx context.Context, inp *exporter.Source
|
|||
}
|
||||
|
||||
var config []byte
|
||||
var buildInfo []byte
|
||||
switch len(inp.Refs) {
|
||||
case 0:
|
||||
config = inp.Metadata[exptypes.ExporterImageConfigKey]
|
||||
if v, ok := inp.Metadata[exptypes.ExporterBuildInfo]; ok {
|
||||
buildInfo = v
|
||||
}
|
||||
case 1:
|
||||
platformsBytes, ok := inp.Metadata[exptypes.ExporterPlatformsKey]
|
||||
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))
|
||||
}
|
||||
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
|
||||
|
@ -187,7 +154,7 @@ func (e *imageExporterInstance) Export(ctx context.Context, inp *exporter.Source
|
|||
|
||||
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 {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
|
|
@ -7,7 +7,6 @@ import (
|
|||
|
||||
"github.com/containerd/containerd/platforms"
|
||||
"github.com/moby/buildkit/cache"
|
||||
binfotypes "github.com/moby/buildkit/util/buildinfo/types"
|
||||
"github.com/moby/buildkit/util/progress"
|
||||
"github.com/moby/buildkit/util/system"
|
||||
"github.com/opencontainers/go-digest"
|
||||
|
@ -43,7 +42,7 @@ func parseHistoryFromConfig(dt []byte) ([]ocispec.History, error) {
|
|||
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{}
|
||||
if err := json.Unmarshal(dt, &m); err != nil {
|
||||
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
|
||||
}
|
||||
|
||||
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)
|
||||
return dt, errors.Wrap(err, "failed to marshal config after patch")
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue