summaryrefslogtreecommitdiffstats
path: root/image
diff options
context:
space:
mode:
authorAlex Goodman <wagoodman@gmail.com>2018-10-27 10:11:54 -0400
committerAlex Goodman <wagoodman@gmail.com>2018-10-27 10:11:54 -0400
commite779798478fef08bcaaad64efc6ffe19fa540c78 (patch)
tree14ae8ef497567f8f21420bd71553f0dfdee1f558 /image
parent9078b1dc813ec864aac3b95368a0bb1a7bce108b (diff)
add id + tar name to the layer details
Diffstat (limited to 'image')
-rw-r--r--image/image.go6
-rw-r--r--image/layer.go19
2 files changed, 18 insertions, 7 deletions
diff --git a/image/image.go b/image/image.go
index 35e8af1..3973afc 100644
--- a/image/image.go
+++ b/image/image.go
@@ -303,6 +303,7 @@ func InitializeData(imageID string) ([]*Layer, []*filetree.FileTree, float64, fi
// note that the image config stores images in reverse chronological order, so iterate backwards through layers
// as you iterate chronologically through history (ignoring history items that have no layer contents)
layerIdx := len(trees) - 1
+ tarPathIdx := 0
for idx := 0; idx < len(config.History); idx++ {
// ignore empty layers, we are only observing layers with content
if config.History[idx].EmptyLayer {
@@ -317,12 +318,11 @@ func InitializeData(imageID string) ([]*Layer, []*filetree.FileTree, float64, fi
Index: layerIdx,
Tree: trees[layerIdx],
RefTrees: trees,
+ TarPath: manifest.LayerTarPaths[tarPathIdx],
}
- if len(manifest.LayerTarPaths) > idx {
- layers[layerIdx].TarPath = manifest.LayerTarPaths[layerIdx]
- }
layerIdx--
+ tarPathIdx++
}
fmt.Println(" Analyzing layers...")
diff --git a/image/layer.go b/image/layer.go
index 36a369d..2e8a4d1 100644
--- a/image/layer.go
+++ b/image/layer.go
@@ -20,13 +20,24 @@ type Layer struct {
RefTrees []*filetree.FileTree
}
-// Id returns the truncated id of the current layer.
+// 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
- if length := len(layer.History.ID); length < 25 {
+ id := layer.Id()
+ if length := len(id); length < 25 {
rangeBound = length
}
- id := layer.History.ID[0:rangeBound]
+ id = id[0:rangeBound]
// show the tagged image as the last layer
// if len(layer.History.Tags) > 0 {
@@ -40,7 +51,7 @@ func (layer *Layer) Id() string {
func (layer *Layer) String() string {
return fmt.Sprintf(LayerFormat,
- layer.Id(),
+ layer.ShortId(),
humanize.Bytes(uint64(layer.History.Size)),
strings.TrimPrefix(layer.History.CreatedBy, "/bin/sh -c "))
}