-
Notifications
You must be signed in to change notification settings - Fork 27
/
pull.go
36 lines (30 loc) · 883 Bytes
/
pull.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
package registry
import (
"context"
"encoding/json"
"fmt"
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
)
// PullBytes a resource from the registry.
func PullBytes(ctx context.Context, sc StorageClient, artifact Artifact) (data []byte, err error) {
srcStorage, err := sc.GetStorage(ctx, artifact)
if err != nil {
return nil, fmt.Errorf("repository source: %v", err)
}
_, data, err = sc.FetchBytes(ctx, srcStorage, artifact)
if err != nil {
return nil, fmt.Errorf("fetch manifest: %v", err)
}
var mani ocispec.Manifest
if err := json.Unmarshal(data, &mani); err != nil {
return nil, fmt.Errorf("unmarshal manifest: %v", err)
}
if len(mani.Layers) < 1 {
return nil, fmt.Errorf("missing layer")
}
data, err = sc.FetchBlob(ctx, srcStorage, mani.Layers[0])
if err != nil {
return nil, fmt.Errorf("fetch blob: %v", err)
}
return data, err
}