image tar can be a symlink (fixes #26)

This commit is contained in:
Alex Goodman 2018-10-21 12:02:51 -04:00
parent d6549ea16d
commit ee74c8500e
No known key found for this signature in database
GPG Key ID: 05328C611D8A520E
2 changed files with 13 additions and 14 deletions

View File

@ -20,7 +20,6 @@ dive build -t <some-tag> .
**Show Docker image contents broken down by layer**
As you select a layer on the left, you are shown the contents of that layer combined with all previous layers on the right.
Also, you can fully explore the file tree with the arrow keys.
**Indicate what's change in each layer**

View File

@ -14,9 +14,9 @@ import (
"github.com/docker/docker/client"
"github.com/wagoodman/dive/filetree"
"github.com/wagoodman/dive/utils"
"github.com/wagoodman/jotframe"
"golang.org/x/net/context"
"github.com/wagoodman/dive/utils"
)
// TODO: this file should be rethought... but since it's only for preprocessing it'll be tech debt for now.
@ -201,7 +201,7 @@ func InitializeData(imageID string) ([]*Layer, []*filetree.FileTree) {
ctx := context.Background()
dockerClient, err := client.NewClientWithOpts()
if err != nil {
fmt.Println("Could not connect to the Docker daemon:"+err.Error())
fmt.Println("Could not connect to the Docker daemon:" + err.Error())
os.Exit(1)
}
_, _, err = dockerClient.ImageInspectWithRaw(ctx, imageID)
@ -211,8 +211,11 @@ func InitializeData(imageID string) ([]*Layer, []*filetree.FileTree) {
}
// save this image to disk temporarily to get the content info
imageTarPath, tmpDir := saveImage(imageID)
defer os.RemoveAll(tmpDir)
// imageTarPath, tmpDir := saveImage(imageID)
// fmt.Println(imageTarPath)
// fmt.Println(tmpDir)
imageTarPath := "/tmp/dive446223287/image.tar"
// defer os.RemoveAll(tmpDir)
// read through the image contents and build a tree
tarFile, err := os.Open(imageTarPath)
@ -255,10 +258,9 @@ func InitializeData(imageID string) ([]*Layer, []*filetree.FileTree) {
name := header.Name
switch header.Typeflag {
case tar.TypeDir:
continue
case tar.TypeReg:
// some layer tars can be relative layer symlinks to other layer tars
if header.Typeflag == tar.TypeSymlink || header.Typeflag == tar.TypeReg {
if strings.HasSuffix(name, "layer.tar") {
line, err := frame.Prepend()
if err != nil {
@ -275,12 +277,9 @@ func InitializeData(imageID string) ([]*Layer, []*filetree.FileTree) {
}
go processLayerTar(line, layerMap, name, tarredBytes)
} else if name == "manifest.json" {
manifest = NewImageManifest(tarReader, header)
}
default:
fmt.Printf("ERRG: unknown tar entry: %v: %s\n", header.Typeflag, name)
}
}
frame.Header().Close()
@ -309,7 +308,8 @@ func InitializeData(imageID string) ([]*Layer, []*filetree.FileTree) {
continue
}
config.History[idx].Size = uint64(trees[(len(trees)-1)-layerIdx].FileSize)
tree := trees[(len(trees)-1)-layerIdx]
config.History[idx].Size = uint64(tree.FileSize)
layers[layerIdx] = &Layer{
History: config.History[idx],
@ -331,7 +331,7 @@ func saveImage(imageID string) (string, string) {
ctx := context.Background()
dockerClient, err := client.NewClientWithOpts()
if err != nil {
fmt.Println("Could not connect to the Docker daemon:"+err.Error())
fmt.Println("Could not connect to the Docker daemon:" + err.Error())
os.Exit(1)
}