@@ -7,6 +7,7 @@ package registry
7
7
import (
8
8
"context"
9
9
"io"
10
+ "sync"
10
11
"time"
11
12
12
13
"github.com/gitpod-io/gitpod/common-go/log"
@@ -18,30 +19,42 @@ import (
18
19
ociv1 "github.com/opencontainers/image-spec/specs-go/v1"
19
20
)
20
21
22
+ // ipfsManifestModifier modifies a manifest and adds IPFS URLs to the layers
21
23
func (reg * Registry ) ipfsManifestModifier (mf * ociv1.Manifest ) error {
22
24
if reg .IPFS == nil {
23
25
return nil
24
26
}
25
27
26
28
ctx , cancel := context .WithTimeout (context .Background (), 10 * time .Second )
27
29
defer cancel ()
30
+
31
+ var wg sync.WaitGroup
28
32
for i , l := range mf .Layers {
29
- url , _ := reg .IPFS .Get (ctx , l .Digest )
30
- if url == "" {
31
- continue
32
- }
33
- mf .Layers [i ].URLs = append (mf .Layers [i ].URLs , url )
33
+ wg .Add (1 )
34
+ go func (i int , dgst digest.Digest ) {
35
+ defer wg .Done ()
36
+
37
+ url , _ := reg .IPFS .Get (ctx , dgst )
38
+ if url == "" {
39
+ return
40
+ }
41
+ mf .Layers [i ].URLs = append (mf .Layers [i ].URLs , url )
42
+ }(i , l .Digest )
34
43
}
44
+ wg .Wait ()
35
45
36
46
return nil
37
47
}
38
48
39
- type IPFSStore struct {
49
+ // IPFSBlobCache can cache blobs in IPFS
50
+ type IPFSBlobCache struct {
40
51
Redis * redis.Client
41
52
IPFS ipfs.CoreAPI
42
53
}
43
54
44
- func (store * IPFSStore ) Get (ctx context.Context , dgst digest.Digest ) (ipfsURL string , err error ) {
55
+ // Get retrieves the IPFS URL for a previously stored blob.
56
+ // Returns an error if the blob is not stored in IPFS yet.
57
+ func (store * IPFSBlobCache ) Get (ctx context.Context , dgst digest.Digest ) (ipfsURL string , err error ) {
45
58
if store == nil || store .IPFS == nil || store .Redis == nil {
46
59
return "" , nil
47
60
}
@@ -54,20 +67,8 @@ func (store *IPFSStore) Get(ctx context.Context, dgst digest.Digest) (ipfsURL st
54
67
return "ipfs://" + res , nil
55
68
}
56
69
57
- func (store * IPFSStore ) Has (ctx context.Context , dgst digest.Digest ) (ok bool , err error ) {
58
- if store == nil || store .IPFS == nil || store .Redis == nil {
59
- return false , nil
60
- }
61
-
62
- res := store .Redis .Exists (ctx , dgst .String ())
63
- if err := res .Err (); err != nil {
64
- return false , err
65
- }
66
-
67
- return res .Val () == 1 , nil
68
- }
69
-
70
- func (store * IPFSStore ) Store (ctx context.Context , dgst digest.Digest , content io.Reader ) (err error ) {
70
+ // Store stores a blob in IPFS. Will happily overwrite/re-upload a blob.
71
+ func (store * IPFSBlobCache ) Store (ctx context.Context , dgst digest.Digest , content io.Reader ) (err error ) {
71
72
if store == nil || store .IPFS == nil || store .Redis == nil {
72
73
return nil
73
74
}
0 commit comments