Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion cache/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1747,7 +1747,7 @@ func TestGetRemotes(t *testing.T) {
case compression.EStargz:
require.Equal(t, ocispecs.MediaTypeImageLayerGzip, desc.MediaType)
case compression.Zstd:
require.Equal(t, ocispecs.MediaTypeImageLayer+"+zstd", desc.MediaType)
require.Equal(t, ocispecs.MediaTypeImageLayerZstd, desc.MediaType)
default:
require.Fail(t, "unhandled media type", compressionType)
}
Expand Down
2 changes: 1 addition & 1 deletion client/client_nydus_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ func testBuildExportNydusWithHybrid(t *testing.T, sb integration.Sandbox) {

mediaTypes := map[compression.Type]string{
compression.Gzip: ocispecs.MediaTypeImageLayerGzip,
compression.Zstd: ocispecs.MediaTypeImageLayer + "+zstd",
compression.Zstd: ocispecs.MediaTypeImageLayerZstd,
}
target := fmt.Sprintf("%s/%s/alpine:%s", registry, compType, identity.NewID())
_, err = c.Solve(sb.Context(), def, SolveOpt{
Expand Down
14 changes: 7 additions & 7 deletions client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2464,7 +2464,7 @@ func testSessionExporter(t *testing.T, sb integration.Sandbox) {

require.Equal(t, 2, len(mfst.Layers))
for _, layer := range mfst.Layers {
require.Contains(t, layer.MediaType, "application/vnd.oci.image.layer.v1.tar+zstd")
require.Contains(t, layer.MediaType, ocispecs.MediaTypeImageLayerZstd)
}
}

Expand Down Expand Up @@ -3485,7 +3485,7 @@ func testMultipleExporters(t *testing.T, sb integration.Sandbox) {
Type: ExporterImage,
Attrs: map[string]string{
"name": target2,
"oci-mediatypes": "true",
"oci-mediatypes": "false",
},
},
}...)
Expand Down Expand Up @@ -4866,7 +4866,7 @@ func testBuildExportZstd(t *testing.T, sb integration.Sandbox) {
require.NoError(t, err)

lastLayer := mfst.Layers[len(mfst.Layers)-1]
require.Equal(t, ocispecs.MediaTypeImageLayer+"+zstd", lastLayer.MediaType)
require.Equal(t, ocispecs.MediaTypeImageLayerZstd, lastLayer.MediaType)

zstdLayerDigest := lastLayer.Digest.Hex()
require.Equal(t, []byte{0x28, 0xb5, 0x2f, 0xfd}, m[ocispecs.ImageBlobsDir+"/sha256/"+zstdLayerDigest].Data[:4])
Expand Down Expand Up @@ -4902,7 +4902,7 @@ func testBuildExportZstd(t *testing.T, sb integration.Sandbox) {
require.NoError(t, err)

lastLayer = mfst.Layers[len(mfst.Layers)-1]
require.Equal(t, images.MediaTypeDockerSchema2Layer+".zstd", lastLayer.MediaType)
require.Equal(t, images.MediaTypeDockerSchema2LayerZstd, lastLayer.MediaType)

require.Equal(t, lastLayer.Digest.Hex(), zstdLayerDigest)
}
Expand Down Expand Up @@ -4989,9 +4989,9 @@ func testPullZstdImage(t *testing.T, sb integration.Sandbox) {

firstLayer := mfst.Layers[0]
if ociMediaTypes {
require.Equal(t, ocispecs.MediaTypeImageLayer+"+zstd", firstLayer.MediaType)
require.Equal(t, ocispecs.MediaTypeImageLayerZstd, firstLayer.MediaType)
} else {
require.Equal(t, images.MediaTypeDockerSchema2Layer+".zstd", firstLayer.MediaType)
require.Equal(t, images.MediaTypeDockerSchema2LayerZstd, firstLayer.MediaType)
}

zstdLayerDigest := firstLayer.Digest.Hex()
Expand Down Expand Up @@ -5906,7 +5906,7 @@ func testZstdLocalCacheExport(t *testing.T, sb integration.Sandbox) {
require.NoError(t, err)

lastLayer := layerIndex.Manifests[len(layerIndex.Manifests)-2]
require.Equal(t, ocispecs.MediaTypeImageLayer+"+zstd", lastLayer.MediaType)
require.Equal(t, ocispecs.MediaTypeImageLayerZstd, lastLayer.MediaType)

zstdLayerDigest := lastLayer.Digest.Hex()
dt, err = os.ReadFile(filepath.Join(destDir, ocispecs.ImageBlobsDir+"/sha256/"+zstdLayerDigest))
Expand Down
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
10 changes: 3 additions & 7 deletions util/compression/compression.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,6 @@ func (c Config) SetLevel(l int) Config {
return c
}

const (
mediaTypeDockerSchema2LayerZstd = images.MediaTypeDockerSchema2Layer + ".zstd"
)

var Default = Gzip

func parse(t string) (Type, error) {
Expand Down Expand Up @@ -191,8 +187,8 @@ var toDockerLayerType = map[string]string{
images.MediaTypeDockerSchema2LayerForeignGzip: images.MediaTypeDockerSchema2LayerForeignGzip,
ocispecs.MediaTypeImageLayerNonDistributable: images.MediaTypeDockerSchema2LayerForeign, //nolint:staticcheck // ignore SA1019: Non-distributable layers are deprecated, and not recommended for future use.
ocispecs.MediaTypeImageLayerNonDistributableGzip: images.MediaTypeDockerSchema2LayerForeignGzip, //nolint:staticcheck // ignore SA1019: Non-distributable layers are deprecated, and not recommended for future use.
ocispecs.MediaTypeImageLayerZstd: mediaTypeDockerSchema2LayerZstd,
mediaTypeDockerSchema2LayerZstd: mediaTypeDockerSchema2LayerZstd,
ocispecs.MediaTypeImageLayerZstd: images.MediaTypeDockerSchema2LayerZstd:,
images.MediaTypeDockerSchema2LayerZstd: images.MediaTypeDockerSchema2LayerZstd:,
}

var toOCILayerType = map[string]string{
Expand All @@ -206,7 +202,7 @@ var toOCILayerType = map[string]string{
images.MediaTypeDockerSchema2LayerForeign: ocispecs.MediaTypeImageLayerNonDistributable, //nolint:staticcheck // ignore SA1019: Non-distributable layers are deprecated, and not recommended for future use.
images.MediaTypeDockerSchema2LayerForeignGzip: ocispecs.MediaTypeImageLayerNonDistributableGzip, //nolint:staticcheck // ignore SA1019: Non-distributable layers are deprecated, and not recommended for future use.
ocispecs.MediaTypeImageLayerZstd: ocispecs.MediaTypeImageLayerZstd,
mediaTypeDockerSchema2LayerZstd: ocispecs.MediaTypeImageLayerZstd,
images.MediaTypeDockerSchema2LayerZstd: ocispecs.MediaTypeImageLayerZstd,
}

func convertLayerMediaType(ctx context.Context, mediaType string, oci bool) string {
Expand Down
2 changes: 1 addition & 1 deletion util/winlayers/applier.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ type winApplier struct {
func (s *winApplier) Apply(ctx context.Context, desc ocispecs.Descriptor, mounts []mount.Mount, opts ...diff.ApplyOpt) (d ocispecs.Descriptor, err error) {
// HACK:, containerd doesn't know about vnd.docker.image.rootfs.diff.tar.zstd, but that
// media type is compatible w/ the oci type, so just lie and say it's the oci type
if desc.MediaType == images.MediaTypeDockerSchema2Layer+".zstd" {
if desc.MediaType == images.MediaTypeDockerSchema2LayerZstd {
desc.MediaType = ocispecs.MediaTypeImageLayerZstd
}

Expand Down
Loading