forked from wagoodman/dive
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlayer.go
57 lines (47 loc) · 1.23 KB
/
layer.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
package image
import (
"fmt"
"github.com/dustin/go-humanize"
"github.com/wagoodman/dive/filetree"
"strings"
)
const (
LayerFormat = "%-25s %7s %s"
)
// Layer represents a Docker image layer and metadata
type Layer struct {
TarPath string
History ImageHistoryEntry
Index int
Tree *filetree.FileTree
RefTrees []*filetree.FileTree
}
// ShortId returns the truncated id of the current layer.
func (layer *Layer) TarId() string {
return strings.TrimSuffix(layer.TarPath, "/layer.tar")
}
// ShortId returns the truncated id of the current layer.
func (layer *Layer) Id() string {
return layer.History.ID
}
// ShortId returns the truncated id of the current layer.
func (layer *Layer) ShortId() string {
rangeBound := 25
id := layer.Id()
if length := len(id); length < 25 {
rangeBound = length
}
id = id[0:rangeBound]
// show the tagged image as the last layer
// if len(layer.History.Tags) > 0 {
// id = "[" + strings.Join(layer.History.Tags, ",") + "]"
// }
return id
}
// String represents a layer in a columnar format.
func (layer *Layer) String() string {
return fmt.Sprintf(LayerFormat,
layer.ShortId(),
humanize.Bytes(uint64(layer.History.Size)),
strings.TrimPrefix(layer.History.CreatedBy, "/bin/sh -c "))
}