buildinfo: change buildinfo attr export key to bool
Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>master
parent
fd0af43d77
commit
bb746566db
|
@ -237,7 +237,7 @@ Keys supported by image output:
|
||||||
* `compression=[uncompressed,gzip,estargz,zstd]`: choose compression type for layers newly created and cached, gzip is default value. estargz should be used with `oci-mediatypes=true`.
|
* `compression=[uncompressed,gzip,estargz,zstd]`: choose compression type for layers newly created and cached, gzip is default value. estargz should be used with `oci-mediatypes=true`.
|
||||||
* `compression-level=[value]`: compression level for gzip, estargz (0-9) and zstd (0-22)
|
* `compression-level=[value]`: compression level for gzip, estargz (0-9) and zstd (0-22)
|
||||||
* `force-compression=true`: forcefully apply `compression` option to all layers (including already existing layers).
|
* `force-compression=true`: forcefully apply `compression` option to all layers (including already existing layers).
|
||||||
* `buildinfo=[all,imageconfig,metadata,none]`: choose [build dependency](docs/build-repro.md#build-dependencies) version to export (default `all`).
|
* `buildinfo=true`: inline build info in [image config](docs/build-repro.md#image-config) (default `true`).
|
||||||
* `buildinfo-attrs=true`: inline build info attributes in [image config](docs/build-repro.md#image-config) (default `false`).
|
* `buildinfo-attrs=true`: inline build info attributes in [image config](docs/build-repro.md#image-config) (default `false`).
|
||||||
|
|
||||||
If credentials are required, `buildctl` will attempt to read Docker configuration file `$DOCKER_CONFIG/config.json`.
|
If credentials are required, `buildctl` will attempt to read Docker configuration file `$DOCKER_CONFIG/config.json`.
|
||||||
|
|
|
@ -6,9 +6,8 @@ Build dependencies are generated when your image has been built. These
|
||||||
dependencies include versions of used images, git repositories and HTTP URLs
|
dependencies include versions of used images, git repositories and HTTP URLs
|
||||||
used by LLB `Source` operation as well as build request attributes.
|
used by LLB `Source` operation as well as build request attributes.
|
||||||
|
|
||||||
By default, the build dependencies are embedded in the image configuration and
|
By default, the build dependencies are inlined in the image configuration. You
|
||||||
also available in the solver response. The export mode can be refined with
|
can disable this behavior with the [`buildinfo` attribute](../README.md#imageregistry).
|
||||||
the [`buildinfo` attribute](../README.md#imageregistry).
|
|
||||||
|
|
||||||
### Image config
|
### Image config
|
||||||
|
|
||||||
|
|
|
@ -22,7 +22,6 @@ import (
|
||||||
"github.com/moby/buildkit/exporter/containerimage/exptypes"
|
"github.com/moby/buildkit/exporter/containerimage/exptypes"
|
||||||
"github.com/moby/buildkit/session"
|
"github.com/moby/buildkit/session"
|
||||||
"github.com/moby/buildkit/snapshot"
|
"github.com/moby/buildkit/snapshot"
|
||||||
"github.com/moby/buildkit/util/buildinfo"
|
|
||||||
"github.com/moby/buildkit/util/compression"
|
"github.com/moby/buildkit/util/compression"
|
||||||
"github.com/moby/buildkit/util/contentutil"
|
"github.com/moby/buildkit/util/contentutil"
|
||||||
"github.com/moby/buildkit/util/leaseutil"
|
"github.com/moby/buildkit/util/leaseutil"
|
||||||
|
@ -79,7 +78,7 @@ func (e *imageExporter) Resolve(ctx context.Context, opt map[string]string) (exp
|
||||||
i := &imageExporterInstance{
|
i := &imageExporterInstance{
|
||||||
imageExporter: e,
|
imageExporter: e,
|
||||||
layerCompression: compression.Default,
|
layerCompression: compression.Default,
|
||||||
buildInfoMode: buildinfo.ExportDefault,
|
buildInfo: true,
|
||||||
}
|
}
|
||||||
|
|
||||||
var esgz bool
|
var esgz bool
|
||||||
|
@ -182,19 +181,14 @@ func (e *imageExporter) Resolve(ctx context.Context, opt map[string]string) (exp
|
||||||
i.compressionLevel = &v
|
i.compressionLevel = &v
|
||||||
case keyBuildInfo:
|
case keyBuildInfo:
|
||||||
if v == "" {
|
if v == "" {
|
||||||
|
i.buildInfo = true
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
bimode, err := buildinfo.ParseExportMode(v)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
i.buildInfoMode = bimode
|
|
||||||
case preferNondistLayersKey:
|
|
||||||
b, err := strconv.ParseBool(v)
|
b, err := strconv.ParseBool(v)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Wrapf(err, "non-bool value %s specified for %s", v, k)
|
return nil, errors.Wrapf(err, "non-bool value specified for %s", k)
|
||||||
}
|
}
|
||||||
i.preferNondistLayers = b
|
i.buildInfo = b
|
||||||
case keyBuildInfoAttrs:
|
case keyBuildInfoAttrs:
|
||||||
if v == "" {
|
if v == "" {
|
||||||
i.buildInfoAttrs = false
|
i.buildInfoAttrs = false
|
||||||
|
@ -205,6 +199,12 @@ func (e *imageExporter) Resolve(ctx context.Context, opt map[string]string) (exp
|
||||||
return nil, errors.Wrapf(err, "non-bool value specified for %s", k)
|
return nil, errors.Wrapf(err, "non-bool value specified for %s", k)
|
||||||
}
|
}
|
||||||
i.buildInfoAttrs = b
|
i.buildInfoAttrs = b
|
||||||
|
case preferNondistLayersKey:
|
||||||
|
b, err := strconv.ParseBool(v)
|
||||||
|
if err != nil {
|
||||||
|
return nil, errors.Wrapf(err, "non-bool value %s specified for %s", v, k)
|
||||||
|
}
|
||||||
|
i.preferNondistLayers = b
|
||||||
default:
|
default:
|
||||||
if i.meta == nil {
|
if i.meta == nil {
|
||||||
i.meta = make(map[string][]byte)
|
i.meta = make(map[string][]byte)
|
||||||
|
@ -232,10 +232,10 @@ type imageExporterInstance struct {
|
||||||
layerCompression compression.Type
|
layerCompression compression.Type
|
||||||
forceCompression bool
|
forceCompression bool
|
||||||
compressionLevel *int
|
compressionLevel *int
|
||||||
buildInfoMode buildinfo.ExportMode
|
buildInfo bool
|
||||||
|
buildInfoAttrs bool
|
||||||
meta map[string][]byte
|
meta map[string][]byte
|
||||||
preferNondistLayers bool
|
preferNondistLayers bool
|
||||||
buildInfoAttrs bool
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *imageExporterInstance) Name() string {
|
func (e *imageExporterInstance) Name() string {
|
||||||
|
@ -271,7 +271,7 @@ func (e *imageExporterInstance) Export(ctx context.Context, src exporter.Source,
|
||||||
defer done(context.TODO())
|
defer done(context.TODO())
|
||||||
|
|
||||||
refCfg := e.refCfg()
|
refCfg := e.refCfg()
|
||||||
desc, err := e.opt.ImageWriter.Commit(ctx, src, e.ociTypes, refCfg, e.buildInfoMode, e.buildInfoAttrs, sessionID)
|
desc, err := e.opt.ImageWriter.Commit(ctx, src, e.ociTypes, refCfg, e.buildInfo, e.buildInfoAttrs, sessionID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -280,15 +280,6 @@ func (e *imageExporterInstance) Export(ctx context.Context, src exporter.Source,
|
||||||
e.opt.ImageWriter.ContentStore().Delete(context.TODO(), desc.Digest)
|
e.opt.ImageWriter.ContentStore().Delete(context.TODO(), desc.Digest)
|
||||||
}()
|
}()
|
||||||
|
|
||||||
if e.buildInfoMode&buildinfo.ExportMetadata == 0 {
|
|
||||||
for k := range src.Metadata {
|
|
||||||
if !strings.HasPrefix(k, exptypes.ExporterBuildInfo) {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
delete(src.Metadata, k)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
resp := make(map[string]string)
|
resp := make(map[string]string)
|
||||||
|
|
||||||
if n, ok := src.Metadata["image.name"]; e.targetName == "*" && ok {
|
if n, ok := src.Metadata["image.name"]; e.targetName == "*" && ok {
|
||||||
|
|
|
@ -50,7 +50,7 @@ type ImageWriter struct {
|
||||||
opt WriterOpt
|
opt WriterOpt
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ic *ImageWriter) Commit(ctx context.Context, inp exporter.Source, oci bool, refCfg cacheconfig.RefConfig, buildInfoMode buildinfo.ExportMode, buildInfoAttrs bool, sessionID string) (*ocispecs.Descriptor, error) {
|
func (ic *ImageWriter) Commit(ctx context.Context, inp exporter.Source, oci bool, refCfg cacheconfig.RefConfig, buildInfo bool, buildInfoAttrs bool, sessionID string) (*ocispecs.Descriptor, error) {
|
||||||
platformsBytes, ok := inp.Metadata[exptypes.ExporterPlatformsKey]
|
platformsBytes, ok := inp.Metadata[exptypes.ExporterPlatformsKey]
|
||||||
|
|
||||||
if len(inp.Refs) > 0 && !ok {
|
if len(inp.Refs) > 0 && !ok {
|
||||||
|
@ -63,16 +63,16 @@ func (ic *ImageWriter) Commit(ctx context.Context, inp exporter.Source, oci bool
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
var buildInfo []byte
|
var dtbi []byte
|
||||||
if buildInfoMode&buildinfo.ExportImageConfig > 0 {
|
if buildInfo {
|
||||||
if buildInfo, err = buildinfo.Format(inp.Metadata[exptypes.ExporterBuildInfo], buildinfo.FormatOpts{
|
if dtbi, err = buildinfo.Format(inp.Metadata[exptypes.ExporterBuildInfo], buildinfo.FormatOpts{
|
||||||
RemoveAttrs: !buildInfoAttrs,
|
RemoveAttrs: !buildInfoAttrs,
|
||||||
}); err != nil {
|
}); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
mfstDesc, configDesc, err := ic.commitDistributionManifest(ctx, inp.Ref, inp.Metadata[exptypes.ExporterImageConfigKey], &remotes[0], oci, inp.Metadata[exptypes.ExporterInlineCache], buildInfo)
|
mfstDesc, configDesc, err := ic.commitDistributionManifest(ctx, inp.Ref, inp.Metadata[exptypes.ExporterImageConfigKey], &remotes[0], oci, inp.Metadata[exptypes.ExporterInlineCache], dtbi)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -134,16 +134,16 @@ func (ic *ImageWriter) Commit(ctx context.Context, inp exporter.Source, oci bool
|
||||||
config := inp.Metadata[fmt.Sprintf("%s/%s", exptypes.ExporterImageConfigKey, p.ID)]
|
config := inp.Metadata[fmt.Sprintf("%s/%s", exptypes.ExporterImageConfigKey, p.ID)]
|
||||||
inlineCache := inp.Metadata[fmt.Sprintf("%s/%s", exptypes.ExporterInlineCache, p.ID)]
|
inlineCache := inp.Metadata[fmt.Sprintf("%s/%s", exptypes.ExporterInlineCache, p.ID)]
|
||||||
|
|
||||||
var buildInfo []byte
|
var dtbi []byte
|
||||||
if buildInfoMode&buildinfo.ExportImageConfig > 0 {
|
if buildInfo {
|
||||||
if buildInfo, err = buildinfo.Format(inp.Metadata[fmt.Sprintf("%s/%s", exptypes.ExporterBuildInfo, p.ID)], buildinfo.FormatOpts{
|
if dtbi, err = buildinfo.Format(inp.Metadata[fmt.Sprintf("%s/%s", exptypes.ExporterBuildInfo, p.ID)], buildinfo.FormatOpts{
|
||||||
RemoveAttrs: !buildInfoAttrs,
|
RemoveAttrs: !buildInfoAttrs,
|
||||||
}); err != nil {
|
}); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
desc, _, err := ic.commitDistributionManifest(ctx, r, config, &remotes[remotesMap[p.ID]], oci, inlineCache, buildInfo)
|
desc, _, err := ic.commitDistributionManifest(ctx, r, config, &remotes[remotesMap[p.ID]], oci, inlineCache, dtbi)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,7 +18,6 @@ import (
|
||||||
"github.com/moby/buildkit/exporter/containerimage/exptypes"
|
"github.com/moby/buildkit/exporter/containerimage/exptypes"
|
||||||
"github.com/moby/buildkit/session"
|
"github.com/moby/buildkit/session"
|
||||||
"github.com/moby/buildkit/session/filesync"
|
"github.com/moby/buildkit/session/filesync"
|
||||||
"github.com/moby/buildkit/util/buildinfo"
|
|
||||||
"github.com/moby/buildkit/util/compression"
|
"github.com/moby/buildkit/util/compression"
|
||||||
"github.com/moby/buildkit/util/contentutil"
|
"github.com/moby/buildkit/util/contentutil"
|
||||||
"github.com/moby/buildkit/util/grpcerrors"
|
"github.com/moby/buildkit/util/grpcerrors"
|
||||||
|
@ -69,7 +68,7 @@ func (e *imageExporter) Resolve(ctx context.Context, opt map[string]string) (exp
|
||||||
i := &imageExporterInstance{
|
i := &imageExporterInstance{
|
||||||
imageExporter: e,
|
imageExporter: e,
|
||||||
layerCompression: compression.Default,
|
layerCompression: compression.Default,
|
||||||
buildInfoMode: buildinfo.ExportDefault,
|
buildInfo: true,
|
||||||
}
|
}
|
||||||
var esgz bool
|
var esgz bool
|
||||||
for k, v := range opt {
|
for k, v := range opt {
|
||||||
|
@ -120,19 +119,14 @@ func (e *imageExporter) Resolve(ctx context.Context, opt map[string]string) (exp
|
||||||
*ot = b
|
*ot = b
|
||||||
case keyBuildInfo:
|
case keyBuildInfo:
|
||||||
if v == "" {
|
if v == "" {
|
||||||
|
i.buildInfo = true
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
bimode, err := buildinfo.ParseExportMode(v)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
i.buildInfoMode = bimode
|
|
||||||
case preferNondistLayersKey:
|
|
||||||
b, err := strconv.ParseBool(v)
|
b, err := strconv.ParseBool(v)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Wrapf(err, "non-bool value specified for %s", k)
|
return nil, errors.Wrapf(err, "non-bool value specified for %s", k)
|
||||||
}
|
}
|
||||||
i.preferNonDist = b
|
i.buildInfo = b
|
||||||
case keyBuildInfoAttrs:
|
case keyBuildInfoAttrs:
|
||||||
if v == "" {
|
if v == "" {
|
||||||
i.buildInfoAttrs = false
|
i.buildInfoAttrs = false
|
||||||
|
@ -143,6 +137,12 @@ func (e *imageExporter) Resolve(ctx context.Context, opt map[string]string) (exp
|
||||||
return nil, errors.Wrapf(err, "non-bool value specified for %s", k)
|
return nil, errors.Wrapf(err, "non-bool value specified for %s", k)
|
||||||
}
|
}
|
||||||
i.buildInfoAttrs = b
|
i.buildInfoAttrs = b
|
||||||
|
case preferNondistLayersKey:
|
||||||
|
b, err := strconv.ParseBool(v)
|
||||||
|
if err != nil {
|
||||||
|
return nil, errors.Wrapf(err, "non-bool value specified for %s", k)
|
||||||
|
}
|
||||||
|
i.preferNonDist = b
|
||||||
default:
|
default:
|
||||||
if i.meta == nil {
|
if i.meta == nil {
|
||||||
i.meta = make(map[string][]byte)
|
i.meta = make(map[string][]byte)
|
||||||
|
@ -170,9 +170,9 @@ type imageExporterInstance struct {
|
||||||
layerCompression compression.Type
|
layerCompression compression.Type
|
||||||
forceCompression bool
|
forceCompression bool
|
||||||
compressionLevel *int
|
compressionLevel *int
|
||||||
buildInfoMode buildinfo.ExportMode
|
buildInfo bool
|
||||||
preferNonDist bool
|
|
||||||
buildInfoAttrs bool
|
buildInfoAttrs bool
|
||||||
|
preferNonDist bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *imageExporterInstance) Name() string {
|
func (e *imageExporterInstance) Name() string {
|
||||||
|
@ -218,7 +218,7 @@ func (e *imageExporterInstance) Export(ctx context.Context, src exporter.Source,
|
||||||
}
|
}
|
||||||
defer done(context.TODO())
|
defer done(context.TODO())
|
||||||
|
|
||||||
desc, err := e.opt.ImageWriter.Commit(ctx, src, e.ociTypes, e.refCfg(), e.buildInfoMode, e.buildInfoAttrs, sessionID)
|
desc, err := e.opt.ImageWriter.Commit(ctx, src, e.ociTypes, e.refCfg(), e.buildInfo, e.buildInfoAttrs, sessionID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -226,15 +226,6 @@ func (e *imageExporterInstance) Export(ctx context.Context, src exporter.Source,
|
||||||
e.opt.ImageWriter.ContentStore().Delete(context.TODO(), desc.Digest)
|
e.opt.ImageWriter.ContentStore().Delete(context.TODO(), desc.Digest)
|
||||||
}()
|
}()
|
||||||
|
|
||||||
if e.buildInfoMode&buildinfo.ExportMetadata == 0 {
|
|
||||||
for k := range src.Metadata {
|
|
||||||
if !strings.HasPrefix(k, exptypes.ExporterBuildInfo) {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
delete(src.Metadata, k)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if desc.Annotations == nil {
|
if desc.Annotations == nil {
|
||||||
desc.Annotations = map[string]string{}
|
desc.Annotations = map[string]string{}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,39 +0,0 @@
|
||||||
package buildinfo
|
|
||||||
|
|
||||||
import "github.com/pkg/errors"
|
|
||||||
|
|
||||||
// ExportMode represents the export mode for buildinfo opt.
|
|
||||||
type ExportMode int
|
|
||||||
|
|
||||||
const (
|
|
||||||
// ExportNone doesn't export build dependencies.
|
|
||||||
ExportNone ExportMode = 0
|
|
||||||
// ExportImageConfig exports build dependencies to
|
|
||||||
// the image config.
|
|
||||||
ExportImageConfig = 1 << iota
|
|
||||||
// ExportMetadata exports build dependencies as metadata to
|
|
||||||
// the exporter response.
|
|
||||||
ExportMetadata
|
|
||||||
// ExportAll exports build dependencies as metadata and
|
|
||||||
// image config.
|
|
||||||
ExportAll = -1
|
|
||||||
)
|
|
||||||
|
|
||||||
// ExportDefault is the default export mode for buildinfo opt.
|
|
||||||
const ExportDefault = ExportAll
|
|
||||||
|
|
||||||
// ParseExportMode returns the export mode matching a string.
|
|
||||||
func ParseExportMode(s string) (ExportMode, error) {
|
|
||||||
switch s {
|
|
||||||
case "none":
|
|
||||||
return ExportNone, nil
|
|
||||||
case "imageconfig":
|
|
||||||
return ExportImageConfig, nil
|
|
||||||
case "metadata":
|
|
||||||
return ExportMetadata, nil
|
|
||||||
case "all":
|
|
||||||
return ExportAll, nil
|
|
||||||
default:
|
|
||||||
return 0, errors.Errorf("unknown buildinfo export mode: %s", s)
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in New Issue