1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

Merge pull request #3113 from shykes/engine-export

Move 'docker export' to the engine API
This commit is contained in:
Victor Vieux 2013-12-10 13:28:24 -08:00
commit 0025e9bd71
3 changed files with 24 additions and 12 deletions

9
api.go
View file

@ -174,10 +174,11 @@ func getContainersExport(srv *Server, version float64, w http.ResponseWriter, r
if vars == nil {
return fmt.Errorf("Missing parameter")
}
name := vars["name"]
if err := srv.ContainerExport(name, w); err != nil {
utils.Errorf("%s", err)
job := srv.Eng.Job("export", vars["name"])
if err := job.Stdout.Add(w); err != nil {
return err
}
if err := job.Run(); err != nil {
return err
}
return nil

View file

@ -113,7 +113,6 @@ func (eng *Engine) Job(name string, args ...string) *Job {
Stderr: NewOutput(),
env: &Env{},
}
job.Stdout.Add(utils.NopWriteCloser(eng.Stdout))
job.Stderr.Add(utils.NopWriteCloser(eng.Stderr))
handler, exists := eng.handlers[name]
if exists {

View file

@ -70,6 +70,10 @@ func jobInitApi(job *engine.Job) engine.Status {
if srv.runtime.networkManager.bridgeNetwork != nil {
job.Eng.Hack_SetGlobalVar("httpapi.bridgeIP", srv.runtime.networkManager.bridgeNetwork.IP)
}
if err := job.Eng.Register("export", srv.ContainerExport); err != nil {
job.Error(err)
return engine.StatusErr
}
if err := job.Eng.Register("create", srv.ContainerCreate); err != nil {
job.Error(err)
return engine.StatusErr
@ -165,22 +169,30 @@ func (srv *Server) ContainerKill(name string, sig int) error {
return nil
}
func (srv *Server) ContainerExport(name string, out io.Writer) error {
func (srv *Server) ContainerExport(job *engine.Job) engine.Status {
if len(job.Args) != 1 {
job.Errorf("Usage: %s container_id", job.Name)
return engine.StatusErr
}
name := job.Args[0]
if container := srv.runtime.Get(name); container != nil {
data, err := container.Export()
if err != nil {
return err
job.Errorf("%s: %s", name, err)
return engine.StatusErr
}
// Stream the entire contents of the container (basically a volatile snapshot)
if _, err := io.Copy(out, data); err != nil {
return err
if _, err := io.Copy(job.Stdout, data); err != nil {
job.Errorf("%s: %s", name, err)
return engine.StatusErr
}
// FIXME: factor job-specific LogEvent to engine.Job.Run()
srv.LogEvent("export", container.ID, srv.runtime.repositories.ImageName(container.Image))
return nil
return engine.StatusOK
}
return fmt.Errorf("No such container: %s", name)
job.Errorf("No such container: %s", name)
return engine.StatusErr
}
// ImageExport exports all images with the given tag. All versions