From 0037da02308b13659ef65f9424c672feb44711f5 Mon Sep 17 00:00:00 2001 From: Tonis Tiigi Date: Sun, 17 Mar 2019 11:04:45 -0700 Subject: [PATCH] builder-next: fix second cachekey for schema1 Signed-off-by: Tonis Tiigi --- .../adapters/containerimage/pull.go | 21 +++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/builder/builder-next/adapters/containerimage/pull.go b/builder/builder-next/adapters/containerimage/pull.go index d0530c6091..9beeb8d7d0 100644 --- a/builder/builder-next/adapters/containerimage/pull.go +++ b/builder/builder-next/adapters/containerimage/pull.go @@ -321,7 +321,11 @@ func (p *puller) CacheKey(ctx context.Context, index int) (string, bool, error) } if p.config != nil { - return cacheKeyFromConfig(p.config).String(), true, nil + k := cacheKeyFromConfig(p.config).String() + if k == "" { + return digest.FromBytes(p.config).String(), true, nil + } + return k, true, nil } if err := p.resolve(ctx); err != nil { @@ -336,7 +340,16 @@ func (p *puller) CacheKey(ctx context.Context, index int) (string, bool, error) return dgst.String(), false, nil } - return cacheKeyFromConfig(p.config).String(), true, nil + k := cacheKeyFromConfig(p.config).String() + if k == "" { + dgst, err := p.mainManifestKey(p.desc.Digest, p.platform) + if err != nil { + return "", false, err + } + return dgst.String(), true, nil + } + + return k, true, nil } func (p *puller) Snapshot(ctx context.Context) (cache.ImmutableRef, error) { @@ -776,8 +789,8 @@ func cacheKeyFromConfig(dt []byte) digest.Digest { if err != nil { return digest.FromBytes(dt) } - if img.RootFS.Type != "layers" { - return digest.FromBytes(dt) + if img.RootFS.Type != "layers" || len(img.RootFS.DiffIDs) == 0 { + return "" } return identity.ChainID(img.RootFS.DiffIDs) }