-
Notifications
You must be signed in to change notification settings - Fork 9
/
cachestore.go
101 lines (80 loc) · 2.86 KB
/
cachestore.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
// Copyright 2022 Namespace Labs Inc; All rights reserved.
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
package buildkit
import (
"context"
"fmt"
"os"
"github.com/containerd/containerd/content"
"github.com/containerd/containerd/errdefs"
"github.com/opencontainers/go-digest"
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
"google.golang.org/grpc/codes"
"namespacelabs.dev/foundation/framework/rpcerrors"
"namespacelabs.dev/foundation/internal/compute/cache"
"namespacelabs.dev/foundation/schema"
)
type cacheStore struct {
cache cache.Cache
}
var _ content.Store = &cacheStore{}
func (cs *cacheStore) Info(ctx context.Context, dgst digest.Digest) (content.Info, error) {
d, err := schema.ParseDigest(dgst.String())
if err != nil {
return content.Info{}, err
}
info, err := cs.cache.Stat(ctx, d)
if err != nil {
if os.IsNotExist(err) {
err = fmt.Errorf("content %v: %w", dgst, errdefs.ErrNotFound)
}
return content.Info{}, err
}
return content.Info{
Digest: dgst,
Size: info.Size(),
}, nil
}
func (cs *cacheStore) Update(ctx context.Context, info content.Info, fieldpaths ...string) (content.Info, error) {
return content.Info{}, rpcerrors.Errorf(codes.Unimplemented, "update: writes not supported")
}
func (cs *cacheStore) Walk(ctx context.Context, fn content.WalkFunc, filters ...string) error {
return rpcerrors.Errorf(codes.Unimplemented, "walk: not implemented")
}
// Delete removes the content from the store.
func (cs *cacheStore) Delete(ctx context.Context, dgst digest.Digest) error {
return rpcerrors.Errorf(codes.Unimplemented, "delete: writes not supported")
}
func (cs *cacheStore) ReaderAt(ctx context.Context, desc ocispec.Descriptor) (content.ReaderAt, error) {
d, err := schema.ParseDigest(desc.Digest.String())
if err != nil {
return nil, err
}
info, err := cs.cache.Stat(ctx, d)
if err != nil {
return nil, err
}
r, err := cs.cache.Blob(d)
if err != nil {
return nil, err
}
return storeReader{r, info.Size()}, nil
}
func (cs *cacheStore) Status(ctx context.Context, ref string) (content.Status, error) {
return content.Status{}, rpcerrors.Errorf(codes.Unimplemented, "status: not implemented")
}
func (cs *cacheStore) ListStatuses(ctx context.Context, filters ...string) ([]content.Status, error) {
return nil, rpcerrors.Errorf(codes.Unimplemented, "liststatuses: not implemented")
}
func (cs *cacheStore) Abort(ctx context.Context, ref string) error {
return rpcerrors.Errorf(codes.Unimplemented, "abort: not implemented")
}
func (cs *cacheStore) Writer(ctx context.Context, opts ...content.WriterOpt) (content.Writer, error) {
return nil, rpcerrors.Errorf(codes.Unimplemented, "writer: writes not supported")
}
type storeReader struct {
cache.ReaderAtCloser
size int64
}
func (s storeReader) Size() int64 { return s.size }