Skip to content

Commit d89c43a

Browse files
authored
Merge pull request #107 from noxiouz/layers_order
isolate(porto): merge layers according to a manifest Scheme
2 parents 4d24ecd + 0499c40 commit d89c43a

File tree

2 files changed

+29
-3
lines changed

2 files changed

+29
-3
lines changed

isolate/porto/box.go

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ import (
2828
porto "github.com/yandex/porto/src/api/go"
2929
portorpc "github.com/yandex/porto/src/api/go/rpc"
3030

31-
_ "github.com/docker/distribution/manifest/schema1"
32-
_ "github.com/docker/distribution/manifest/schema2"
31+
"github.com/docker/distribution/manifest/schema1"
32+
"github.com/docker/distribution/manifest/schema2"
3333
"github.com/docker/distribution/reference"
3434
"github.com/docker/distribution/registry/client"
3535
"github.com/docker/distribution/registry/client/transport"
@@ -405,8 +405,17 @@ func (b *Box) Spool(ctx context.Context, name string, opts isolate.Profile) (err
405405
return err
406406
}
407407
apexctx.GetLogger(ctx).WithField("name", name).Infof("create a layer %s in Porto with merge", layerName)
408+
var order layersOrder
409+
switch manifest.(type) {
410+
case schema1.SignedManifest, *schema1.SignedManifest:
411+
order = layerOrderV1
412+
case schema2.DeserializedManifest, *schema2.DeserializedManifest:
413+
order = layerOrderV2
414+
default:
415+
return fmt.Errorf("unknown manifest type %T", manifest)
416+
}
408417

409-
for _, descriptor := range manifest.References() {
418+
for _, descriptor := range order(manifest.References()) {
410419
blobPath, err := b.blobRepo.Get(ctx, repo, descriptor.Digest)
411420
if err != nil {
412421
return err

isolate/porto/utils.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"sync/atomic"
88
"time"
99

10+
"github.com/docker/distribution"
1011
porto "github.com/yandex/porto/src/api/go"
1112
portorpc "github.com/yandex/porto/src/api/go/rpc"
1213
)
@@ -144,3 +145,19 @@ func portoConnect() (porto.API, error) {
144145
return nil, err
145146
}
146147
}
148+
149+
type layersOrder func(references []distribution.Descriptor) []distribution.Descriptor
150+
151+
var layerOrderV1 layersOrder = func(references []distribution.Descriptor) []distribution.Descriptor {
152+
return func(slice []distribution.Descriptor) []distribution.Descriptor {
153+
size := len(slice) - 1
154+
for i := 0; i < len(slice)/2; i++ {
155+
slice[i], slice[size-i] = slice[size-i], slice[i]
156+
}
157+
return slice
158+
}(references)
159+
}
160+
161+
var layerOrderV2 layersOrder = func(references []distribution.Descriptor) []distribution.Descriptor {
162+
return references
163+
}

0 commit comments

Comments
 (0)