remove job from image_export
Signed-off-by: He Simei <hesimei@zju.edu.cn> Signed-off-by: Alexander Morozov <lk4d4@docker.com>
This commit is contained in:
parent
fa3e2dd45e
commit
2a14b7dd35
3 changed files with 37 additions and 20 deletions
|
@ -887,17 +887,32 @@ func (s *Server) getImagesGet(eng *engine.Engine, version version.Version, w htt
|
|||
if err := parseForm(r); err != nil {
|
||||
return err
|
||||
}
|
||||
if version.GreaterThan("1.0") {
|
||||
|
||||
useJSON := version.GreaterThan("1.0")
|
||||
if useJSON {
|
||||
w.Header().Set("Content-Type", "application/x-tar")
|
||||
}
|
||||
var job *engine.Job
|
||||
if name, ok := vars["name"]; ok {
|
||||
job = eng.Job("image_export", name)
|
||||
} else {
|
||||
job = eng.Job("image_export", r.Form["names"]...)
|
||||
|
||||
output := utils.NewWriteFlusher(w)
|
||||
imageExportConfig := &graph.ImageExportConfig{
|
||||
Engine: eng,
|
||||
Outstream: output,
|
||||
}
|
||||
job.Stdout.Add(w)
|
||||
return job.Run()
|
||||
if name, ok := vars["name"]; ok {
|
||||
imageExportConfig.Names = []string{name}
|
||||
} else {
|
||||
imageExportConfig.Names = r.Form["names"]
|
||||
}
|
||||
|
||||
if err := s.daemon.Repositories().ImageExport(imageExportConfig); err != nil {
|
||||
if !output.Flushed() {
|
||||
return err
|
||||
}
|
||||
sf := streamformatter.NewStreamFormatter(useJSON)
|
||||
output.Write(sf.FormatError(err))
|
||||
}
|
||||
return nil
|
||||
|
||||
}
|
||||
|
||||
func (s *Server) postImagesLoad(eng *engine.Engine, version version.Version, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
|
||||
|
|
|
@ -2,7 +2,6 @@ package graph
|
|||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
|
@ -20,10 +19,14 @@ import (
|
|||
// uncompressed tar ball.
|
||||
// name is the set of tags to export.
|
||||
// out is the writer where the images are written to.
|
||||
func (s *TagStore) CmdImageExport(job *engine.Job) error {
|
||||
if len(job.Args) < 1 {
|
||||
return fmt.Errorf("Usage: %s IMAGE [IMAGE...]\n", job.Name)
|
||||
}
|
||||
type ImageExportConfig struct {
|
||||
Names []string
|
||||
Outstream io.Writer
|
||||
Engine *engine.Engine
|
||||
}
|
||||
|
||||
func (s *TagStore) ImageExport(imageExportConfig *ImageExportConfig) error {
|
||||
|
||||
// get image json
|
||||
tempdir, err := ioutil.TempDir("", "docker-export-")
|
||||
if err != nil {
|
||||
|
@ -40,7 +43,7 @@ func (s *TagStore) CmdImageExport(job *engine.Job) error {
|
|||
repo[tag] = id
|
||||
}
|
||||
}
|
||||
for _, name := range job.Args {
|
||||
for _, name := range imageExportConfig.Names {
|
||||
name = registry.NormalizeLocalName(name)
|
||||
logrus.Debugf("Serializing %s", name)
|
||||
rootRepo := s.Repositories[name]
|
||||
|
@ -48,7 +51,7 @@ func (s *TagStore) CmdImageExport(job *engine.Job) error {
|
|||
// this is a base repo name, like 'busybox'
|
||||
for tag, id := range rootRepo {
|
||||
addKey(name, tag, id)
|
||||
if err := s.exportImage(job.Eng, id, tempdir); err != nil {
|
||||
if err := s.exportImage(imageExportConfig.Engine, id, tempdir); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
@ -67,13 +70,13 @@ func (s *TagStore) CmdImageExport(job *engine.Job) error {
|
|||
if len(repoTag) > 0 {
|
||||
addKey(repoName, repoTag, img.ID)
|
||||
}
|
||||
if err := s.exportImage(job.Eng, img.ID, tempdir); err != nil {
|
||||
if err := s.exportImage(imageExportConfig.Engine, img.ID, tempdir); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
} else {
|
||||
// this must be an ID that didn't get looked up just right?
|
||||
if err := s.exportImage(job.Eng, name, tempdir); err != nil {
|
||||
if err := s.exportImage(imageExportConfig.Engine, name, tempdir); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
@ -96,10 +99,10 @@ func (s *TagStore) CmdImageExport(job *engine.Job) error {
|
|||
}
|
||||
defer fs.Close()
|
||||
|
||||
if _, err := io.Copy(job.Stdout, fs); err != nil {
|
||||
if _, err := io.Copy(imageExportConfig.Outstream, fs); err != nil {
|
||||
return err
|
||||
}
|
||||
logrus.Debugf("End export job: %s", job.Name)
|
||||
logrus.Debugf("End export image")
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
|
@ -11,7 +11,6 @@ import (
|
|||
func (s *TagStore) Install(eng *engine.Engine) error {
|
||||
for name, handler := range map[string]engine.Handler{
|
||||
"image_inspect": s.CmdLookup,
|
||||
"image_export": s.CmdImageExport,
|
||||
"viz": s.CmdViz,
|
||||
} {
|
||||
if err := eng.Register(name, handler); err != nil {
|
||||
|
|
Loading…
Reference in a new issue