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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Look for manifests in the local cache next to the full images. #570

Merged
merged 1 commit into from
Feb 19, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions pkg/cache/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,20 +145,53 @@ func LocalSource(opts *config.KanikoOptions, cacheKey string) (v1.Image, error)
type cachedImage struct {
digest string
v1.Image
mfst *v1.Manifest
}

func (c *cachedImage) Digest() (v1.Hash, error) {
return v1.NewHash(c.digest)
}

func (c *cachedImage) Manifest() (*v1.Manifest, error) {
if c.mfst == nil {
return c.Image.Manifest()
}
return c.mfst, nil
}

func mfstFromPath(p string) (*v1.Manifest, error) {
f, err := os.Open(p)
if err != nil {
return nil, err
}
defer f.Close()
return v1.ParseManifest(f)
}

func cachedImageFromPath(p string) (v1.Image, error) {
imgTar, err := tarball.ImageFromPath(p, nil)
if err != nil {
return nil, errors.Wrap(err, "getting image from path")
}

// Manifests may be present next to the tar, named with a ".json" suffix
mfstPath := p + ".json"

var mfst *v1.Manifest
if _, err := os.Stat(mfstPath); err != nil {
logrus.Debugf("Manifest does not exist at file: %s", mfstPath)
} else {
mfst, err = mfstFromPath(mfstPath)
if err != nil {
logrus.Debugf("Error parsing manifest from file: %s", mfstPath)
} else {
logrus.Infof("Found manifest at %s", mfstPath)
}
}

return &cachedImage{
digest: filepath.Base(p),
Image: imgTar,
mfst: mfst,
}, nil
}
2 changes: 2 additions & 0 deletions pkg/executor/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,8 @@ func (s *stageBuilder) build() error {
return err
}
timing.DefaultRun.Stop(t)
} else {
logrus.Info("Skipping unpacking as no commands require it.")
}
if err := util.DetectFilesystemWhitelist(constants.WhitelistPath); err != nil {
return err
Expand Down
2 changes: 1 addition & 1 deletion pkg/util/image_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func RetrieveSourceImage(stage config.KanikoStage, opts *config.KanikoOptions) (

// Finally, check if local caching is enabled
// If so, look in the local cache before trying the remote registry
if opts.Cache && opts.CacheDir != "" {
if opts.CacheDir != "" {
cachedImage, err := cachedImage(opts, currentBaseName)
if cachedImage != nil {
return cachedImage, nil
Expand Down