|
@@ -4,6 +4,7 @@ import (
|
|
|
"context"
|
|
|
"encoding/json"
|
|
|
"fmt"
|
|
|
+ "strconv"
|
|
|
"strings"
|
|
|
|
|
|
distref "github.com/docker/distribution/reference"
|
|
@@ -18,7 +19,9 @@ import (
|
|
|
)
|
|
|
|
|
|
const (
|
|
|
- keyImageName = "name"
|
|
|
+ keyImageName = "name"
|
|
|
+ keyBuildInfo = "buildinfo"
|
|
|
+ keyBuildInfoAttrs = "buildinfo-attrs"
|
|
|
)
|
|
|
|
|
|
// Differ can make a moby layer from a snapshot
|
|
@@ -44,11 +47,34 @@ 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}
|
|
|
+ i := &imageExporterInstance{
|
|
|
+ imageExporter: e,
|
|
|
+ buildInfo: true,
|
|
|
+ }
|
|
|
for k, v := range opt {
|
|
|
switch k {
|
|
|
case keyImageName:
|
|
|
i.targetName = v
|
|
|
+ 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)
|
|
@@ -61,8 +87,10 @@ func (e *imageExporter) Resolve(ctx context.Context, opt map[string]string) (exp
|
|
|
|
|
|
type imageExporterInstance struct {
|
|
|
*imageExporter
|
|
|
- targetName string
|
|
|
- meta map[string][]byte
|
|
|
+ targetName string
|
|
|
+ meta map[string][]byte
|
|
|
+ buildInfo bool
|
|
|
+ buildInfoAttrs bool
|
|
|
}
|
|
|
|
|
|
func (e *imageExporterInstance) Name() string {
|
|
@@ -93,9 +121,13 @@ 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 {
|
|
@@ -109,6 +141,9 @@ func (e *imageExporterInstance) Export(ctx context.Context, inp exporter.Source,
|
|
|
return 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
|
|
@@ -147,7 +182,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])
|
|
|
+ config, err = patchImageConfig(config, diffs, history, inp.Metadata[exptypes.ExporterInlineCache], buildInfo)
|
|
|
if err != nil {
|
|
|
return nil, err
|
|
|
}
|