Skip to content
This repository was archived by the owner on Mar 27, 2024. It is now read-only.

Compare layers of images #233

Merged
merged 4 commits into from
May 15, 2018
Merged

Conversation

priyawadhwa
Copy link
Contributor

I added a "file-layer" type which unpacks each layer of each image to a different temp dir, and then compares the files within corresponding layers.

If one of the images contains more layers than the other, I compare the file system of the extra layer with an empty directory.

#222

Copy link
Contributor

@nkubala nkubala left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! Looking pretty good overall, a few comments inline.

I'm a little unsure about diffing with an empty directory in the case where an image has more layers than another: this would cause the entire file contents of that layer to be outputted, which can be huge. Maybe instead we warn the user that a layer is present in one image that isn't in another, and have them run analyze if they want to see the contents?

Also, maybe out of the scope of this PR....but it would be really cool if we could do something like
container-diff analyze daemon://my_image:tag --type=layer --layer layer_id and see the contents of an individual layer :)

if err != nil {
return util.FileLayerAnalyzeResult{}, err
}
directoryEntry := pkgutil.GetDirectoryEntries(layerDir)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: combine with line below so you don't create a new local var

directoryEntries = append(pkgutil.GetDirectoryEntries(layerDir), directoryEntry)

if err != nil {
return err
}
return unpackTar(tar.NewReader(contents), root, whitelist)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As part of switching to go-containerregistry, I removed all the whiteout handling in unpackTar (since it gets handled implicitly by mutate.Extract). I don't think it should cause any problems here since a tombstoned file would be treated like any normal file would, but just making a note of that here in case you can think of any cases where it would be an issue.

analysis, valid := r.Analysis.([][]util.DirectoryEntry)
if !valid {
logrus.Error("Unexpected structure of Analysis. Should be of type []DirectoryEntry")
return errors.New("Could not output FileAnalyzer analysis result")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this error will get outputted somewhere further up the stack right? Can you just do an errors.Wrapf here and return that

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, what error do you mean? There isn't a specific error to wrap, which is why I think all the AnalyzeResults are returning new ones.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah sorry, I meant to combine these errors into one and return them without logging anything here. I see that you're just following the pattern from what was already here though, so it's fine for now. We should clean this error handling up later.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool, sounds good

analysis, valid := r.Analysis.([][]util.DirectoryEntry)
if !valid {
logrus.Error("Unexpected structure of Analysis. Should be of type []DirectoryEntry")
return errors.New("Could not output FileAnalyzer analysis result")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment w.r.t. error here

"history": HistoryAnalyzer{},
"metadata": MetadataAnalyzer{},
"file": FileAnalyzer{},
"file-layer": FileLayerAnalyzer{},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this would be a little cleaner as layer instead of file-layer

@priyawadhwa
Copy link
Contributor Author

Yah makes sense, only layers that are present in both images should be diffed now, and I definitely could add diffing specific layers in another PR. I think this is RFAL!

@priyawadhwa priyawadhwa merged commit a4bd726 into GoogleContainerTools:master May 15, 2018
@priyawadhwa priyawadhwa deleted the layers branch May 15, 2018 21:57
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants