LCOW: Add platform to image store

Signed-off-by: John Howard <jhoward@microsoft.com>
This commit is contained in:
John Howard 2017-05-16 14:35:28 -07:00
parent f97fbba5ce
commit 6c33684987
5 changed files with 21 additions and 7 deletions

View File

@ -656,7 +656,9 @@ func NewDaemon(config *config.Config, registryService registry.Service, containe
return nil, err
}
d.imageStore, err = image.NewImageStore(ifs, d.layerStore)
// TODO LCOW @jhowardmsft. For now assume it's the runtime OS. This will be modified
// as the stores are split in a follow-up commit.
d.imageStore, err = image.NewImageStore(ifs, runtime.GOOS, d.layerStore)
if err != nil {
return nil, err
}

View File

@ -96,6 +96,15 @@ func (img *Image) RunConfig() *container.Config {
return img.Config
}
// Platform returns the image's operating system. If not populated, defaults to the host runtime OS.
func (img *Image) Platform() string {
os := img.OS
if os == "" {
os = runtime.GOOS
}
return os
}
// MarshalJSON serializes the image to JSON. It sorts the top-level keys so
// that JSON that's been manipulated by a push/pull cycle with a legacy
// registry won't end up with a different key order.

View File

@ -42,15 +42,17 @@ type store struct {
images map[ID]*imageMeta
fs StoreBackend
digestSet *digestset.Set
platform string
}
// NewImageStore returns new store object for given layer store
func NewImageStore(fs StoreBackend, ls LayerGetReleaser) (Store, error) {
func NewImageStore(fs StoreBackend, platform string, ls LayerGetReleaser) (Store, error) {
is := &store{
ls: ls,
images: make(map[ID]*imageMeta),
fs: fs,
digestSet: digestset.NewSet(),
platform: platform,
}
// load all current images and retain layers

View File

@ -1,6 +1,7 @@
package image
import (
"runtime"
"testing"
"github.com/docker/docker/layer"
@ -25,7 +26,7 @@ func TestRestore(t *testing.T) {
err = fs.SetMetadata(id2, "parent", []byte(id1))
assert.NoError(t, err)
is, err := NewImageStore(fs, &mockLayerGetReleaser{})
is, err := NewImageStore(fs, runtime.GOOS, &mockLayerGetReleaser{})
assert.NoError(t, err)
assert.Len(t, is.Map(), 2)
@ -142,7 +143,7 @@ func TestParentReset(t *testing.T) {
func defaultImageStore(t *testing.T) (Store, func()) {
fsBackend, cleanup := defaultFSStoreBackend(t)
store, err := NewImageStore(fsBackend, &mockLayerGetReleaser{})
store, err := NewImageStore(fsBackend, runtime.GOOS, &mockLayerGetReleaser{})
assert.NoError(t, err)
return store, cleanup

View File

@ -94,7 +94,7 @@ func TestMigrateContainers(t *testing.T) {
t.Fatal(err)
}
is, err := image.NewImageStore(ifs, ls)
is, err := image.NewImageStore(ifs, runtime.GOOS, ls)
if err != nil {
t.Fatal(err)
}
@ -172,12 +172,12 @@ func TestMigrateImages(t *testing.T) {
t.Fatal(err)
}
is, err := image.NewImageStore(ifs, ls)
is, err := image.NewImageStore(ifs, runtime.GOOS, ls)
if err != nil {
t.Fatal(err)
}
ms, err := metadata.NewFSMetadataStore(filepath.Join(tmpdir, "distribution"))
ms, err := metadata.NewFSMetadataStore(filepath.Join(tmpdir, "distribution"), runtime.GOOS)
if err != nil {
t.Fatal(err)
}