imagemetaresolver: use platform in cache

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
docker-18.09
Tonis Tiigi 2018-07-17 16:02:15 -07:00
parent 628681f8e4
commit c9df92f4c5
1 changed files with 15 additions and 5 deletions

View File

@ -5,6 +5,7 @@ import (
"net/http"
"sync"
"github.com/containerd/containerd/platforms"
"github.com/containerd/containerd/remotes"
"github.com/containerd/containerd/remotes/docker"
"github.com/docker/docker/pkg/locker"
@ -74,19 +75,28 @@ func (imr *imageMetaResolver) ResolveImageConfig(ctx context.Context, ref string
imr.locker.Lock(ref)
defer imr.locker.Unlock(ref)
if res, ok := imr.cache[ref]; ok {
return res.dgst, res.config, nil
}
if platform == nil {
platform = imr.platform
}
k := imr.key(ref, platform)
if res, ok := imr.cache[k]; ok {
return res.dgst, res.config, nil
}
dgst, config, err := imageutil.Config(ctx, ref, imr.resolver, imr.buffer, platform)
if err != nil {
return "", nil, err
}
imr.cache[ref] = resolveResult{dgst: dgst, config: config}
imr.cache[k] = resolveResult{dgst: dgst, config: config}
return dgst, config, nil
}
func (imr *imageMetaResolver) key(ref string, platform *specs.Platform) string {
if platform != nil {
ref += platforms.Format(*platform)
}
return ref
}