...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 package crane
16
17 import (
18 "fmt"
19
20 "github.com/google/go-containerregistry/pkg/name"
21 v1 "github.com/google/go-containerregistry/pkg/v1"
22 "github.com/google/go-containerregistry/pkg/v1/remote"
23 "github.com/google/go-containerregistry/pkg/v1/tarball"
24 )
25
26
27 func Load(path string, opt ...Option) (v1.Image, error) {
28 return LoadTag(path, "", opt...)
29 }
30
31
32
33 func LoadTag(path, tag string, opt ...Option) (v1.Image, error) {
34 if tag == "" {
35 return tarball.ImageFromPath(path, nil)
36 }
37
38 o := makeOptions(opt...)
39 t, err := name.NewTag(tag, o.Name...)
40 if err != nil {
41 return nil, fmt.Errorf("parsing tag %q: %w", tag, err)
42 }
43 return tarball.ImageFromPath(path, &t)
44 }
45
46
47 func Push(img v1.Image, dst string, opt ...Option) error {
48 o := makeOptions(opt...)
49 tag, err := name.ParseReference(dst, o.Name...)
50 if err != nil {
51 return fmt.Errorf("parsing reference %q: %w", dst, err)
52 }
53 return remote.Write(tag, img, o.Remote...)
54 }
55
56
57 func Upload(layer v1.Layer, repo string, opt ...Option) error {
58 o := makeOptions(opt...)
59 ref, err := name.NewRepository(repo, o.Name...)
60 if err != nil {
61 return fmt.Errorf("parsing repo %q: %w", repo, err)
62 }
63
64 return remote.WriteLayer(ref, layer, o.Remote...)
65 }
66
View as plain text