mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Move "import" to graph/import.go
Signed-off-by: Solomon Hykes <solomon@docker.com>
This commit is contained in:
parent
f2029f7be1
commit
fa27580cff
4 changed files with 62 additions and 52 deletions
61
graph/import.go
Normal file
61
graph/import.go
Normal file
|
@ -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
|
||||||
|
}
|
|
@ -20,6 +20,7 @@ func (s *TagStore) Install(eng *engine.Engine) error {
|
||||||
eng.Register("images", s.CmdImages)
|
eng.Register("images", s.CmdImages)
|
||||||
eng.Register("viz", s.CmdViz)
|
eng.Register("viz", s.CmdViz)
|
||||||
eng.Register("load", s.CmdLoad)
|
eng.Register("load", s.CmdLoad)
|
||||||
|
eng.Register("import", s.CmdImport)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -9,7 +9,6 @@ import (
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
|
||||||
"net/url"
|
"net/url"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
|
@ -641,56 +640,6 @@ func (srv *Server) ImagePush(job *engine.Job) engine.Status {
|
||||||
return engine.StatusOK
|
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 {
|
func (srv *Server) DeleteImage(name string, imgs *engine.Table, first, force, noprune bool) error {
|
||||||
var (
|
var (
|
||||||
repoName, tag string
|
repoName, tag string
|
||||||
|
|
|
@ -91,7 +91,6 @@ func InitServer(job *engine.Job) engine.Status {
|
||||||
"log": srv.Log,
|
"log": srv.Log,
|
||||||
"build": srv.Build,
|
"build": srv.Build,
|
||||||
"pull": srv.ImagePull,
|
"pull": srv.ImagePull,
|
||||||
"import": srv.ImageImport,
|
|
||||||
"image_delete": srv.ImageDelete,
|
"image_delete": srv.ImageDelete,
|
||||||
"events": srv.Events,
|
"events": srv.Events,
|
||||||
"push": srv.ImagePush,
|
"push": srv.ImagePush,
|
||||||
|
|
Loading…
Reference in a new issue