images, services/images: implement image service

Server and Client images of the image store are now provided. We have
created an image metadata interface and converted the bolt functions to
implement that interface over an transaction. A remote client
implementation is provided that implements the same interface.

Signed-off-by: Stephen J Day <stephen.day@docker.com>
This commit is contained in:
Stephen J Day 2017-04-03 18:33:24 -07:00
parent a5c9d6d41b
commit 1ea809dc2a
No known key found for this signature in database
GPG key ID: 67B3DED84EDC823F
5 changed files with 280 additions and 45 deletions

60
services/images/client.go Normal file
View file

@ -0,0 +1,60 @@
package images
import (
"context"
imagesapi "github.com/containerd/containerd/api/services/images"
"github.com/containerd/containerd/images"
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
)
type remoteStore struct {
client imagesapi.ImagesClient
}
func NewStoreFromClient(client imagesapi.ImagesClient) images.Store {
return &remoteStore{
client: client,
}
}
func (s *remoteStore) Put(ctx context.Context, name string, desc ocispec.Descriptor) error {
// TODO(stevvooe): Consider that the remote may want to augment and return
// a modified image.
_, err := s.client.Put(ctx, &imagesapi.PutRequest{
Image: imagesapi.Image{
Name: name,
Target: descToProto(&desc),
},
})
return rewriteGRPCError(err)
}
func (s *remoteStore) Get(ctx context.Context, name string) (images.Image, error) {
resp, err := s.client.Get(ctx, &imagesapi.GetRequest{
Name: name,
})
if err != nil {
return images.Image{}, rewriteGRPCError(err)
}
return imageFromProto(resp.Image), nil
}
func (s *remoteStore) List(ctx context.Context) ([]images.Image, error) {
resp, err := s.client.List(ctx, &imagesapi.ListRequest{})
if err != nil {
return nil, rewriteGRPCError(err)
}
return imagesFromProto(resp.Images), nil
}
func (s *remoteStore) Delete(ctx context.Context, name string) error {
_, err := s.client.Delete(ctx, &imagesapi.DeleteRequest{
Name: name,
})
return rewriteGRPCError(err)
}