Skip to content

Commit f1c323c

Browse files
committed
[ported] Remove dependency on docker schemav1
It's been removed in containerd v2 so it should be removed from the ported function as well Signed-off-by: Baptiste Girard-Carrabin <[email protected]>
1 parent 53778f1 commit f1c323c

File tree

1 file changed

+44
-57
lines changed

1 file changed

+44
-57
lines changed

pkg/content/ported.go

Lines changed: 44 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,6 @@ import (
2929
"github.com/containerd/errdefs"
3030
"github.com/containerd/log"
3131
"github.com/containerd/platforms"
32-
33-
// nolint:staticcheck
34-
"github.com/containerd/containerd/v2/core/remotes/docker/schema1"
3532
"github.com/opencontainers/go-digest"
3633
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
3734
"golang.org/x/sync/semaphore"
@@ -41,7 +38,7 @@ import (
4138
var fetchSingleflight = &singleflight.Group{}
4239

4340
// Ported from containerd project, copyright The containerd Authors.
44-
// github.com/containerd/containerd/blob/main/pull.go
41+
// github.com/containerd/containerd/blob/main/client/pull.go
4542
func fetch(ctx context.Context, store content.Store, rCtx *client.RemoteContext, ref string, limit int) (images.Image, error) {
4643
name, desc, err := rCtx.Resolver.Resolve(ctx, ref)
4744
if err != nil {
@@ -61,66 +58,56 @@ func fetch(ctx context.Context, store content.Store, rCtx *client.RemoteContext,
6158
limiter *semaphore.Weighted
6259
)
6360

64-
// nolint:staticcheck
65-
if desc.MediaType == images.MediaTypeDockerSchema1Manifest && rCtx.ConvertSchema1 {
66-
schema1Converter, err := schema1.NewConverter(store, fetcher)
67-
if err != nil {
68-
return images.Image{}, fmt.Errorf("failed to create schema1 converter: %w", err)
69-
}
70-
71-
handler = images.Handlers(append(rCtx.BaseHandlers, schema1Converter)...)
72-
73-
isConvertible = true
61+
if desc.MediaType == images.MediaTypeDockerSchema1Manifest {
62+
return images.Image{}, fmt.Errorf("%w: media type %q is no longer supported since containerd v2.1, please rebuild the image as %q or %q",
63+
errdefs.ErrNotImplemented,
64+
images.MediaTypeDockerSchema1Manifest, images.MediaTypeDockerSchema2Manifest, ocispec.MediaTypeImageManifest)
65+
}
7466

75-
converterFunc = func(ctx context.Context, _ ocispec.Descriptor) (ocispec.Descriptor, error) {
76-
return schema1Converter.Convert(ctx)
77-
}
67+
// Get all the children for a descriptor
68+
childrenHandler := images.ChildrenHandler(store)
69+
// Set any children labels for that content
70+
childrenHandler = images.SetChildrenMappedLabels(store, childrenHandler, rCtx.ChildLabelMap)
71+
if rCtx.AllMetadata {
72+
// Filter manifests by platforms but allow to handle manifest
73+
// and configuration for not-target platforms
74+
childrenHandler = remotes.FilterManifestByPlatformHandler(childrenHandler, rCtx.PlatformMatcher)
7875
} else {
79-
// Get all the children for a descriptor
80-
childrenHandler := images.ChildrenHandler(store)
81-
// Set any children labels for that content
82-
childrenHandler = images.SetChildrenMappedLabels(store, childrenHandler, rCtx.ChildLabelMap)
83-
if rCtx.AllMetadata {
84-
// Filter manifests by platforms but allow to handle manifest
85-
// and configuration for not-target platforms
86-
childrenHandler = remotes.FilterManifestByPlatformHandler(childrenHandler, rCtx.PlatformMatcher)
87-
} else {
88-
// Filter children by platforms if specified.
89-
childrenHandler = images.FilterPlatforms(childrenHandler, rCtx.PlatformMatcher)
90-
}
91-
// Sort and limit manifests if a finite number is needed
92-
if limit > 0 {
93-
childrenHandler = images.LimitManifests(childrenHandler, rCtx.PlatformMatcher, limit)
94-
}
76+
// Filter children by platforms if specified.
77+
childrenHandler = images.FilterPlatforms(childrenHandler, rCtx.PlatformMatcher)
78+
}
79+
// Sort and limit manifests if a finite number is needed
80+
if limit > 0 {
81+
childrenHandler = images.LimitManifests(childrenHandler, rCtx.PlatformMatcher, limit)
82+
}
9583

96-
// set isConvertible to true if there is application/octet-stream media type
97-
convertibleHandler := images.HandlerFunc(
98-
func(_ context.Context, desc ocispec.Descriptor) ([]ocispec.Descriptor, error) {
99-
if desc.MediaType == docker.LegacyConfigMediaType {
100-
isConvertible = true
101-
}
84+
// set isConvertible to true if there is application/octet-stream media type
85+
convertibleHandler := images.HandlerFunc(
86+
func(_ context.Context, desc ocispec.Descriptor) ([]ocispec.Descriptor, error) {
87+
if desc.MediaType == docker.LegacyConfigMediaType {
88+
isConvertible = true
89+
}
10290

103-
return []ocispec.Descriptor{}, nil
104-
},
105-
)
91+
return []ocispec.Descriptor{}, nil
92+
},
93+
)
10694

107-
appendDistSrcLabelHandler, err := docker.AppendDistributionSourceLabel(store, ref)
108-
if err != nil {
109-
return images.Image{}, err
110-
}
95+
appendDistSrcLabelHandler, err := docker.AppendDistributionSourceLabel(store, ref)
96+
if err != nil {
97+
return images.Image{}, err
98+
}
11199

112-
handlers := append(rCtx.BaseHandlers,
113-
fetchHandler(store, fetcher),
114-
convertibleHandler,
115-
childrenHandler,
116-
appendDistSrcLabelHandler,
117-
)
100+
handlers := append(rCtx.BaseHandlers,
101+
fetchHandler(store, fetcher),
102+
convertibleHandler,
103+
childrenHandler,
104+
appendDistSrcLabelHandler,
105+
)
118106

119-
handler = images.Handlers(handlers...)
107+
handler = images.Handlers(handlers...)
120108

121-
converterFunc = func(ctx context.Context, desc ocispec.Descriptor) (ocispec.Descriptor, error) {
122-
return docker.ConvertManifest(ctx, store, desc)
123-
}
109+
converterFunc = func(ctx context.Context, desc ocispec.Descriptor) (ocispec.Descriptor, error) {
110+
return docker.ConvertManifest(ctx, store, desc)
124111
}
125112

126113
if rCtx.HandlerWrapper != nil {
@@ -174,7 +161,7 @@ func fetchHandler(ingester content.Ingester, fetcher remotes.Fetcher) images.Han
174161
}
175162

176163
// Ported from containerd project, copyright The containerd Authors.
177-
// github.com/containerd/containerd/blob/main/client.go
164+
// github.com/containerd/containerd/blob/main/client/client.go
178165
func push(ctx context.Context, store content.Store, pushCtx *client.RemoteContext, desc ocispec.Descriptor, ref string) error {
179166
if pushCtx.PlatformMatcher == nil {
180167
if len(pushCtx.Platforms) > 0 {

0 commit comments

Comments
 (0)