forked from buildpacks/imgutil
-
Notifications
You must be signed in to change notification settings - Fork 0
/
image.go
111 lines (96 loc) · 3.27 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
package imgutil
import (
"fmt"
"io"
"strings"
"time"
v1 "github.com/google/go-containerregistry/pkg/v1"
)
type Image interface {
// getters
Architecture() (string, error)
CreatedAt() (time.Time, error)
Entrypoint() ([]string, error)
Env(key string) (string, error)
// Found reports if image exists in the image store with `Name()`.
Found() bool
GetAnnotateRefName() (string, error)
// GetLayer retrieves layer by diff id. Returns a reader of the uncompressed contents of the layer.
GetLayer(diffID string) (io.ReadCloser, error)
History() ([]v1.History, error)
Identifier() (Identifier, error)
// Kind exposes the type of image that backs the imgutil.Image implementation.
// It could be `local`, `remote`, or `layout`.
Kind() string
Label(string) (string, error)
Labels() (map[string]string, error)
// ManifestSize returns the size of the manifest. If a manifest doesn't exist, it returns 0.
ManifestSize() (int64, error)
Name() string
OS() (string, error)
OSVersion() (string, error)
// TopLayer returns the diff id for the top layer
TopLayer() (string, error)
UnderlyingImage() v1.Image
// Valid returns true if the image is well-formed (e.g. all manifest layers exist on the registry).
Valid() bool
Variant() (string, error)
WorkingDir() (string, error)
// setters
// AnnotateRefName set a value for the `org.opencontainers.image.ref.name` annotation
AnnotateRefName(refName string) error
Rename(name string)
SetArchitecture(string) error
SetCmd(...string) error
SetEntrypoint(...string) error
SetEnv(string, string) error
SetHistory([]v1.History) error
SetLabel(string, string) error
SetOS(string) error
SetOSVersion(string) error
SetVariant(string) error
SetWorkingDir(string) error
// modifiers
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
Delete() error
Rebase(string, Image) error
RemoveLabel(string) error
ReuseLayer(diffID string) error
ReuseLayerWithHistory(diffID string, history v1.History) error
// 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 Identifier fmt.Stringer
// Platform represents the target arch/os/os_version for an image construction and querying.
type Platform struct {
Architecture string
OS 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)
}