-
Notifications
You must be signed in to change notification settings - Fork 41
/
image.go
142 lines (116 loc) · 3.62 KB
/
image.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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
package imgutil
import (
"fmt"
"io"
"strings"
"time"
v1 "github.com/google/go-containerregistry/pkg/v1"
"github.com/google/go-containerregistry/pkg/v1/types"
)
type Image interface {
WithEditableManifest
WithEditableConfig
WithEditableLayers
// getters
// Found reports if image exists in the image store with `Name()`.
Found() bool
Identifier() (Identifier, error)
// Kind exposes the type of image that backs the imgutil.Image implementation.
// It could be `local`, `remote`, or `layout`.
Kind() string
Name() string
UnderlyingImage() v1.Image
// Valid returns true if the image is well-formed (e.g. all manifest layers exist on the registry).
Valid() bool
// setters
Delete() error
Rename(name string)
// Save saves the image as `Name()` and any additional names provided to this method.
Save(additionalNames ...string) error
// SaveAs ignores the image `Name()` method and saves the image according to name & additional names provided to this method
SaveAs(name string, additionalNames ...string) error
// SaveFile saves the image as a docker archive and provides the filesystem location
SaveFile() (string, error)
}
type WithEditableManifest interface {
// getters
Annotations() (map[string]string, error)
Digest() (v1.Hash, error)
GetAnnotateRefName() (string, error)
ManifestSize() (int64, error)
MediaType() (types.MediaType, error)
// setters
AnnotateRefName(refName string) error
SetAnnotations(map[string]string) error
}
type WithEditableConfig interface {
// getters
Architecture() (string, error)
CreatedAt() (time.Time, error)
Entrypoint() ([]string, error)
Env(key string) (string, error)
History() ([]v1.History, error)
Label(string) (string, error)
Labels() (map[string]string, error)
OS() (string, error)
OSFeatures() ([]string, error)
OSVersion() (string, error)
RemoveLabel(string) error
Variant() (string, error)
WorkingDir() (string, error)
// setters
SetArchitecture(string) error
SetCmd(...string) error
SetEntrypoint(...string) error
SetEnv(string, string) error
SetHistory([]v1.History) error
SetLabel(string, string) error
SetOS(string) error
SetOSFeatures([]string) error
SetOSVersion(string) error
SetVariant(string) error
SetWorkingDir(string) error
}
type WithEditableLayers interface {
// getters
// GetLayer retrieves layer by diff id. Returns a reader of the uncompressed contents of the layer.
GetLayer(diffID string) (io.ReadCloser, error)
// TopLayer returns the diff id for the top layer
TopLayer() (string, error)
// setters
AddLayer(path string) error
AddLayerWithDiffID(path, diffID string) error
AddLayerWithDiffIDAndHistory(path, diffID string, history v1.History) error
AddOrReuseLayerWithHistory(path, diffID string, history v1.History) error
Rebase(string, Image) error
ReuseLayer(diffID string) error
ReuseLayerWithHistory(diffID string, history v1.History) error
}
type Identifier fmt.Stringer
// Platform represents the target arch/os/variant/os_version for an image construction and querying.
type Platform struct {
Architecture string
OS string
Variant string
OSVersion string
}
type SaveDiagnostic struct {
ImageName string
Cause error
}
type SaveError struct {
Errors []SaveDiagnostic
}
func (e SaveError) Error() string {
var errors []string
for _, d := range e.Errors {
errors = append(errors, fmt.Sprintf("[%s: %s]", d.ImageName, d.Cause.Error()))
}
return fmt.Sprintf("failed to write image to the following tags: %s", strings.Join(errors, ","))
}
type ErrLayerNotFound struct {
DiffID string
}
func (e ErrLayerNotFound) Error() string {
return fmt.Sprintf("failed to find layer with diff ID %q", e.DiffID)
}