2017-03-09 06:03:46 +00:00
|
|
|
package rootfs
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
|
|
|
rootfsapi "github.com/docker/containerd/api/services/rootfs"
|
|
|
|
containerd_v1_types "github.com/docker/containerd/api/types/descriptor"
|
|
|
|
"github.com/docker/containerd/rootfs"
|
|
|
|
digest "github.com/opencontainers/go-digest"
|
|
|
|
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
|
|
|
|
)
|
|
|
|
|
2017-03-15 06:34:32 +00:00
|
|
|
func NewUnpackerFromClient(client rootfsapi.RootFSClient) rootfs.Unpacker {
|
|
|
|
return remoteUnpacker{
|
2017-03-09 06:03:46 +00:00
|
|
|
client: client,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-15 06:34:32 +00:00
|
|
|
type remoteUnpacker struct {
|
2017-03-09 06:03:46 +00:00
|
|
|
client rootfsapi.RootFSClient
|
|
|
|
}
|
|
|
|
|
2017-03-15 06:34:32 +00:00
|
|
|
func (rp remoteUnpacker) Unpack(ctx context.Context, layers []ocispec.Descriptor) (digest.Digest, error) {
|
|
|
|
pr := rootfsapi.UnpackRequest{
|
2017-03-09 06:03:46 +00:00
|
|
|
Layers: make([]*containerd_v1_types.Descriptor, len(layers)),
|
|
|
|
}
|
|
|
|
for i, l := range layers {
|
|
|
|
pr.Layers[i] = &containerd_v1_types.Descriptor{
|
|
|
|
MediaType: l.MediaType,
|
|
|
|
Digest: l.Digest,
|
2017-03-15 06:34:32 +00:00
|
|
|
Size_: l.Size,
|
2017-03-09 06:03:46 +00:00
|
|
|
}
|
|
|
|
}
|
2017-03-15 06:34:32 +00:00
|
|
|
resp, err := rp.client.Unpack(ctx, &pr)
|
2017-03-09 06:03:46 +00:00
|
|
|
if err != nil {
|
2017-03-16 00:17:25 +00:00
|
|
|
return "", err
|
2017-03-09 06:03:46 +00:00
|
|
|
}
|
|
|
|
return resp.ChainID, nil
|
|
|
|
}
|