1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

LCOW: Fix ImageCache to address right store

Signed-off-by: John Howard <jhoward@microsoft.com>
This commit is contained in:
John Howard 2017-05-31 09:28:56 -07:00
parent 87abf34a3d
commit ba40132366
6 changed files with 13 additions and 17 deletions

View file

@ -78,7 +78,7 @@ type Result struct {
// ImageCacheBuilder represents a generator for stateful image cache. // ImageCacheBuilder represents a generator for stateful image cache.
type ImageCacheBuilder interface { type ImageCacheBuilder interface {
// MakeImageCache creates a stateful image cache. // MakeImageCache creates a stateful image cache.
MakeImageCache(cacheFrom []string) ImageCache MakeImageCache(cacheFrom []string, platform string) ImageCache
} }
// ImageCache abstracts an image cache. // ImageCache abstracts an image cache.

View file

@ -166,7 +166,7 @@ func newBuilder(clientCtx context.Context, options builderOptions) *Builder {
buildStages: newBuildStages(), buildStages: newBuildStages(),
imageSources: newImageSources(clientCtx, options), imageSources: newImageSources(clientCtx, options),
pathCache: options.PathCache, pathCache: options.PathCache,
imageProber: newImageProber(options.Backend, config.CacheFrom, config.NoCache), imageProber: newImageProber(options.Backend, config.CacheFrom, options.Platform, config.NoCache),
containerManager: newContainerManager(options.Backend), containerManager: newContainerManager(options.Backend),
platform: options.Platform, platform: options.Platform,
} }

View file

@ -63,7 +63,7 @@ func newBuilderWithMockBackend() *Builder {
Backend: mockBackend, Backend: mockBackend,
}), }),
buildStages: newBuildStages(), buildStages: newBuildStages(),
imageProber: newImageProber(mockBackend, nil, false), imageProber: newImageProber(mockBackend, nil, runtime.GOOS, false),
containerManager: newContainerManager(mockBackend), containerManager: newContainerManager(mockBackend),
} }
return b return b
@ -488,10 +488,10 @@ func TestRunWithBuildArgs(t *testing.T) {
} }
mockBackend := b.docker.(*MockBackend) mockBackend := b.docker.(*MockBackend)
mockBackend.makeImageCacheFunc = func(_ []string) builder.ImageCache { mockBackend.makeImageCacheFunc = func(_ []string, _ string) builder.ImageCache {
return imageCache return imageCache
} }
b.imageProber = newImageProber(mockBackend, nil, false) b.imageProber = newImageProber(mockBackend, nil, runtime.GOOS, false)
mockBackend.getImageFunc = func(_ string) (builder.Image, builder.ReleaseableLayer, error) { mockBackend.getImageFunc = func(_ string) (builder.Image, builder.ReleaseableLayer, error) {
return &mockImage{ return &mockImage{
id: "abcdef", id: "abcdef",

View file

@ -19,13 +19,13 @@ type imageProber struct {
cacheBusted bool cacheBusted bool
} }
func newImageProber(cacheBuilder builder.ImageCacheBuilder, cacheFrom []string, noCache bool) ImageProber { func newImageProber(cacheBuilder builder.ImageCacheBuilder, cacheFrom []string, platform string, noCache bool) ImageProber {
if noCache { if noCache {
return &nopProber{} return &nopProber{}
} }
reset := func() builder.ImageCache { reset := func() builder.ImageCache {
return cacheBuilder.MakeImageCache(cacheFrom) return cacheBuilder.MakeImageCache(cacheFrom, platform)
} }
return &imageProber{cache: reset(), reset: reset} return &imageProber{cache: reset(), reset: reset}
} }

View file

@ -18,7 +18,7 @@ type MockBackend struct {
containerCreateFunc func(config types.ContainerCreateConfig) (container.ContainerCreateCreatedBody, error) containerCreateFunc func(config types.ContainerCreateConfig) (container.ContainerCreateCreatedBody, error)
commitFunc func(string, *backend.ContainerCommitConfig) (string, error) commitFunc func(string, *backend.ContainerCommitConfig) (string, error)
getImageFunc func(string) (builder.Image, builder.ReleaseableLayer, error) getImageFunc func(string) (builder.Image, builder.ReleaseableLayer, error)
makeImageCacheFunc func(cacheFrom []string) builder.ImageCache makeImageCacheFunc func(cacheFrom []string, platform string) builder.ImageCache
} }
func (m *MockBackend) ContainerAttachRaw(cID string, stdin io.ReadCloser, stdout, stderr io.Writer, stream bool, attached chan struct{}) error { func (m *MockBackend) ContainerAttachRaw(cID string, stdin io.ReadCloser, stdout, stderr io.Writer, stream bool, attached chan struct{}) error {
@ -71,9 +71,9 @@ func (m *MockBackend) GetImageAndReleasableLayer(ctx context.Context, refOrID st
return &mockImage{id: "theid"}, &mockLayer{}, nil return &mockImage{id: "theid"}, &mockLayer{}, nil
} }
func (m *MockBackend) MakeImageCache(cacheFrom []string) builder.ImageCache { func (m *MockBackend) MakeImageCache(cacheFrom []string, platform string) builder.ImageCache {
if m.makeImageCacheFunc != nil { if m.makeImageCacheFunc != nil {
return m.makeImageCacheFunc(cacheFrom) return m.makeImageCacheFunc(cacheFrom, platform)
} }
return nil return nil
} }

View file

@ -1,22 +1,18 @@
package daemon package daemon
import ( import (
"runtime"
"github.com/Sirupsen/logrus" "github.com/Sirupsen/logrus"
"github.com/docker/docker/builder" "github.com/docker/docker/builder"
"github.com/docker/docker/image/cache" "github.com/docker/docker/image/cache"
) )
// MakeImageCache creates a stateful image cache. // MakeImageCache creates a stateful image cache.
func (daemon *Daemon) MakeImageCache(sourceRefs []string) builder.ImageCache { func (daemon *Daemon) MakeImageCache(sourceRefs []string, platform string) builder.ImageCache {
if len(sourceRefs) == 0 { if len(sourceRefs) == 0 {
// TODO @jhowardmsft LCOW. For now, assume it is the OS of the host return cache.NewLocal(daemon.stores[platform].imageStore)
return cache.NewLocal(daemon.stores[runtime.GOOS].imageStore)
} }
// TODO @jhowardmsft LCOW. For now, assume it is the OS of the host cache := cache.New(daemon.stores[platform].imageStore)
cache := cache.New(daemon.stores[runtime.GOOS].imageStore)
for _, ref := range sourceRefs { for _, ref := range sourceRefs {
img, err := daemon.GetImage(ref) img, err := daemon.GetImage(ref)