From ec6b2277b88aed2fea9b6d49909e54b6369fc71a Mon Sep 17 00:00:00 2001 From: Alejandro Visiedo Date: Sat, 31 Oct 2020 21:27:55 +0100 Subject: [PATCH] docker-archive: Add support for kaniko --- dive/image/docker/image_archive.go | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/dive/image/docker/image_archive.go b/dive/image/docker/image_archive.go index 7e911729..065863c0 100644 --- a/dive/image/docker/image_archive.go +++ b/dive/image/docker/image_archive.go @@ -2,14 +2,16 @@ package docker import ( "archive/tar" + "compress/gzip" "fmt" - "github.com/wagoodman/dive/dive/filetree" - "github.com/wagoodman/dive/dive/image" "io" "io/ioutil" "os" "path" "strings" + + "github.com/wagoodman/dive/dive/filetree" + "github.com/wagoodman/dive/dive/image" ) type ImageArchive struct { @@ -48,12 +50,29 @@ func NewImageArchive(tarFile io.ReadCloser) (*ImageArchive, error) { if strings.HasSuffix(name, ".tar") { currentLayer++ + layerReader := tar.NewReader(tarReader) + tree, err := processLayerTar(name, layerReader) + if err != nil { + return img, err + } + + // add the layer to the image + img.layerMap[tree.Name] = tree + + } else if strings.HasSuffix(name, ".tar.gz") || strings.HasSuffix(name, "tgz") { + currentLayer++ + + // Add gzip reader + gz, err := gzip.NewReader(tarReader) if err != nil { return img, err } - layerReader := tar.NewReader(tarReader) - tree, err := processLayerTar(name, layerReader) + // Add tar reader + layerReader := tar.NewReader(gz) + + // Process layer + tree, err := processLayerTar(name, layerReader) if err != nil { return img, err } @@ -61,7 +80,7 @@ func NewImageArchive(tarFile io.ReadCloser) (*ImageArchive, error) { // add the layer to the image img.layerMap[tree.Name] = tree - } else if strings.HasSuffix(name, ".json") { + } else if strings.HasSuffix(name, ".json") || strings.HasPrefix(name, "sha256:") { fileBuffer, err := ioutil.ReadAll(tarReader) if err != nil { return img, err