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
|
@ -887,17 +887,32 @@ func (s *Server) getImagesGet(eng *engine.Engine, version version.Version, w htt
|
||||||
if err := parseForm(r); err != nil {
|
if err := parseForm(r); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if version.GreaterThan("1.0") {
|
|
||||||
|
useJSON := version.GreaterThan("1.0")
|
||||||
|
if useJSON {
|
||||||
w.Header().Set("Content-Type", "application/x-tar")
|
w.Header().Set("Content-Type", "application/x-tar")
|
||||||
}
|
}
|
||||||
var job *engine.Job
|
|
||||||
if name, ok := vars["name"]; ok {
|
output := utils.NewWriteFlusher(w)
|
||||||
job = eng.Job("image_export", name)
|
imageExportConfig := &graph.ImageExportConfig{
|
||||||
} else {
|
Engine: eng,
|
||||||
job = eng.Job("image_export", r.Form["names"]...)
|
Outstream: output,
|
||||||
}
|
}
|
||||||
job.Stdout.Add(w)
|
if name, ok := vars["name"]; ok {
|
||||||
return job.Run()
|
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 {
|
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 (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
|
@ -20,10 +19,14 @@ import (
|
||||||
// uncompressed tar ball.
|
// uncompressed tar ball.
|
||||||
// name is the set of tags to export.
|
// name is the set of tags to export.
|
||||||
// out is the writer where the images are written to.
|
// out is the writer where the images are written to.
|
||||||
func (s *TagStore) CmdImageExport(job *engine.Job) error {
|
type ImageExportConfig struct {
|
||||||
if len(job.Args) < 1 {
|
Names []string
|
||||||
return fmt.Errorf("Usage: %s IMAGE [IMAGE...]\n", job.Name)
|
Outstream io.Writer
|
||||||
|
Engine *engine.Engine
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *TagStore) ImageExport(imageExportConfig *ImageExportConfig) error {
|
||||||
|
|
||||||
// get image json
|
// get image json
|
||||||
tempdir, err := ioutil.TempDir("", "docker-export-")
|
tempdir, err := ioutil.TempDir("", "docker-export-")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -40,7 +43,7 @@ func (s *TagStore) CmdImageExport(job *engine.Job) error {
|
||||||
repo[tag] = id
|
repo[tag] = id
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for _, name := range job.Args {
|
for _, name := range imageExportConfig.Names {
|
||||||
name = registry.NormalizeLocalName(name)
|
name = registry.NormalizeLocalName(name)
|
||||||
logrus.Debugf("Serializing %s", name)
|
logrus.Debugf("Serializing %s", name)
|
||||||
rootRepo := s.Repositories[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'
|
// this is a base repo name, like 'busybox'
|
||||||
for tag, id := range rootRepo {
|
for tag, id := range rootRepo {
|
||||||
addKey(name, tag, id)
|
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
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -67,13 +70,13 @@ func (s *TagStore) CmdImageExport(job *engine.Job) error {
|
||||||
if len(repoTag) > 0 {
|
if len(repoTag) > 0 {
|
||||||
addKey(repoName, repoTag, img.ID)
|
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
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
// this must be an ID that didn't get looked up just right?
|
// 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
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -96,10 +99,10 @@ func (s *TagStore) CmdImageExport(job *engine.Job) error {
|
||||||
}
|
}
|
||||||
defer fs.Close()
|
defer fs.Close()
|
||||||
|
|
||||||
if _, err := io.Copy(job.Stdout, fs); err != nil {
|
if _, err := io.Copy(imageExportConfig.Outstream, fs); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
logrus.Debugf("End export job: %s", job.Name)
|
logrus.Debugf("End export image")
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -11,7 +11,6 @@ import (
|
||||||
func (s *TagStore) Install(eng *engine.Engine) error {
|
func (s *TagStore) Install(eng *engine.Engine) error {
|
||||||
for name, handler := range map[string]engine.Handler{
|
for name, handler := range map[string]engine.Handler{
|
||||||
"image_inspect": s.CmdLookup,
|
"image_inspect": s.CmdLookup,
|
||||||
"image_export": s.CmdImageExport,
|
|
||||||
"viz": s.CmdViz,
|
"viz": s.CmdViz,
|
||||||
} {
|
} {
|
||||||
if err := eng.Register(name, handler); err != nil {
|
if err := eng.Register(name, handler); err != nil {
|
||||||
|
|
Loading…
Reference in New Issue