diff --git a/daemon/daemon.go b/daemon/daemon.go index e7588b0b63..fafd4b2668 100644 --- a/daemon/daemon.go +++ b/daemon/daemon.go @@ -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 } diff --git a/image/image.go b/image/image.go index 9f892d298a..34ad2e6786 100644 --- a/image/image.go +++ b/image/image.go @@ -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. diff --git a/image/store.go b/image/store.go index 17a3b7880a..8cdf113944 100644 --- a/image/store.go +++ b/image/store.go @@ -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 diff --git a/image/store_test.go b/image/store_test.go index 21a9b0b41b..13318cf221 100644 --- a/image/store_test.go +++ b/image/store_test.go @@ -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 diff --git a/migrate/v1/migratev1_test.go b/migrate/v1/migratev1_test.go index 852f5891fb..51b6741226 100644 --- a/migrate/v1/migratev1_test.go +++ b/migrate/v1/migratev1_test.go @@ -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) }