浏览代码

LCOW: Plumb through platform on Import

Signed-off-by: John Howard <jhoward@microsoft.com>
John Howard 8 年之前
父节点
当前提交
3d5cec70b4
共有 3 个文件被更改,包括 13 次插入17 次删除
  1. 1 1
      api/server/router/image/backend.go
  2. 1 2
      api/server/router/image/image_routes.go
  3. 11 14
      daemon/import.go

+ 1 - 1
api/server/router/image/backend.go

@@ -35,7 +35,7 @@ type imageBackend interface {
 
 
 type importExportBackend interface {
 type importExportBackend interface {
 	LoadImage(inTar io.ReadCloser, outStream io.Writer, quiet bool) error
 	LoadImage(inTar io.ReadCloser, outStream io.Writer, quiet bool) error
-	ImportImage(src string, repository, tag string, msg string, inConfig io.ReadCloser, outStream io.Writer, changes []string) error
+	ImportImage(src string, repository, platform string, tag string, msg string, inConfig io.ReadCloser, outStream io.Writer, changes []string) error
 	ExportImage(names []string, outStream io.Writer) error
 	ExportImage(names []string, outStream io.Writer) error
 }
 }
 
 

+ 1 - 2
api/server/router/image/image_routes.go

@@ -149,8 +149,7 @@ func (s *imageRouter) postImagesCreate(ctx context.Context, w http.ResponseWrite
 		// 'err' MUST NOT be defined within this block, we need any error
 		// 'err' MUST NOT be defined within this block, we need any error
 		// generated from the download to be available to the output
 		// generated from the download to be available to the output
 		// stream processing below
 		// stream processing below
-		// TODO @jhowardmsft LCOW Support: This will need extending for the platform too.
-		err = s.backend.ImportImage(src, repo, tag, message, r.Body, output, r.Form["changes"])
+		err = s.backend.ImportImage(src, repo, platform, tag, message, r.Body, output, r.Form["changes"])
 	}
 	}
 	if err != nil {
 	if err != nil {
 		if !output.Flushed() {
 		if !output.Flushed() {

+ 11 - 14
daemon/import.go

@@ -26,13 +26,18 @@ import (
 // inConfig (if src is "-"), or from a URI specified in src. Progress output is
 // inConfig (if src is "-"), or from a URI specified in src. Progress output is
 // written to outStream. Repository and tag names can optionally be given in
 // written to outStream. Repository and tag names can optionally be given in
 // the repo and tag arguments, respectively.
 // the repo and tag arguments, respectively.
-func (daemon *Daemon) ImportImage(src string, repository, tag string, msg string, inConfig io.ReadCloser, outStream io.Writer, changes []string) error {
+func (daemon *Daemon) ImportImage(src string, repository, platform string, tag string, msg string, inConfig io.ReadCloser, outStream io.Writer, changes []string) error {
 	var (
 	var (
 		rc     io.ReadCloser
 		rc     io.ReadCloser
 		resp   *http.Response
 		resp   *http.Response
 		newRef reference.Named
 		newRef reference.Named
 	)
 	)
 
 
+	// Default the platform if not supplied.
+	if platform == "" {
+		platform = runtime.GOOS
+	}
+
 	if repository != "" {
 	if repository != "" {
 		var err error
 		var err error
 		newRef, err = reference.ParseNormalizedNamed(repository)
 		newRef, err = reference.ParseNormalizedNamed(repository)
@@ -85,17 +90,11 @@ func (daemon *Daemon) ImportImage(src string, repository, tag string, msg string
 	if err != nil {
 	if err != nil {
 		return err
 		return err
 	}
 	}
-	// TODO: support windows baselayer?
-	// TODO: LCOW support @jhowardmsft. For now, pass in a null platform when
-	//       registering the layer. Windows doesn't currently support import,
-	//       but for Linux images, there's no reason it couldn't. However it
-	//       would need another CLI flag as there's no meta-data indicating
-	//       the OS of the thing being imported.
-	l, err := daemon.stores[runtime.GOOS].layerStore.Register(inflatedLayerData, "", "")
+	l, err := daemon.stores[platform].layerStore.Register(inflatedLayerData, "", layer.Platform(platform))
 	if err != nil {
 	if err != nil {
 		return err
 		return err
 	}
 	}
-	defer layer.ReleaseAndLog(daemon.stores[runtime.GOOS].layerStore, l) // TODO LCOW @jhowardmsft as for above comment
+	defer layer.ReleaseAndLog(daemon.stores[platform].layerStore, l)
 
 
 	created := time.Now().UTC()
 	created := time.Now().UTC()
 	imgConfig, err := json.Marshal(&image.Image{
 	imgConfig, err := json.Marshal(&image.Image{
@@ -103,7 +102,7 @@ func (daemon *Daemon) ImportImage(src string, repository, tag string, msg string
 			DockerVersion: dockerversion.Version,
 			DockerVersion: dockerversion.Version,
 			Config:        config,
 			Config:        config,
 			Architecture:  runtime.GOARCH,
 			Architecture:  runtime.GOARCH,
-			OS:            runtime.GOOS, // TODO LCOW @jhowardmsft as for above commment
+			OS:            platform,
 			Created:       created,
 			Created:       created,
 			Comment:       msg,
 			Comment:       msg,
 		},
 		},
@@ -120,16 +119,14 @@ func (daemon *Daemon) ImportImage(src string, repository, tag string, msg string
 		return err
 		return err
 	}
 	}
 
 
-	// TODO @jhowardmsft LCOW - Again, assume the OS of the host for now
-	id, err := daemon.stores[runtime.GOOS].imageStore.Create(imgConfig)
+	id, err := daemon.stores[platform].imageStore.Create(imgConfig)
 	if err != nil {
 	if err != nil {
 		return err
 		return err
 	}
 	}
 
 
 	// FIXME: connect with commit code and call refstore directly
 	// FIXME: connect with commit code and call refstore directly
 	if newRef != nil {
 	if newRef != nil {
-		// TODO @jhowardmsft LCOW - Again, assume the OS of the host for now
-		if err := daemon.TagImageWithReference(id, runtime.GOOS, newRef); err != nil {
+		if err := daemon.TagImageWithReference(id, platform, newRef); err != nil {
 			return err
 			return err
 		}
 		}
 	}
 	}