diff --git a/cmd/root.go b/cmd/root.go index 6df6d16d..212301e1 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -132,35 +132,40 @@ func getPrepperForImage(image string) (pkgutil.Prepper, error) { Source: image, Client: cli, }, nil - } - ref, err := docker.ParseReference("//" + image) - if err != nil { - return nil, err - } - src, err := ref.NewImageSource(nil) - if err != nil { - return nil, err + // see if the image name has tag provided, if not add latest as tag + if !strings.Contains(image, ":") { + image = image + ":latest" } if strings.HasPrefix(image, DaemonPrefix) { - // remove the DaemonPrefix image := strings.Replace(image, DaemonPrefix, "", -1) - // see if the image name has tag provided, if not add latest as tag if !strings.Contains(image, ":") { image = image + ":latest" } return pkgutil.DaemonPrepper{ - Source: image, - Client: cli, - ImageSource: src, + Source: image, + Client: cli, }, nil } // either has remote prefix or has no prefix, in which case we force remote + // see if the image name has tag provided, if not add latest as tag + if !strings.Contains(image, ":") { + image = image + ":latest" + } + ref, err := docker.ParseReference("//" + image) + if err != nil { + return nil, err + } + src, err := ref.NewImageSource(nil) + if err != nil { + return nil, err + } + if !noCache { cacheDir, err := cacheDir() if err != nil { diff --git a/pkg/util/daemon_prepper.go b/pkg/util/daemon_prepper.go index fb6c2c38..9a685767 100644 --- a/pkg/util/daemon_prepper.go +++ b/pkg/util/daemon_prepper.go @@ -22,16 +22,14 @@ import ( "strings" "github.com/containers/image/docker/daemon" - "github.com/containers/image/types" "github.com/docker/docker/client" "github.com/sirupsen/logrus" ) type DaemonPrepper struct { - Source string - Client *client.Client - ImageSource types.ImageSource + Source string + Client *client.Client } func (p DaemonPrepper) Name() string { @@ -54,6 +52,11 @@ func (p DaemonPrepper) GetFileSystem() (string, error) { return "", err } + src, err := ref.NewImageSource(nil) + if err != nil { + return "", err + } + sanitizedName := strings.Replace(p.Source, ":", "", -1) sanitizedName = strings.Replace(sanitizedName, "/", "", -1) @@ -61,7 +64,7 @@ func (p DaemonPrepper) GetFileSystem() (string, error) { if err != nil { return "", err } - return path, getFileSystemFromReference(ref, p.ImageSource, path) + return path, getFileSystemFromReference(ref, src, path) } func (p DaemonPrepper) GetConfig() (ConfigSchema, error) { diff --git a/tests/apt_analysis_expected.json b/tests/apt_analysis_expected.json index 1e71789f..88e5a49b 100644 --- a/tests/apt_analysis_expected.json +++ b/tests/apt_analysis_expected.json @@ -1,6 +1,6 @@ [ { - "Image": "gcr.io/gcp-runtimes/apt-modified", + "Image": "gcr.io/gcp-runtimes/apt-modified:latest", "AnalyzeType": "Apt", "Analysis": [ { diff --git a/tests/apt_diff_expected.json b/tests/apt_diff_expected.json index 489bb366..b5cbd80f 100644 --- a/tests/apt_diff_expected.json +++ b/tests/apt_diff_expected.json @@ -1,7 +1,7 @@ [ { - "Image1": "gcr.io/gcp-runtimes/apt-base", - "Image2": "gcr.io/gcp-runtimes/apt-modified", + "Image1": "gcr.io/gcp-runtimes/apt-base:latest", + "Image2": "gcr.io/gcp-runtimes/apt-modified:latest", "DiffType": "Apt", "Diff": { "Packages1": [ diff --git a/tests/apt_sorted_diff_expected.json b/tests/apt_sorted_diff_expected.json index 21eeed7a..9b6b2490 100644 --- a/tests/apt_sorted_diff_expected.json +++ b/tests/apt_sorted_diff_expected.json @@ -1,7 +1,7 @@ [ { - "Image1": "gcr.io/gcp-runtimes/apt-base", - "Image2": "gcr.io/gcp-runtimes/apt-modified", + "Image1": "gcr.io/gcp-runtimes/apt-base:latest", + "Image2": "gcr.io/gcp-runtimes/apt-modified:latest", "DiffType": "Apt", "Diff": { "Packages1": [ diff --git a/tests/file_diff_expected.json b/tests/file_diff_expected.json index c058376b..e23c0d6f 100644 --- a/tests/file_diff_expected.json +++ b/tests/file_diff_expected.json @@ -1,7 +1,7 @@ [ { - "Image1": "gcr.io/gcp-runtimes/diff-base", - "Image2": "gcr.io/gcp-runtimes/diff-modified", + "Image1": "gcr.io/gcp-runtimes/diff-base:latest", + "Image2": "gcr.io/gcp-runtimes/diff-modified:latest", "DiffType": "File", "Diff": { "Adds": null, diff --git a/tests/file_sorted_analysis_expected.json b/tests/file_sorted_analysis_expected.json index ac69d7e0..c8d78118 100644 --- a/tests/file_sorted_analysis_expected.json +++ b/tests/file_sorted_analysis_expected.json @@ -1,6 +1,6 @@ [ { - "Image": "gcr.io/gcp-runtimes/diff-modified", + "Image": "gcr.io/gcp-runtimes/diff-modified:latest", "AnalyzeType": "File", "Analysis": [ { diff --git a/tests/hist_diff_expected.json b/tests/hist_diff_expected.json index e46ee7fc..5d9451c3 100644 --- a/tests/hist_diff_expected.json +++ b/tests/hist_diff_expected.json @@ -1,7 +1,7 @@ [ { - "Image1": "gcr.io/gcp-runtimes/diff-base", - "Image2": "gcr.io/gcp-runtimes/diff-modified", + "Image1": "gcr.io/gcp-runtimes/diff-base:latest", + "Image2": "gcr.io/gcp-runtimes/diff-modified:latest", "DiffType": "History", "Diff": { "Adds": [ diff --git a/tests/integration_test.go b/tests/integration_test.go index e0b19367..e3c2d961 100644 --- a/tests/integration_test.go +++ b/tests/integration_test.go @@ -22,6 +22,7 @@ import ( "bytes" "context" "fmt" + "io" "io/ioutil" "os" "os/exec" @@ -135,14 +136,14 @@ func TestDiffAndAnalysis(t *testing.T) { differFlags: []string{"--type=node", "--type=pip", "--type=apt"}, expectedFile: "multi_diff_expected.json", }, - // { - // description: "multi differ local", - // subcommand: "diff", - // imageA: multiBaseLocal, - // imageB: multiModifiedLocal, - // differFlags: []string{"--type=node", "--type=pip", "--type=apt"}, - // expectedFile: "multi_diff_expected.json", - // }, + { + description: "multi differ local", + subcommand: "diff", + imageA: multiBaseLocal, + imageB: multiModifiedLocal, + differFlags: []string{"--type=node", "--type=pip", "--type=apt"}, + expectedFile: "multi_diff_expected.json", + }, { description: "history differ", subcommand: "diff", @@ -232,12 +233,15 @@ func TestMain(m *testing.M) { fmt.Printf("Error retrieving docker client: %s", err) os.Exit(1) } - closer.Close() + io.Copy(os.Stdout, closer) + closer, err = cli.ImagePull(ctx, multiModified, types.ImagePullOptions{}) if err != nil { fmt.Printf("Error retrieving docker client: %s", err) os.Exit(1) } + io.Copy(os.Stdout, closer) + closer.Close() os.Exit(m.Run()) } diff --git a/tests/multi_diff_expected.json b/tests/multi_diff_expected.json index c9b33909..2a532a06 100644 --- a/tests/multi_diff_expected.json +++ b/tests/multi_diff_expected.json @@ -1,7 +1,7 @@ [ { - "Image1": "gcr.io/gcp-runtimes/multi-base", - "Image2": "gcr.io/gcp-runtimes/multi-modified", + "Image1": "gcr.io/gcp-runtimes/multi-base:latest", + "Image2": "gcr.io/gcp-runtimes/multi-modified:latest", "DiffType": "Apt", "Diff": { "Packages1": [], @@ -56,8 +56,8 @@ } }, { - "Image1": "gcr.io/gcp-runtimes/multi-base", - "Image2": "gcr.io/gcp-runtimes/multi-modified", + "Image1": "gcr.io/gcp-runtimes/multi-base:latest", + "Image2": "gcr.io/gcp-runtimes/multi-modified:latest", "DiffType": "Node", "Diff": { "Packages1": [], @@ -89,8 +89,8 @@ } }, { - "Image1": "gcr.io/gcp-runtimes/multi-base", - "Image2": "gcr.io/gcp-runtimes/multi-modified", + "Image1": "gcr.io/gcp-runtimes/multi-base:latest", + "Image2": "gcr.io/gcp-runtimes/multi-modified:latest", "DiffType": "Pip", "Diff": { "Packages1": [ diff --git a/tests/node_analysis_expected.json b/tests/node_analysis_expected.json index 70d94ef0..e5e88349 100644 --- a/tests/node_analysis_expected.json +++ b/tests/node_analysis_expected.json @@ -1,6 +1,6 @@ [ { - "Image": "gcr.io/gcp-runtimes/node-modified", + "Image": "gcr.io/gcp-runtimes/node-modified:latest", "AnalyzeType": "Node", "Analysis": [ { diff --git a/tests/node_diff_order_expected.json b/tests/node_diff_order_expected.json index e8a08836..f867d262 100644 --- a/tests/node_diff_order_expected.json +++ b/tests/node_diff_order_expected.json @@ -1,7 +1,7 @@ [ { "Image1": "gcr.io/gcp-runtimes/node-modified:2.0", - "Image2": "gcr.io/gcp-runtimes/node-modified", + "Image2": "gcr.io/gcp-runtimes/node-modified:latest", "DiffType": "Node", "Diff": { "Packages1": [], diff --git a/tests/pip_analysis_expected.json b/tests/pip_analysis_expected.json index 55bb3a5b..cd17ed1a 100644 --- a/tests/pip_analysis_expected.json +++ b/tests/pip_analysis_expected.json @@ -1,6 +1,6 @@ [ { - "Image": "gcr.io/gcp-runtimes/pip-modified", + "Image": "gcr.io/gcp-runtimes/pip-modified:latest", "AnalyzeType": "Pip", "Analysis": [ { diff --git a/tests/rpm_analysis_expected.json b/tests/rpm_analysis_expected.json index c18217fa..bf40f7ed 100644 --- a/tests/rpm_analysis_expected.json +++ b/tests/rpm_analysis_expected.json @@ -1,6 +1,6 @@ [ { - "Image": "valentinrothberg/containerdiff:diff-modified", + "Image": "valentinrothberg/containerdiff:diff-modified:latest", "AnalyzeType": "RPM", "Analysis": [ {