Skip to content
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions exporter/containerimage/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ func (e *imageExporter) Resolve(ctx context.Context, id int, opt map[string]stri
RefCfg: cacheconfig.RefConfig{
Compression: compression.New(compression.Default),
},
OCITypes: true,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we start considering changing the defaults in code? (Have a "DisableOCITypes" boolean, and start sunsetting the "OCITypes" bool)?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We discussed this a bit; @tonistiigi expressed a preference for keeping the exporter as-is for now, and just initializing the instance with the modified default.

ForceInlineAttestations: true,
},
store: true,
Expand Down
1 change: 1 addition & 0 deletions exporter/containerimage/exptypes/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ var (
OptKeyOCITypes ImageExporterOptKey = "oci-mediatypes"

// Use OCI artifact format for the attestation manifest.
// Value: bool <true|false>
OptKeyOCIArtifact ImageExporterOptKey = "oci-artifact"

// Force attestation to be attached.
Expand Down
41 changes: 4 additions & 37 deletions exporter/containerimage/opts.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
cacheconfig "github.com/moby/buildkit/cache/config"
"github.com/moby/buildkit/exporter/containerimage/exptypes"
"github.com/moby/buildkit/exporter/util/epoch"
"github.com/moby/buildkit/util/bklog"
"github.com/moby/buildkit/util/compression"
"github.com/pkg/errors"
)
Expand Down Expand Up @@ -49,7 +48,7 @@ func (c *ImageCommitOpts) Load(ctx context.Context, opt map[string]string) (map[
case exptypes.OptKeyName:
c.ImageName = v
case exptypes.OptKeyOCITypes:
err = parseBoolWithDefault(&c.OCITypes, k, v, true)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not handling the empty value in here seems like possibly breaking change. Don't remember the history behind it but maybe don't break it as it seems harmeless.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That change was made for the other types that originally used this parsing function, so based on that I'm relatively confident in/in favor of this change.

err = parseBool(&c.OCITypes, k, v)
case exptypes.OptKeyOCIArtifact:
err = parseBool(&c.OCIArtifact, k, v)
case exptypes.OptKeyForceInlineAttestations:
Expand All @@ -67,42 +66,18 @@ func (c *ImageCommitOpts) Load(ctx context.Context, opt map[string]string) (map[
}
}

if c.RefCfg.Compression.Type.OnlySupportOCITypes() {
c.EnableOCITypes(ctx, c.RefCfg.Compression.Type.String())
if c.RefCfg.Compression.Type.OnlySupportOCITypes() && !c.OCITypes {
return nil, errors.Errorf("exporter option \"compression=%s\" conflicts with \"oci-mediatypes=false\"", c.RefCfg.Compression.Type)
}
if c.OCIArtifact && !c.OCITypes {
c.EnableOCITypes(ctx, "oci-artifact")
return nil, errors.New("exporter option \"oci-artifact=true\" conflicts with \"oci-mediatypes=false\"")
}

c.Annotations = c.Annotations.Merge(as)

return rest, nil
}

func (c *ImageCommitOpts) EnableOCITypes(ctx context.Context, reason string) {
if !c.OCITypes {
message := "forcibly turning on oci-mediatype mode"
if reason != "" {
message += " for " + reason
}
bklog.G(ctx).Warn(message)

c.OCITypes = true
}
}

func (c *ImageCommitOpts) EnableForceCompression(ctx context.Context, reason string) {
if !c.RefCfg.Compression.Force {
message := "forcibly turning on force-compression mode"
if reason != "" {
message += " for " + reason
}
bklog.G(ctx).Warn(message)

c.RefCfg.Compression.Force = true
}
}

func parseBool(dest *bool, key string, value string) error {
b, err := strconv.ParseBool(value)
if err != nil {
Expand All @@ -112,14 +87,6 @@ func parseBool(dest *bool, key string, value string) error {
return nil
}

func parseBoolWithDefault(dest *bool, key string, value string, defaultValue bool) error {
if value == "" {
*dest = defaultValue
return nil
}
return parseBool(dest, key, value)
}

func toBytesMap(m map[string]string) map[string][]byte {
result := make(map[string][]byte)
for k, v := range m {
Expand Down
6 changes: 3 additions & 3 deletions exporter/containerimage/writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,13 +108,13 @@ func (ic *ImageWriter) Commit(ctx context.Context, inp *exporter.Source, session
}
}
if len(a.Index)+len(a.IndexDescriptor)+len(a.ManifestDescriptor) > 0 {
opts.EnableOCITypes(ctx, "annotations")
return nil, errors.New("cannot export annotations with \"oci-mediatypes=false\"")
}
}

if !isMap {
if len(ps.Platforms) > 1 {
return nil, errors.Errorf("cannot export multiple platforms without multi-platform enabled")
return nil, errors.New("cannot export multiple platforms without multi-platform enabled")
}

var ref cache.ImmutableRef
Expand Down Expand Up @@ -186,7 +186,7 @@ func (ic *ImageWriter) Commit(ctx context.Context, inp *exporter.Source, session
}

if len(inp.Attestations) > 0 {
opts.EnableOCITypes(ctx, "attestations")
return nil, errors.New("cannot export attestations with \"oci-mediatypes=false\"")
}

refs := make([]cache.ImmutableRef, 0, len(inp.Refs))
Expand Down
Loading