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 ")) } diff --git a/ui/detailsview.go b/ui/detailsview.go index 51fcd07..3728c59 100644 --- a/ui/detailsview.go +++ b/ui/detailsview.go @@ -123,7 +123,9 @@ func (view *DetailsView) Render() error { // update contents view.view.Clear() - fmt.Fprintln(view.view, Formatting.Header("Layer Command")) + fmt.Fprintln(view.view, Formatting.Header("Digest: ")+currentLayer.Id()) + fmt.Fprintln(view.view, Formatting.Header("Tar ID: ")+currentLayer.TarId()) + fmt.Fprintln(view.view, Formatting.Header("Command:")) fmt.Fprintln(view.view, currentLayer.History.CreatedBy) fmt.Fprintln(view.view, effStr) diff --git a/ui/layerview.go b/ui/layerview.go index 9fd7219..9d13aee 100644 --- a/ui/layerview.go +++ b/ui/layerview.go @@ -193,7 +193,7 @@ func (view *LayerView) Render() error { layerId = fmt.Sprintf("%-25s", layer.History.ID) } - layerStr = fmt.Sprintf(image.LayerFormat, layerId, humanize.Bytes(uint64(layer.History.Size)), "FROM "+layer.Id()) + layerStr = fmt.Sprintf(image.LayerFormat, layerId, humanize.Bytes(uint64(layer.History.Size)), "FROM "+layer.ShortId()) } compareBar := view.renderCompareBar(idx)