diff --git a/graph/import.go b/graph/import.go new file mode 100644 index 0000000000..049742af45 --- /dev/null +++ b/graph/import.go @@ -0,0 +1,61 @@ +package graph + +import ( + "net/http" + "net/url" + + "github.com/docker/docker/archive" + "github.com/docker/docker/engine" + "github.com/docker/docker/utils" +) + +func (s *TagStore) CmdImport(job *engine.Job) engine.Status { + if n := len(job.Args); n != 2 && n != 3 { + return job.Errorf("Usage: %s SRC REPO [TAG]", job.Name) + } + var ( + src = job.Args[0] + repo = job.Args[1] + tag string + sf = utils.NewStreamFormatter(job.GetenvBool("json")) + archive archive.ArchiveReader + resp *http.Response + ) + if len(job.Args) > 2 { + tag = job.Args[2] + } + + if src == "-" { + archive = job.Stdin + } else { + u, err := url.Parse(src) + if err != nil { + return job.Error(err) + } + if u.Scheme == "" { + u.Scheme = "http" + u.Host = src + u.Path = "" + } + job.Stdout.Write(sf.FormatStatus("", "Downloading from %s", u)) + resp, err = utils.Download(u.String()) + if err != nil { + return job.Error(err) + } + progressReader := utils.ProgressReader(resp.Body, int(resp.ContentLength), job.Stdout, sf, true, "", "Importing") + defer progressReader.Close() + archive = progressReader + } + img, err := s.graph.Create(archive, "", "", "Imported from "+src, "", nil, nil) + if err != nil { + return job.Error(err) + } + // Optionally register the image at REPO/TAG + if repo != "" { + if err := s.Set(repo, tag, img.ID, true); err != nil { + return job.Error(err) + } + } + job.Stdout.Write(sf.FormatStatus("", img.ID)) + return engine.StatusOK +} diff --git a/graph/service.go b/graph/service.go index 8c61296b1e..80ab6de3fd 100644 --- a/graph/service.go +++ b/graph/service.go @@ -20,6 +20,7 @@ func (s *TagStore) Install(eng *engine.Engine) error { eng.Register("images", s.CmdImages) eng.Register("viz", s.CmdViz) eng.Register("load", s.CmdLoad) + eng.Register("import", s.CmdImport) return nil } diff --git a/server/image.go b/server/image.go index 8fdc71dc11..ae7e321d8e 100644 --- a/server/image.go +++ b/server/image.go @@ -9,7 +9,6 @@ import ( "io" "io/ioutil" "net" - "net/http" "net/url" "os" "os/exec" @@ -641,56 +640,6 @@ func (srv *Server) ImagePush(job *engine.Job) engine.Status { return engine.StatusOK } -func (srv *Server) ImageImport(job *engine.Job) engine.Status { - if n := len(job.Args); n != 2 && n != 3 { - return job.Errorf("Usage: %s SRC REPO [TAG]", job.Name) - } - var ( - src = job.Args[0] - repo = job.Args[1] - tag string - sf = utils.NewStreamFormatter(job.GetenvBool("json")) - archive archive.ArchiveReader - resp *http.Response - ) - if len(job.Args) > 2 { - tag = job.Args[2] - } - - if src == "-" { - archive = job.Stdin - } else { - u, err := url.Parse(src) - if err != nil { - return job.Error(err) - } - if u.Scheme == "" { - u.Scheme = "http" - u.Host = src - u.Path = "" - } - job.Stdout.Write(sf.FormatStatus("", "Downloading from %s", u)) - resp, err = utils.Download(u.String()) - if err != nil { - return job.Error(err) - } - progressReader := utils.ProgressReader(resp.Body, int(resp.ContentLength), job.Stdout, sf, true, "", "Importing") - defer progressReader.Close() - archive = progressReader - } - img, err := srv.daemon.Graph().Create(archive, "", "", "Imported from "+src, "", nil, nil) - if err != nil { - return job.Error(err) - } - // Optionally register the image at REPO/TAG - if repo != "" { - if err := srv.daemon.Repositories().Set(repo, tag, img.ID, true); err != nil { - return job.Error(err) - } - } - job.Stdout.Write(sf.FormatStatus("", img.ID)) - return engine.StatusOK -} func (srv *Server) DeleteImage(name string, imgs *engine.Table, first, force, noprune bool) error { var ( repoName, tag string diff --git a/server/init.go b/server/init.go index 20d7088839..c9c3a37563 100644 --- a/server/init.go +++ b/server/init.go @@ -91,7 +91,6 @@ func InitServer(job *engine.Job) engine.Status { "log": srv.Log, "build": srv.Build, "pull": srv.ImagePull, - "import": srv.ImageImport, "image_delete": srv.ImageDelete, "events": srv.Events, "push": srv.ImagePush,