Skip to content

Commit 34d3c17

Browse files
author
Maksym Pavlenko
authored
Merge pull request containerd#10291 from ktock/push-platform-conf
Transfer: Push: Enable to specify platforms
2 parents 4c27379 + 5611fdd commit 34d3c17

File tree

4 files changed

+22
-16
lines changed

4 files changed

+22
-16
lines changed

cmd/ctr/commands/images/push.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,14 @@ var pushCommand = &cli.Command{
112112
if err != nil {
113113
return err
114114
}
115-
is := image.NewStore(local)
115+
var p []ocispec.Platform
116+
if pss := context.StringSlice("platform"); len(pss) > 0 {
117+
p, err = platforms.ParseAll(pss)
118+
if err != nil {
119+
return fmt.Errorf("invalid platform %v: %w", pss, err)
120+
}
121+
}
122+
is := image.NewStore(local, image.WithPlatforms(p...))
116123

117124
pf, done := ProgressHandler(ctx, os.Stdout)
118125
defer done()

core/transfer/image/imagestore.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,10 @@ func (is *Store) Lookup(ctx context.Context, store images.Store) ([]images.Image
348348
return imgs, nil
349349
}
350350

351+
func (is *Store) Platforms() []ocispec.Platform {
352+
return is.platforms
353+
}
354+
351355
func (is *Store) UnpackPlatforms() []transfer.UnpackConfiguration {
352356
unpacks := make([]transfer.UnpackConfiguration, len(is.unpacks))
353357
for i, uc := range is.unpacks {

core/transfer/local/push.go

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -33,22 +33,12 @@ import (
3333
)
3434

3535
func (ts *localTransferService) push(ctx context.Context, ig transfer.ImageGetter, p transfer.ImagePusher, tops *transfer.Config) error {
36-
/*
37-
// TODO: Platform matching
38-
if pushCtx.PlatformMatcher == nil {
39-
if len(pushCtx.Platforms) > 0 {
40-
ps, err := platforms.ParseAll(pushCtx.Platforms)
41-
if err != nil {
42-
return err
43-
}
44-
pushCtx.PlatformMatcher = platforms.Any(ps...)
45-
} else {
46-
pushCtx.PlatformMatcher = platforms.All
47-
}
48-
}
49-
*/
5036
matcher := platforms.All
51-
// Filter push
37+
if ipg, ok := ig.(transfer.ImagePlatformsGetter); ok {
38+
if ps := ipg.Platforms(); len(ps) > 0 {
39+
matcher = platforms.Any(ps...)
40+
}
41+
}
5242

5343
img, err := ig.Get(ctx, ts.images)
5444
if err != nil {

core/transfer/transfer.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,11 @@ type ImageUnpacker interface {
100100
UnpackPlatforms() []UnpackConfiguration
101101
}
102102

103+
// ImagePlatformsGetter is type which returns configured platforms.
104+
type ImagePlatformsGetter interface {
105+
Platforms() []ocispec.Platform
106+
}
107+
103108
// UnpackConfiguration specifies the platform and snapshotter to use for resolving
104109
// the unpack Platform, if snapshotter is not specified the platform default will
105110
// be used.

0 commit comments

Comments
 (0)