44 "context"
55 "encoding/json"
66 "fmt"
7+ "strconv"
78 "strings"
89
910 distref "github.com/docker/distribution/reference"
@@ -18,7 +19,9 @@ import (
1819)
1920
2021const (
21- keyImageName = "name"
22+ keyImageName = "name"
23+ keyBuildInfo = "buildinfo"
24+ keyBuildInfoAttrs = "buildinfo-attrs"
2225)
2326
2427// Differ can make a moby layer from a snapshot
@@ -44,11 +47,34 @@ func New(opt Opt) (exporter.Exporter, error) {
4447}
4548
4649func (e * imageExporter ) Resolve (ctx context.Context , opt map [string ]string ) (exporter.ExporterInstance , error ) {
47- i := & imageExporterInstance {imageExporter : e }
50+ i := & imageExporterInstance {
51+ imageExporter : e ,
52+ buildInfo : true ,
53+ }
4854 for k , v := range opt {
4955 switch k {
5056 case keyImageName :
5157 i .targetName = v
58+ case keyBuildInfo :
59+ if v == "" {
60+ i .buildInfo = true
61+ continue
62+ }
63+ b , err := strconv .ParseBool (v )
64+ if err != nil {
65+ return nil , errors .Wrapf (err , "non-bool value specified for %s" , k )
66+ }
67+ i .buildInfo = b
68+ case keyBuildInfoAttrs :
69+ if v == "" {
70+ i .buildInfoAttrs = false
71+ continue
72+ }
73+ b , err := strconv .ParseBool (v )
74+ if err != nil {
75+ return nil , errors .Wrapf (err , "non-bool value specified for %s" , k )
76+ }
77+ i .buildInfoAttrs = b
5278 default :
5379 if i .meta == nil {
5480 i .meta = make (map [string ][]byte )
@@ -61,8 +87,10 @@ func (e *imageExporter) Resolve(ctx context.Context, opt map[string]string) (exp
6187
6288type imageExporterInstance struct {
6389 * imageExporter
64- targetName string
65- meta map [string ][]byte
90+ targetName string
91+ meta map [string ][]byte
92+ buildInfo bool
93+ buildInfoAttrs bool
6694}
6795
6896func (e * imageExporterInstance ) Name () string {
@@ -93,9 +121,13 @@ func (e *imageExporterInstance) Export(ctx context.Context, inp exporter.Source,
93121 }
94122
95123 var config []byte
124+ var buildInfo []byte
96125 switch len (inp .Refs ) {
97126 case 0 :
98127 config = inp .Metadata [exptypes .ExporterImageConfigKey ]
128+ if v , ok := inp .Metadata [exptypes .ExporterBuildInfo ]; ok {
129+ buildInfo = v
130+ }
99131 case 1 :
100132 platformsBytes , ok := inp .Metadata [exptypes .ExporterPlatformsKey ]
101133 if ! ok {
@@ -109,6 +141,9 @@ func (e *imageExporterInstance) Export(ctx context.Context, inp exporter.Source,
109141 return nil , errors .Errorf ("number of platforms does not match references %d %d" , len (p .Platforms ), len (inp .Refs ))
110142 }
111143 config = inp .Metadata [fmt .Sprintf ("%s/%s" , exptypes .ExporterImageConfigKey , p .Platforms [0 ].ID )]
144+ if v , ok := inp .Metadata [fmt .Sprintf ("%s/%s" , exptypes .ExporterBuildInfo , p .Platforms [0 ].ID )]; ok {
145+ buildInfo = v
146+ }
112147 }
113148
114149 var diffs []digest.Digest
@@ -147,7 +182,7 @@ func (e *imageExporterInstance) Export(ctx context.Context, inp exporter.Source,
147182
148183 diffs , history = normalizeLayersAndHistory (diffs , history , ref )
149184
150- config , err = patchImageConfig (config , diffs , history , inp .Metadata [exptypes .ExporterInlineCache ])
185+ config , err = patchImageConfig (config , diffs , history , inp .Metadata [exptypes .ExporterInlineCache ], buildInfo )
151186 if err != nil {
152187 return nil , err
153188 }
0 commit comments