mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Engine: 'export' returns a raw archive of a container's filesystem
This commit is contained in:
parent
50f3a696bd
commit
9656cdf0c2
2 changed files with 24 additions and 11 deletions
9
api.go
9
api.go
|
@ -173,10 +173,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
|
||||
|
|
26
server.go
26
server.go
|
@ -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
|
||||
|
@ -190,22 +194,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
|
||||
|
|
Loading…
Reference in a new issue