Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(daemon): lazy image saving #1121

Merged
merged 4 commits into from
Sep 19, 2021
Merged

feat(daemon): lazy image saving #1121

merged 4 commits into from
Sep 19, 2021

Conversation

knqyf263
Copy link
Contributor

@knqyf263 knqyf263 commented Sep 8, 2021

Fix #627

A faster way of getting an image ID is really useful for caching. We don't want to call docker save if we already have the image information in the cache. For example, in our case, we should skip scanning vulnerabilities of the image when the scan result exists in the cache. The cache key is an image ID, so it is enough to call docker inspect to know only the image ID.

This implementation is based on computed() as below.

func (i *image) compute() error {

The downside is that daemon.Image doesn't return an error and it might return an error when each method is called (knqyf263@881e16e).

I probably should add tests, but I'd like to hear your thought on this idea before working on tests 馃檱

I also want to replace ConfigFile with this approach in another PR because I think we can generate the config file from the result of docker inspect and docker history.

@codecov-commenter
Copy link

codecov-commenter commented Sep 8, 2021

Codecov Report

Merging #1121 (abae8c9) into main (c5dea0c) will decrease coverage by 0.10%.
The diff coverage is 65.21%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #1121      +/-   ##
==========================================
- Coverage   75.16%   75.06%   -0.11%     
==========================================
  Files         108      108              
  Lines        7724     7800      +76     
==========================================
+ Hits         5806     5855      +49     
- Misses       1363     1380      +17     
- Partials      555      565      +10     
Impacted Files Coverage 螖
pkg/v1/daemon/options.go 94.28% <酶> (酶)
pkg/v1/daemon/image.go 76.00% <65.21%> (-24.00%) 猬囷笍
pkg/legacy/tarball/write.go 67.18% <0.00%> (-1.16%) 猬囷笍
pkg/v1/remote/transport/error.go 100.00% <0.00%> (酶)
pkg/v1/mutate/image.go 69.72% <0.00%> (+0.49%) 猬嗭笍
pkg/v1/mutate/mutate.go 71.94% <0.00%> (+0.51%) 猬嗭笍

Continue to review full report at Codecov.

Legend - Click here to learn more
螖 = absolute <relative> (impact), 酶 = not affected, ? = missing data
Powered by Codecov. Last update c5dea0c...abae8c9. Read the comment docs.

@knqyf263 knqyf263 changed the title feat(daemon): tarball lazy loading feat(daemon): lazy image saving Sep 8, 2021
if err := i.initialize(); err != nil {
return nil, err
}
return i.tarballImage.LayerByDigest(h)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should be LayerByDiffID

Copy link
Contributor Author

@knqyf263 knqyf263 Sep 19, 2021

Choose a reason for hiding this comment

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

Thanks. Fixed bb5ea5e

@jonjohnsonjr
Copy link
Collaborator

LGTM in general other than the one bug. I would like to see a test (you should be able to catch most issues by calling validate.Image) 馃憤

@knqyf263
Copy link
Contributor Author

@jonjohnsonjr Thanks for the review! I fixed the bug and added validate.Image. Could you take a look again?

@jonjohnsonjr
Copy link
Collaborator

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

getting image ID (sha) takes longer than docker cli
3 participants