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

Add filesystem caching #232

Merged
merged 1 commit into from
Jun 12, 2018
Merged

Conversation

nkubala
Copy link
Contributor

@nkubala nkubala commented May 14, 2018

This adds naive caching of the extracted filesystem tarball. On successive runs, the tarball on disk will be used for all runs of container-diff. The --no-cache flag can be passed to force a reextraction of the filesystem, and the --save flag can be used to persist that tarball on disk.

Fixes #230

return "", err
}
rootDir := filepath.Join(dir, ".container-diff", "cache")
imageName = strings.Replace(imageName, string(os.PathSeparator), "", -1)
Copy link
Contributor

Choose a reason for hiding this comment

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

We should probably only cache on digests, not tags. If there's a tag, let's resolve it to a digest then cache.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In general I agree, but what about images that were just built locally and don't have digests? I could just do a docker build -t "foo:bar" . and that image won't have a digest.

Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm, we need some way to cache at a content-addressable level, otherwise you risk stale images for things like "latest". What happens if you call Digest() on an image from the daemon? It should work.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The latest changes from go-containerregistry fix this (it used to take on the order of 7 minutes to call Digest()), so we're good here.

@nkubala nkubala force-pushed the cache branch 2 times, most recently from cc3dca6 to 158af30 Compare May 17, 2018 22:06
cmd/root.go Outdated
imgLayers, err := img.Layers()
if err != nil {
return pkgutil.Image{}, err
}
for _, layer := range imgLayers {
path, err := ioutil.TempDir("", strings.Replace(imageName, "/", "", -1))
layerStart := time.Now()
diffID, err := layer.DiffID()
Copy link
Contributor

Choose a reason for hiding this comment

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

I would think we would want to use the Digest, not the DiffID here. Could you explain in a comment why we're using one vs. the other?

My thinking is that caching is most important from a registry, where the layers are compressed. The digest will be faster in that case.

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, I was experimenting with some things across machines and absentmindedly pushed to this branch. google/go-containerregistry#150 is why I was originally apprehensive to using Digest, I was just trying to get something unique to create the cache directory, but I'll be changing this back to Digest

Copy link
Contributor

Choose a reason for hiding this comment

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

Cool, I think this is good to go once you switch it back.

cmd/root.go Outdated
elapsed := time.Now().Sub(start)
logrus.Infof("retrieving image from daemon took %f seconds", elapsed.Seconds())
// TODO(nkubala): remove this when we can set compression level in containerregistry
noCache = true // force noCache if image is in daemon
Copy link
Contributor

Choose a reason for hiding this comment

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

How does this work if one image is in the registry and one isn't?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ah yeah, good point. changed to use a different variable

cmd/root.go Outdated
@@ -208,6 +231,48 @@ func getImageForName(imageName string) (pkgutil.Image, error) {
}, nil
}

func getExtractPathForImage(imageName string, image v1.Image) (string, error) {
if isDaemon {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we check if something is from the daemon here, instead of at the package level? I'm still confused about how this would work with two images, one from a daemon and one from a registry.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Picking up the latest changes to go-containerregistry eliminates the need for this, removed.

@nkubala nkubala force-pushed the cache branch 2 times, most recently from 3b353f8 to 4a14a48 Compare June 11, 2018 20:03
dlorenc
dlorenc previously approved these changes Jun 12, 2018
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